Print text positioned in image

Asked

Viewed 274 times

1

I have a text positioned in the center of an image, the logic is to print a certificate, and this text is generated dynamically, this occurs correctly. The problem is when printing, the text is on page 2 the image on page 1 inserir a descrição da imagem aqui

HTML:

<div id="DivImpressao">
<section id="AtestadoTecnico">                          
       <img id="imgAtestado" src="~/Images/Site/AtestadoTecnico.png" runat="server" class="imgAtestadoTecnico" height="685" />                           
        <div class="txtAtestadoTecnico">
                <div style="text-align: justify; font-family: Ebrima; font-size: 10pt; margin-top: 20px">
                    //texto aqui
                </div>
         </div>
      </section>

CSS:

#AtestadoTecnico {
    width: 1014px;
    height: 670px;
    position: relative;
}

.imgAtestadoTecnico {
    top: 0px;
    bottom: 20px;
    position: absolute;
}

.txtAtestadoTecnico {
    top: 100px;
    left: 120px;
    position: absolute;
}

Javascript (here I pass the "Divimpressao" as parameter for printing:

function imprimePanel(elementId) {
    var printContent = document.getElementById(elementId);
    var windowUrl = 'about:blank';
    var uniqueName = new Date();
    var windowName = 'Print' + uniqueName.getTime();
    var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');
    printWindow.document.write(printContent.innerHTML);
    printWindow.document.close();
    printWindow.focus();
    printWindow.print();
    printWindow.close();
}
  • Face in the test I did here when I give CTRL+P in Chrome does not break the image on one page and the text on the other does not... There must be something else in your CSS or is this your script ai is making break. Pq vc is giving top=50000 in the window??

  • Yes, when you have it printed by Chrome, it doesn’t happen to break.. It happens when I click the print button I created that calls the Javascript function that is in the question.. then the break happens.

1 answer

0

I managed to solve using a plugin for Jquery called printThis Very simple to use and was perfect the page.

$('selector').printThis();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.