Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Access to Current Page [page] and Number of Pages [toPage] outside of headers and footers #1889

Closed
RafaPolit opened this issue Aug 4, 2014 · 13 comments

Comments

@RafaPolit
Copy link

There are many situations where I need to access the page number inside the 'body' of the PDF and not only on headers and footers. Is there a way to do that, or any implementation that can be made to access the data?

Thanks,
Rafael Pólit.

@ashkulz
Copy link
Member

ashkulz commented Aug 22, 2014

Nope, that can't be done -- it would possibly change the layout of the page, possibly generating new pages ... and so on.

@engwan
Copy link

engwan commented Sep 11, 2014

+1 on this.

Today I found myself needing to add something like this in the body: "This document is xx pages long".

I'm thinking of doing this in Javascript. The JS in headers / footers are run in a separate context right? So I can't use that to increment a global variable.

So I'm planning to computing the number of pages from document.scrollHeight. Is there a way to get the page size in JS? Or do I have to hard code it or pass it through url params?

Like @ashkulz said, after JS replaces the div / span with the page number, the layout can possibly change and can possibly flow into a new page, etc.. But for 90% of the use cases, I think this won't be a problem.

It's also possible to put placeholder text inside the element like <span class="topage">xx</span>, so that the layout won't change too much.

@lssilveira11
Copy link

I need this feature too!

Actually, this feature can be veeeery powerfull. Think this way: you have many figures in you webpage. Each figure have a div bellow them with a span to show the legend text and a input[type=hidden] with the value [page] or [frompage].

What you can do with this? TABLE OF FIGURES!!

In javascript, you can build a ul grabbing all the legend of the figures, and then check the value of the input[type=hidden] to get the page number of that element, because the process will have replaced the [page] text in the value of these inputs with the actual page number value.

But, we don't have this feature (yet) ... :(

@CaroEvans
Copy link

Is this feature still not available?

@faheemhameed
Copy link

Would be great and very useful to have this feature. Thanks!

@deruiter2
Copy link

deruiter2 commented Apr 16, 2019

Is there any news on this feature? Would be very useful for a project i'm working on.

@flyingangel
Copy link

Source: https://wkhtmltopdf.org/usage/wkhtmltopdf.txt
Scroll down to example of function subst()

@louissmsfactor
Copy link

@flyingangel Can you please read the subject? They need outside header or footer!

@aliencrash
Copy link

I have another way we could use this.
For example for invoices that break for different pages, it requires us for the first page create the subtotal and the start of the next page the transported value. At the end the next page, if there is more pages always have a transported value summed up with the rest of the tables.

@admcfajn
Copy link

@louissmsfactor Could you please not revive topics that are years-old just to correct someone else who is trying to help?

@louissmsfactor
Copy link

@admcfajn he wrote his answer in september... and he helped nobody, his answer is irrelevant.
@aliencrash did you find a workaround to accomplish this?

@admcfajn
Copy link

admcfajn commented Jun 24, 2020

@louissmsfactor you're coming across a bit rude is my point. Frankly cross-posting that relevant info may have helped somebody, i mean really who are you to say "[they] helped nobody". i think you may be underestimating what their small contribution to this thread may have done. In fact, i found it to be helpful reminder just yesterday when i was troubleshooting issues related to this topic

If you don't have anything good to say, maybe you should consider not saying anything, or not typing anything as the case may be

@ashkulz
Copy link
Member

ashkulz commented Jun 25, 2020

I'm locking this conversation. Although this is obviously good to have, I'm not sure how it can be implemented right now -- the focus right now is upgrading the browser engine (read the project status), this will come after/if it gets upgraded.

@wkhtmltopdf wkhtmltopdf locked as too heated and limited conversation to collaborators Jun 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests