10

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

Once I try to create a PDF from this file using weasyprint, the font look much bigger, and the document exceeds the page width.

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

I'm not really sure how to debug the issue. Weasyprint does not seem to suppose print scaling, which is what I assume chrome is doing. Taking the document, rendering it, and then scaling it to fit on the page.

I tried using the zoom parameter of the write_pdf method .write_pdf(target=target, zoom=0.7), but it seems to zoom the page size AND the content size, so that is no help, really. I tried combining it with css to make the page bigger. So I zoom down with weasy and scale up with css

@page {
    size: XXXin YYYin
}

This just ended up looking weird. So where do I go from here?

Eldamir
  • 9,888
  • 6
  • 52
  • 73

1 Answers1

9

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

Community
  • 1
  • 1
Ross Wilson
  • 91
  • 1
  • 4
  • 1
    This is an old question now. I believe I endef up solving it by setting a width on the body tag – Eldamir Aug 16 '16 at 13:34
  • 2
    @Ross Wilson, I had the same problem as Eldamir but in my case passing the page parameters you mentiones through the stylesheets weasyprint argument has not worked. Anything else I could try? My printed documented is still exceeding the page in size. Eldemir, if you could remember the solution and post it here it would be really helpful too! – fernandosjp Jun 26 '17 at 05:01
  • @fernandosjp I'm not sure if this is helpful, but it seems like I also had to limit the width of the body element (mine is currently set to 600px but it could probably be bigger depending on the margins you want). If I set it really high, then the information on the pdf will go off the standard size page. – Ross Wilson Jun 27 '17 at 18:35