Reputation: 2172
I am working on creating a printable document from an HTML page but the output is too large. I don't want to have to completely restyle the page to work for printing as well (ie. print media queries for everything again), so I was wondering if there is a way I can change the window.print
(or window print dialog) settings.
I have figured out that setting the scale
equal to 80%
generates a good PDF; however, I obviously don't want people to have to remember this. Is there a way to do this in Chrome?
I have tried adjusting the browser page zoom
but this leads to the same behaviour (squished content) that only covers a portion of the page. The technique was based on this question: Force page zoom at 100% with JS.
Also, I have tried adjusting the body
scale to transform: scale(0.8);
, but also to no avail. This resulted in a large amount of whitespace around the elements in the PDF that I couldn't remove.
Upvotes: 5
Views: 29215
Reputation: 8979
The window.print() method calls the browser's built-in print support plugin to print the current DOM page. You can check the documentation: it doesn't support any argument or settings. To setup the print, you can only utilize the browser's GUI( ex. enable or disable background graphics etc.) see the screenshot below with browser GUI.
As you can see in the image(Screenshot from Chrome), you can save to pdf or directly send to the printer as well. There are some other settings that are available to be changed accordingly. For more info about the window methods, you can go through Official Mozilla Docs for Window Object in Javascript
Upvotes: 5