openhtmltopdf
openhtmltopdf copied to clipboard
print pdf in landscape instead of portrait
When I m converting my HTML to pdf it is printing in portrait mode due to which some content is missing. How can I convert it to landscape mode while generating pdf.
If you can change/modify your HTML, you can accomplish this using CSS rules:
/* Landscape pages */
@page {
size: 11in 8.5in;
margin-bottom: 0.75in;
margin-left: 0.9in;
margin-right: 0.9in;
margin-top: 0.75in;
}
I added the above change as:
<style>
/* Landscape pages */
@page {
size: 11in 8.5in;
margin-bottom: 0.75in;
margin-left: 0.9in;
margin-right: 0.9in;
margin-top: 0.75in;
}
</style>
It worked, thank you!
Hey there,
In the Template Guide (https://openhtmltopdf.com/template-guide.pdf) , it says that you can use the following CSS to get the PDF to be in landscape mode:
<style>
/* Landscape pages */
@page {
size: letter landscape;
}
</style>
I tried but I saw no change in the documents. Is there anything else we need to do? Or do we have to change the dimensions "manually" as it has been shown here?
Cheers!
Hi @Verdoso , I use ...
<style>
@page {
size: a4 landscape;
}
</style>
... and it works like a charm. Are you sure your overall HTML structure is correct?
Hi @costas80, Ok, false alarm, it was Spring caching the css in the static directory. It's weird because I was modifying the css and seeing the changes all along, and all of a sudden it stopped refreshing the css with new changes. I've tried every property I have seen to get it to refresh during development to no avail.
But anyway, it's not an openhtmltopdf issue, so thanks for confirming it works. Cheers!