Make a complete copy of a PDF

My intent is to make a new copy then save() it so I can get the page
count.
How can I make a complete copy of the Pdf() object?

Alternatively I’d like to copy the contents a page to a new Pdf object.

Hello Dan,

Thanks for considering Aspose.

I'm afraid I'm unable to understand your requirement.

Can you please elaborate your requirement that either you want to make a copy of the PDF object when saving a PDF document which is being generated by Aspose.Pdf or you need to make a copy of any existing PDF document ?

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

FYI, if you are using Aspose.Pdf for .NET to generate a PDF document, you can try using the PageCount property of Pdf class, which the pages count of the generated PDF. You can only get the value of this property when the Save method is called. Or in case you want to count the number of pages present in any existing PDF document, please try using the NumberofPages property of PdfFileInfo class present in Aspose.Pdf.Kit, which returns the total number of pages present in any existing PDF document.

Thank you for the quick response.

My primary requirement is to know when paragraphs wrap to another page so that when text does wrap that I can place text on a line at the bottom of the first page and also at the top of the next page.

(I asked about that ability in another thread but was informed there was no property to allow it.)

I’ve devised a method to allow me to do the above requirement. I add one paragraph at a time, then save() and test the page count. If the pagecount has incremented then I know the paragraph is wrapping. If it wraps I then delete the new paragraph and add it again but with one word removed, then I test it again.

I continue the above method until the paragraph fits exactly. This all works perfectly, although slowly, but it works well.

The problem is that each time I am adding, removing and testing, the page count continues to climb. So I get page numbers like 3865, then 4194, then 5274 etc.

So the problem seems to be the pagecount not reverting when a page has effectively been removed.

My proposed solution to this last problem would be to have a primary a secondary PDF. The primary would be the final PDF. The secondary would be the testing PDF which I would perform the paragraph fit test so the page numbers of the primary PDF remain correct.

In order for me to do this I need to be able to copy individual pages between the primary and secondary PDF objects.

Alternatively, if at the last page I could set the total pagecount on every page that would work as well. (“page 1 of x”)

(note: I am currently only using Aspose.PDF for .NET although we have 4 licenses for Total working through procurement.)

Hello Dan,

Thanks for considering Aspose.

Regarding your requirement of setting the correct page number for the PDF document, please try using the IsPageNumberForDocument property of Pdf class, which indicates whether total page number is count for whole document and when this property is set to true, the "$P" symbol will be replaced by the total page number of the document. Or when you are adding, removing and testing the paragraph length, you may also try using the IsPageNumberRestarted property of Pdf class.

Please try using them, or in case you still face any problem, please share the code snippet that you're using, so that we can test the scenario at our end.

We apologize for your inconvenience.

I’ve tried all combination for those but the numbering is still off. Am I able to create my own section at the bottom of every page and set an ID for those sections and then set the page numbers just before I save the PDF? I haven’t found any good example for setting the ID.

My code is a bit more than just a snippet.

Can I privately send you a sample PDF and some of the code?

Well… not the best solution but this appears to be the only solution at the moment. I first create the PDF completely in order to get the total page count. I then re-create the PDF and set the page footer manually using the total page count from the first run.

So it has to do double the work. And this isn’t a great solution for 1000+ page documents but it will have to do for now.

I think the page count issue will go away if I can have a real solution for my previous thread:
Adding &quot;continued&quot; to bottom of a wrapped page

Hello Dan,

Thanks for your interest in our products.

I've marked this forum thread as private, and now the contents shared in this thread are only accessible to Aspose staff members. In case you're still not confident while sharing the artifacts here, you can also send them directly to us, while following the instructions specified over How to send a license?

We apologize for your inconvenience.