Resize images with Print.Window

Asked

Viewed 57 times

1

I have a Function that prints an image in order to print it. But I would like to know if you have how to change the position of this image at the time it enters the method.

At the moment the Function thus opens the image

inserir a descrição da imagem aqui

I would like to resize the image 90º on the right to be able to pick up the sheet (A4 format), this is possible ?

Follows code:

function printPartOfPage(elementId) {
           var printContent = document.getElementById(elementId);
            var printWindow = window.open('', '', 'left=10,top=10,width=740,height=600');

            printWindow.document.write(printContent.innerHTML);
            printWindow.document.close();
            printWindow.focus();
            printWindow.print();
            printWindow.close();
        }

1 answer

1


Igor in the CSS of your page you can make a style to change the orientation of the sheet only at the time of printing this way.

@page {
  size: A4 landscape;
}

You may have to adapt your JS to call this css if you don’t use css in the project.

See a practical example:

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}
div {
    width: 90%;
}
@page {
  size: landscape;
}
<div>
    <img src='http://unsplash.it/600/280' style="width: 100%;" alt="">
</div>

With this example above I got these results

COM @page size: Landscape

inserir a descrição da imagem aqui

SEM @page size

inserir a descrição da imagem aqui

Here is a documentation from Mozilla about the @page https://developer.mozilla.org/en-US/docs/Web/CSS/@page/size

Browser other questions tagged

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