Free Support Forum - aspose.com

Page Numbering without cover page

Hi,

We are rendering PDF with the help of Aspose Library in .NET environment.
We have top cover page and then data. We are using page numbering in header. Issue is we need to ignore first cover page in page numbering total count as well as in start count.

Please review the provided details and let us know any solution to resolve the issue.
if any other details needed, please do ask.

Thanks.

@ovais

Thanks for contacting support.

You can extract first page of the PDF and create separate PDF document without the cover page and apply page number over it. Later, you can re-merge cover page with numbered pages and save as new PDF. Please check following articles which may help you achieving the requirement:

In case you find any issue while achieving what you require, please share a sample PDF document along with sample code snippet you are using to add page numbers. We will test the scenario in our environment and address it accordingly.

Hi Asad,
Thank you for the response.
the proposed solution is not working for me as the pdf generates actual page numbering on document.save() call and we are using delegate “OnPageGenerate” to set the header.
We can use our manual page numbering as well but we will not be able to get the total page count before save() call. hope you got my point.

Thanks.

@ovais

You may call ProcessParagraphs() method of Document object. This way you will get correct page count of PDF before document is saved. In case you still face any issue, please share your sample code snippet along with sample PDF document, so that we can test the scenario in our environment and address it accordingly.

@Farhan.Raza

This solution works fine but it is taking double time as “ProcessParagraphs()” takes time first and then “Save()”. Due to this we are facing performance issue.
Please if you can provide a better solution whihch has no performance impact.
Thanks.

@ovais

We are afraid performance overhead will occur in this case. However, kindly share SSCCE code along with sample document so that we may log a performance enhancement ticket to check improvment possibilities.

@Farhan.Raza
The dev will share the code and example with you. Meanwhile I have a quick question; on paid support do Aspose only resolve issues/bugs or will you address feature requests as well?

@10pearls

Please take all the time you need and get back to us as per your convenience. Paid Support includes bug fixes as well as feature requests.

@Farhan.Raza

I have attached the sample project link in which you can see the the generated PDF.
In the PDF, we need to start page count from page 2 starting with “1”, but it stars with “2 of [Total]”

The above attached project is a console App,
You just need to run it with following steps,

  • In "PdfGeneration.cs" file, at line number "22", change "InfiniteProcedure.json" to "NormalProcedure.json"
  • Run the project
  • It will ask you for number of threads, set to "1"
  • t will ask you for number of counts, set to "1"

You can find the generated page in “PdfProcedures” folder

FYI: In “PdfHelper.cs” class, At line number “599”, we generate page numbers.

Please have a look at attached project and let us know that how we can resolve the issue we are facing.
Your help in this regard will be highly appreciated.
Thanks,
Ovais

@ovais

Thanks for sharing sample project.

We have checked your project and noticed that you are using expression ($p of $P) to display page numbers. Since you cannot use ProcessParagraphs() method due to performance overhead, You may probably try using different approach (probably workaround) to add page numbers. For an instance, you can change your call to AddHeader() method in OnPageGenerate() method as following:

AddHeader(metaInfo, page, page.Number - 1, sectionId, isCoverPage, sectionHeaderHtml, (showSectionPageNumbers ?? false), lstElementEntity, lstElementPropertyEntity, lstStepEntity, generatedFiles, isChangeLog, coverChangeLog);

AND at the line number “599”, you can change the statement as following:

TextFragment hfHeaderTxt2 = new TextFragment("Page " + pageNumber + " of $P");

With the above-mentioned changes, the attached PDF has been generated in our environment. You may further modify your code as well according to your actual needs. Please share your feedback in case our suggestions do not suit your requirements.

JohnMcClane_The Die Hard Films (1988-2013)_5248857363648552693.pdf (115.8 KB)

@asad.ali

Thanks for the detailed answer, Its working for the page number but I have issue with total page number as well. The generated PDF prints total count is 8 and last page prints Page 7 of 8.
The requirement is to skip first page from page count as well as total count.
Thanks.
Regards,
Ovais

@ovais

Thanks for your feedback.

We again checked the sample project that you have shared and would like to suggest you that you could generate PDF document without Cover Page in original method i.e. PdfHelper.GeneratePdf(). Once the document is generated and filename is obtained successfully in PdfGeneration.GeneratePdf() method, you can insert Cover Page there. Please check the attached screenshot. InsertCoverPage.png (44.3 KB)

Please also note that you do not have to implement previously suggested code changes in this case. You will only shift cover page related code in other Class where you obtain filename of generated PDF. Please let us know about your feedback against this suggestion.