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

Is there a way to get the current page number during pdf generation? #461

Open
marvfinsy opened this issue Jun 25, 2024 · 8 comments
Open
Labels
good first issue Good for newcomers new feature New feature or request

Comments

@marvfinsy
Copy link

marvfinsy commented Jun 25, 2024

Is your feature request related to a problem? Please describe.
This feature is not related to a bug. But would help solve the below problem.

Describe the solution you'd like
While generating rows i want to be able to print a unique row on the first page but not any other. Also have the need to print extra information on only the last page.
Also need to alter headings and footers per page or based on page content (a certain description appears in footer if a unique line item appears on that page).

Describe alternatives you've considered
I assume that the heading code is executed for each page. Thought about a counter in the headings code.

Additional context

@marvfinsy marvfinsy changed the title Is there a way to get the current page during pdf generation? Is there a way to get the current page number during pdf generation? Jun 25, 2024
@nikolai-shilin
Copy link

you can manually count those when you add content as per page.New()

@lordofscripts
Copy link

The suggestion of using page.New() as a reference may not be entirely valid because you can create a new page and add as many rows as you want which may overflow to the next page.

@marvfinsy
Copy link
Author

ur correct. i'd have to calculate how many line items will fit on a page and call page.New() myself.

It would be nice to be able to register a callback on overflow to a new page.

@nikolai-shilin
Copy link

ur correct. i'd have to calculate how many line items will fit on a page and call page.New() myself.

It would be nice to be able to register a callback on overflow to a new page.

It would indeed, but there is no such option so far:)

@lordofscripts
Copy link

ur correct. i'd have to calculate how many line items will fit on a page and call page.New() myself.

It would be nice to be able to register a callback on overflow to a new page.

Great idea about the callback.

My tests indicate that on a Letter page without header and a simpler footer you can fit 244 row units.

Now, I reached a dead end here because the Row Height (which is for obvious reasons not part of Twitter Bootstrap) is way too limiting requiring much guess work, and the inability to plainly feed a paragraph and no means of calculating the necessary row height. I spent too many weeks thinking Maroto/V2 was THE solution. I saw myself in need of dumping all these weeks' work in favor of GoDocx which doesn't impose these unnecessary restrictions. It is not PDF but you can always print to PDF.

I hope there is some rethinking of this library so that it becomes viable for documents and not just premade forms.

@Fernando-hub527
Copy link
Collaborator

ur correct. i'd have to calculate how many line items will fit on a page and call page.New() myself.
It would be nice to be able to register a callback on overflow to a new page.

Great idea about the callback.

My tests indicate that on a Letter page without header and a simpler footer you can fit 244 row units.

Now, I reached a dead end here because the Row Height (which is for obvious reasons not part of Twitter Bootstrap) is way too limiting requiring much guess work, and the inability to plainly feed a paragraph and no means of calculating the necessary row height. I spent too many weeks thinking Maroto/V2 was THE solution. I saw myself in need of dumping all these weeks' work in favor of GoDocx which doesn't impose these unnecessary restrictions. It is not PDF but you can always print to PDF.

I hope there is some rethinking of this library so that it becomes viable for documents and not just premade forms.

Hello, about the automatic calculation of row height, I recently started working on this feature, it is not finished yet, however for the text component it is already working, if you can take a look and say if it is what you expected, it will be of great help! feature

I think the idea of ​​being able to register a function as a callback is great, I can add this feature!

@marvfinsy
Copy link
Author

Great... Will be looking for it... The power of the callback will be; when its called and what can be altered (header/footer) etc...

I am working on a some-what involved workaround. i have a situation where i'm generating an invoice. If this "special" line_item appears i need to add some "xtra text" on that page above the footer. To attempt this i have 2 ideas.

  1. When adding line items i call addRows() one line at a time. Before each addRows() call, i call FitInCurrentPage(). When no more space on the page i can add the "xtra text" before line_item_x. Then write line_item_x.
  2. If the above does not work, I might have to make 2 passes. The 1st pass is to remember what pages things appeared on. Then make a 2nd pass to generate the pdf.

@lordofscripts
Copy link

@Fernando-hub527

Hello, about the automatic calculation of row height, I recently started working on this feature, it is not finished yet, however for the text component it is already working, if you can take a look and say if it is what you expected, it will be of great help! feature

I cannot try it out because it has not made it out into neither 2.08 nor 2.0.9. What you write indicates it works fine for the text component. At this moment all I need is that it works for text, I need to feed paragraphs without having to bother about row height.

Any timeline when this change is going to make it to the main branch? else I forget about this forever and use godocx instead. I wanted to use PDF in several pet projects but if it isn't going to work then I might as well move forward with an alternative.

@Fernando-hub527 Fernando-hub527 added new feature New feature or request good first issue Good for newcomers labels Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers new feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants