openhtmltopdf icon indicating copy to clipboard operation
openhtmltopdf copied to clipboard

print pdf in landscape instead of portrait

Open ak2263 opened this issue 2 years ago • 5 comments

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.

ak2263 avatar May 09 '22 13:05 ak2263

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;	
}

smahnken avatar May 12 '22 16:05 smahnken

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!

pavankumarchaitanya avatar Dec 20 '22 17:12 pavankumarchaitanya

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!

Verdoso avatar Jun 02 '23 12:06 Verdoso

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?

costas80 avatar Jun 02 '23 12:06 costas80

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!

Verdoso avatar Jun 02 '23 15:06 Verdoso