Weasyprint pdf not suitable for page

I have an html page with simple css2 rules. All content is contained in a div that is 930 pixels wide. In the browser, it looks as expected, and when printing (from chrome), it neatly fits the page with a decent font size.

As soon as I try to create a PDF from this file using weasyprint, the font will look much larger and the document will exceed the page width.

HTML(string=html, base_url=server_base_url).write_pdf(target=target) 

I am not sure how to debug the problem. Weasyprint doesn't seem to imply print scaling, which I assume chrome does. By accepting a document, rendering it, and then scaling it to fit on the page.

I tried using the zoom parameter of the write_pdf .write_pdf(target=target, zoom=0.7) method .write_pdf(target=target, zoom=0.7) , but it seems to increase the page size and the content size, so this will not help. I tried combining it with css to make the page bigger. This way I decrease the brightness and scaling with css

 @page { size: XXXin YYYin } 

It just seemed strange. So where do I go?

+5
source share
1 answer

Have you tried using

 @page { size: Letter; margin: 0in 0.44in 0.2in 0.44in; } 

You can adjust the margin as you like, but the Letter size should be the standard page size.

page size

+3
source

Source: https://habr.com/ru/post/1236675/


All Articles