Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only getting single page PDF #198

Closed
AlecTaylor opened this issue May 27, 2014 · 4 comments
Closed

Only getting single page PDF #198

AlecTaylor opened this issue May 27, 2014 · 4 comments

Comments

@AlecTaylor
Copy link

I am using a template from Zurb; and using WeasyPrint as an option to show the email as a PDF. Unfortunately I am only ever getting one page.

Here is a runnable test-case showing this issue:

from weasyprint import HTML, CSS
from urllib2 import urlopen

if __name__ == '__main__':
    html = urlopen('http://zurb.com/ink/downloads/templates/basic.html').read()
    html = html.replace('<p class=\"lead\">', '{0}<p class=\"lead\">'.format(
        '<p class=\"lead\">{0}</p>'.format("foobar " * 50) * 50))
    HTML(string=html).write_pdf('foo.pdf',
                                stylesheets=[CSS(string='@page { size: A4; margin: 2cm };'
                                                        '* { float: none !important; };'
                                                        '@media print { nav { display: none; } }')])

How do I get multiple pages?

@SimonSapin
Copy link
Member

CSS(string='@page { size: A4; margin: 2cm };'
           '* { float: none !important; };'
           '@media print { nav { display: none; } }')

CSS does not use semi-colons between rules, so your second and third rules here will be invalid: they’re style rules whose selectors start with a semi-colon. But fixing this does not fix your pagination issue.

I see you’re using * { float: none !important; }, so you may be aware that WeasyPrint does not support page breaks inside float. Unfortunately, it also can not break table cells (only between table rows at most), and this document uses tables for layout.

Now if you can’t change the HTML for some reason, you could butcher the document with a stylesheet like table, thead, tbody, tfoot, tr, th, td { display: block }, but I really recommend not using table nor floats for layout in the first place, when targeting WeasyPrint.

@jdus
Copy link
Contributor

jdus commented May 27, 2014

All the paragraphs are in one single cell and, as Simon stated, Weaspyrint does not allow to split table cells (yet). If you could rearrange the code, so that the paragraphs would all reside in their own table cell and row, it should work.

E.g.

<tr><td><h1>Hi, Susan Calvin</td></tr>
<tr><td>paragraph 1</td></tr>
<tr><td>paragraph 2</td></tr>
<tr><td>paragraph 3</td></tr>
...
'''

@SimonSapin
Copy link
Member

If you could rearrange the code, so that the paragraphs would all reside in their own table cell

Or, you know, just use <p> paragraphs without a table.

@liZe
Copy link
Member

liZe commented Aug 14, 2015

Duplicates #36

@liZe liZe closed this as completed Aug 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants