You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Paged media CSS doesn't support more complex page header/footer requirements, like tables. A solution to this is to create a separate page with such a header, and merge this into the PDF on the required pages. A proof of concept was written by pikhovkin in this Gist.
I made a function to use this functionality with WeasyPrint, and would like to create a pull request to include this into Flask-WeayPrint, since it is such a common use-case.
(any comments about my coding is welcome, since I'm new to the Python language and community)
Overlay: Represents one HTML page to be overlaid on a PDF document.
template_name_or_list: the name of the HTML template, which is resolved with jinja2's get_or_select_template method.
fn_include_on_page: a function that takes a 0-based page number, and returns a boolean that indicates if it needs to be included on that page.
kwargs: context used to render the overlay. Can also be used to dynamically position content.
render_pdf_with_overlays renders the PDF like Flask-WeasyPrint's render_pdf, but with overlays.
stylesheets are also used to render the Overlay, so if any FontConfiguration is included, it is also included in the Overlays.
the overlays templates are rendered to HTML with the supplied context, and this context is extended with the page and pages entries, indicating current 1-based page number and number of pages (CSS page and pages counters don't work with single page overlays)
The text was updated successfully, but these errors were encountered:
Thank you for your comment and for your idea, it looks like a great solution. Next version of WeasyPrint may rely on pdfrw, a library able to edit PDF files. It's opening a large set of new possible solutions like this one, with or without an API in WeasyPrint.
However, your solution doesn't really rely on the Flask part of Flask-WeasyPrint and would be better discussed in Kozea/WeasyPrint#92. Could you please copy your comment in Kozea/WeasyPrint#92?
My solution does rely on Flask a bit (actually Jinja2) for rendering of the page number (which obviously varies per page). But I get your point, some work should be done in WeasyPrint first.
Paged media CSS doesn't support more complex page header/footer requirements, like tables. A solution to this is to create a separate page with such a header, and merge this into the PDF on the required pages. A proof of concept was written by pikhovkin in this Gist.
I made a function to use this functionality with WeasyPrint, and would like to create a pull request to include this into Flask-WeayPrint, since it is such a common use-case.
(any comments about my coding is welcome, since I'm new to the Python language and community)
My API is currently like this:
Overlay
: Represents one HTML page to be overlaid on a PDF document.template_name_or_list
: the name of the HTML template, which is resolved with jinja2's get_or_select_template method.fn_include_on_page
: a function that takes a 0-based page number, and returns a boolean that indicates if it needs to be included on that page.kwargs
: context used to render the overlay. Can also be used to dynamically position content.render_pdf_with_overlays
renders the PDF like Flask-WeasyPrint'srender_pdf
, but with overlays.stylesheets
are also used to render the Overlay, so if any FontConfiguration is included, it is also included in the Overlays.overlays
templates are rendered to HTML with the supplied context, and this context is extended with thepage
andpages
entries, indicating current 1-based page number and number of pages (CSS page and pages counters don't work with single page overlays)The text was updated successfully, but these errors were encountered: