Different dynamic footers in each page

48 views
Skip to first unread message

nerrierr

unread,
Jan 27, 2019, 4:20:40 PM1/27/19
to wkhtmltopdf General
Hello,

Is there a way to define different dynamic footers in each pdf page?
For example, something like this:
    On Page 1 -> img in the bottom of the page
    On Page 2 -> no footer
    On Page 3 -> some text with some details in the bottom of the page

More specifically I need to be able to define content (the unique footer) that is inserted after some specific element (that is generated dynamically with variable length of content) and on whatever page that element ends, put the "footer" at the bottom of the current page.

I am working on implementing a pdf reporting mechanism with the content defined in html. I based my solution around wkhtmltopdf and .Net ASP MVC and found myself stuck on this "needed functionality"

Can this be done somehow by wkhtmltopdf?
Something similar can be done in the html file using css (using div with specific size for each pdf page), but that only works for static content. For dynamic html content you don't really know where things end up (on what page your content will be since the paging is decided by wkhtmltopdf)


Thank you,
Signed,
A developer in need of help

Jakob Truelsen

unread,
Jan 28, 2019, 1:03:28 PM1/28/19
to wkhtmltop...@googlegroups.com
You dynamically change the content of headers of footers, as the page
numbers are provided in the query arguments. The header and footer are
generated after the pages are printed, so they cannot have dynamic
height. You need to either modify wkhtmltpdf to find the location of
those elements and provide them to the header/footer generation, or
you can use some hack.

One hack you can use is to output hidden <h1 > tags together with the
specific html tags you are looking for, and then not use h1 for
anything else in the document. The content of the last <h1> tag can
then be found in the ?section=xxx query parameter.

If you need something more specific than this, you will have to modify
wkhtmltopdf, to figure out what modifications to make, it would be
good to look at how we currently generate the section query parameter.

/Jakob
> --
> ===================================================
> You received this message because you are subscribed to the "wkhtmltopdf General" group.
> To post to this group, send email to wkhtmltop...@googlegroups.com
> To unsubscribe from this group, send email to wkhtmltopdf-gen...@googlegroups.com
>
> For more options, visit this group at
> http://groups.google.com/group/wkhtmltopdf-general?hl=en?hl=en
> ---
> You received this message because you are subscribed to the Google Groups "wkhtmltopdf General" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wkhtmltopdf-gen...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

nerrierr

unread,
Jan 28, 2019, 1:25:03 PM1/28/19
to wkhtmltop...@googlegroups.com
Hi,

I'm a little sad that there isn't a more flexible (built-in) way to do this, but I thank you for the quick response.
I will try to see if using query arguments will suffice (but most likely not since I will probably also need to have the footer size dynamic).
If that doesn't work I will try to go the JavaScript route and edit the size of elements at run-time that way (but I assume it will be a little complicated, slow-running and generally ugly code).

Regards,
Signed,
A slightly disappointed developer
Reply all
Reply to author
Forward
0 new messages