signintech / gopdf

A simple library for generating PDF written in Go lang
MIT License
2.46k stars 269 forks source link

Get count of pages easily. #163

Open hsluoyz opened 3 years ago

hsluoyz commented 3 years ago

Is there an easy way to get the number of pages?

misterunix commented 3 years ago

Track each time you call gopdf.AddPage(). That's what I do.

necrophidia commented 3 years ago

@hsluoyz you could use GetNumberOfPages now.. :) https://github.com/signintech/gopdf/pull/165

hsluoyz commented 3 years ago

But how to get the page count of a PDF file.

If we import the PDF: https://github.com/signintech/gopdf#import-existing-pdf , how to import all the pages of that PDF? In gopdf we don't know the page count, so the for loop has no ending condition.

For example, create PDF file B, import all the pages from PDF file A to B (with some modifications like adding footer). There's no easy way to get the page count of A, but for importing pages, you have to know the page index of A.

Another way is to return error in UseImportedTemplate() when the page index is out of page count, but it doesn't.

necrophidia commented 3 years ago

Ah.. okay.. I misunderstood your question. Previously I use a c-go library for importing another pdf (as images) to be used in Gopdf due to this limitation also.

vantaboard commented 1 month ago

@oneplus1000 can you close this issue if it has been resolved?