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

How to add cover page? and How to hide some contents in first page only? #511

Closed
xploregopi opened this issue Sep 25, 2017 · 3 comments
Closed
Labels
CSS Questions about how to do something with CSS

Comments

@xploregopi
Copy link

How to add cover page?
How to hide some contents in first page only?

@liZe liZe added the CSS Questions about how to do something with CSS label Sep 26, 2017
@liZe
Copy link
Member

liZe commented Sep 26, 2017

Cover pages can be added using either:

You can find other related stuff in #92 too.

@ritiksoni00
Copy link

Cover pages can be added using either:

You can find other related stuff in #92 too.

i tried||

@page first{
   display: table-row;
}
.first-page {
   page: first;
   display: none;
}

and it doesn't work. What's wrong in it?

@kdipippo
Copy link

kdipippo commented Apr 29, 2024

Replying to this thread from 5 years ago with a possible solution to how to add a cover page: make 2 WeasyPrint.HTML objects, one containing the cover page and another containing the rest of the content and merge them together.

This applies at least to weasyprint==60.1.

# Assemble cover page Document, should generate only 1 page within weasy_coverpage_doc.pages.
coverpage_html_string = "... your function that returns coverpage html string ..."
weasy_coverpage_html = HTML(string=coverpage_html_string)
weasy_coverpage_doc = weasy_coverpage_html.render()

# Assemble content Document.
html_string = "... your function that returns content html string ..."
weasy_html = HTML(string=html_string, base_url=markdown_path)
weasy_doc = weasy_coverpage_html.render()

# Insert first (will be only) page from weasy_coverpage_doc into pages in weasy_doc.
weasy_doc.pages.insert(0, weasy_coverpage_doc.pages[0])
weasy_doc.write_pdf(f"content_with_coverpage.pdf")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS Questions about how to do something with CSS
Projects
None yet
Development

No branches or pull requests

4 participants