A page numbering task

I want to use Aspose.Words and Pdf.Kit to perform the following tasks:

  1. Add header and footers to text documents and save result to PDFs. The footer I add must contain some placeholder for page number (the number itself will be known later on stage 3). (Used: Aspose.Words)
  2. Combine several PDFs, got at previous stage, into single PDF. Used: (Pdf.Kit.PdfFileEditor)
  3. Add page number at placeholder positions to each page of that PDF. It must be formatted like "X of Y", where X is page number and Y is total number of pages in that PDF. (Used: Pdf.Kit.PdfFileStamp)

I need placeholders because input document (processed on stage 1) can have different page layout and so I don't the know exact position of footer.

I tried using form fields as placeholders and filling them with Pdf.Kit.FormEditor. Suppose I have form field "qwe" put to footer on stage 1. Form fields have breeded one per page. But they have names like "qwe.43736594" and I don't know which one resides on which page.

Can you help me with my solution or offer a better one?


Hi Eugene,

As I can understand, you’re trying to add form fields using Aspose.Words. You need to discuss it with Aspose.Words team if this is possible to assign unique names to the form fields while adding them using Aspose.Words. You can post your query in this forum.

I think, once you know which fields are on which page, you would be in a better position to add page numbers. However, I would like to share with you that you can also add page numbers using Aspose.Pdf.Kit as well. Please find the details and an example on this link. As you need to format the page numbers as ‘X of Y’ i.e ‘Current Page Number of Total’. You’ll also need the total number of pages, which you can get using PdfFileInfo.NumberOfPages. Please try it at your end and see if it can help in your scenario.

If you think I haven’t understood your requirement clearly then please share a sample input PDF file along with the sample output you want to generate.

We’re looking forward to help you out.
Regards,

I can not add page numbers using Aspose.Pdf.Kit because it requires coordinates to be specified. My document can have pages with different margins, so I don't know the position of footer.

Yes, I will ask Aspose.Words team some questions.

BTW, is there a way to determine the page of specified form field using Pdf.Kit?

Hi Eugene,

Yes, you can get the page number of a particular PDF form field using Form and FormFieldFacade classes. The following code snippet shows you how to do this:



//create Form object with input PDF file

Form pdfForm = new Form(“input.pdf”);

//get FormFieldFacade of the particular field

FormFieldFacade fieldFacade = pdfForm.GetFieldFacade(“FirstName”);

//get page number of a particular filed

Console.WriteLine(“Page Number: {0}”, fieldFacade.PageNumber);

Console.ReadLine();


I hope this helps. If you have any further questions, please do let us know.
Regards,

I tried to use you advice, now I have another problem. After I fill fields using Pdf.Kit.Form class, the look of fields is changed much. I have attached C# project that demonstrates my usage scenario. Compare field look in 1.pdf and 2.pdf. Why it happens?

Hi Eugene,

Thank you very much for sharing the sample application. I have tested this issue at my end and noticed that the text in the fields when filled moves a little bit down and looks cut off. I have logged this issue as PDFKITNET-19073 in our issue tracking system. Our team will look into this issue and you’ll be updated via this forum thread once it is resolved.

We’re sorry for the inconvenience.
Regards,

Accidentally I found a workaround for this bug. I called FormEditor.DecorateField() for each field I filled, and fields look became normal.

FormEditor fe = new FormEditor(@"2.pdf", @"3.pdf");
var fff = new FormFieldFacade();
fe.Facade = fff;
foreach (string field in fieldNames)
if (field.StartsWith("pn."))
{
fe.DecorateField(field);
}
fe.ResetFacade();
fe.Save();

I don't know what DecorateField() does, but it worked. This is still unacceptable, because it requires to make one more intermediate file. Still waiting for fix.

Hi Eugene,

This issue is resolved and a fix will be available in our upcoming monthly release. The new release will hopefully be published at the end of the next week.

If you find any further questions, please do let us know.
Regards,

The issues you have found earlier (filed as 19073) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.