ASPOSE.PDF.Kit - Page Numbers in Merged File

Hi,

I'm using ASPOSE.PDF.Kit to merge two different PDF documents.

Query:

The requirement is to add page numbers to resultant document. That is I would like have page numbers from 1 till in the merged document.

I had a look at the library ASPOSE.PDF.Kit, however I could not see any property exposed to do the same. Please suggest me any solution.

Please let me know if you need any further information.

Thanks in advance.

- Damodar Shanbhag

Please refer to PdfFileStamp.AddPageNumber Method. Sample codes are as follows:

Example

[C#]
System.String inFile = "text.pdf";                            
System.String outFile = "textwithpagenumber.pdf";
PdfFileStamp fileStamp = null;                                

fileStamp = new PdfFileStamp(inFile, outFile);
FormattedText ft = new FormattedText(“Page #.”,System.Drawing.Color.FromArgb((0,200,0),
FontStyle.TimesRoman,EncodingType.Winansi,false,12);
fileStamp.AddPageNumber(ft);
fileStamp.Close();

[Visual Basic]
Dim inFile As String = “text.pdf”
Dim outFile As String = “textwithpagenumber.pdf”
Dim fileStamp As PdfFileStamp = Nothing

fileStamp = New PdfFileStamp(inFile, outFile)
'add page number
Dim ft As FormattedText = New FormattedText(“Page #.”,System.Drawing.Color.FromArgb((0,200,0),
FontStyle.TimesRoman,EncodingType.Winansi,False,12)
fileStamp.addPageNumber(ft)
fileStamp.close()

Hi,

Thanks very much for sharing the code, Kevin.

I'm using ASPOSE.Pdf.Kit.dll library (version 1.4.0.0).

In this library, I do not find "addPageNumber()" method in PdfFileStamp Class.

Do I need to use a different version of the library?

Please let me know if you need any further information.

Regards,

- Damodar

Hi,
You need to download the latest version of Aspose.Pdf.Kit. Here is the url.

Hi Damodar,

Method addPageNumber() is available since Aspose.Pdf.Kit v1.8.4.0. So at least you should download this release to get it work.

Hi

Thanks for the information and I could use "AddPageNumber()" method using new version of dll.

Here is the issue which I'm facing now:

  1. . Merging & Re-numbering the pages

Let us consider an example where I'm merging pdf document A ( having 4 pages - page numbers from 1 till 4) and pdf document B (having 3 pages - page numbers from 1 till 3).

The resultant merged doucment C (containing 7 pages), I would like to have document page numbers from 1 till 7.How can I go about doing this?

Is there a way I can erase the numbers which were printed earlier and then re-number the same?

(Note: Erasing might be quite challenging as we do not know much about input documents of this merger component and where exactly has the page number is positioned in the document)

2. Positioning the page numbers

As of now, the page numbers are getting printed at "Bottom - Center" of the page. Can I change the position, where page number is getting printed? I would like to have page numbers at say Right bottom corner ro Top Right corner etc..........Please let me know your suggestions.

Let me know I you need any further information.

Thanks in advance.

Regards,

- Damodar

Dear Damodar,

1. Merging & Re-numbering the pages

You can use PdfFileEditor.Concatenate firstly to merge multi PDF documents into one, save the merged result in a stream object, new a PdfFileStamp taking the stream object as parameter, then use PdfFileStamp.AddPageNumber to number the pages.

Note: Erasing the numbers coming from multi PDF documents is not available in Aspose.Pdf.Kit.

2. Positioning the page numbers

This feature is not provided now. But we would like to support this function in a short time. Please give us more information about your requirement such as the design of API and parameters.

Thanks Kevin,

Please let me know if there is any solution for the first requirement which I had specified ( Merging & Re-numbering the pages)?

As every document will have page numbers and merging two such documents requires continuation of for page numbers....

Let me know if you need more information on the same.

Thanks and regards,

- Damodar

Hi,

This is regarding positioning page number:

First of all, I feel adding page number is a very cumbersome process.

Example:

If I use ASPOSE.Pdf.Kit to merge two PDF documents A.pdf and B.pdf with a result C.pdf (merged file). To add page number to this C.pdf, I might need to create one more output file (say D.pdf) and store both C.pdf and D.pdf. It is bit over head to create input/output file everytime I need to add some content to page.

Is there a better approach to add page number than using PdfFileStamp where I need to save output file twice. Also an internet application to be able to save very time and retrieve from repository, will definitely an burden on server which affects the performace.

Any suggestions?

Also to position the page number, if I could get some attribute like "align" which will align the resultant text to Right/Left/Center of the page. That will do. Please let me know if you need any further information.

Thanks

- Damodar

In Web application,you can save the merged and page-numbered result both as Stream objects. For example.

If FileStream fsa contains A.pdf, FileStream fsb contains B.pdf, MemoryStream ms will hold the merged pdf named c, then you could respond to clients with page-numbered pdf named d in HttpRespond stream.

//read input Pdf documents
FileStream fsa= File.Open(inputfile1,FileMode.Open,FileAccess.Read,FileShare.Read);
FileStream fsb= File.Open(inputfile2,FileMode.Open,FileAccess.Read,FileShare.Read);

//new a PdfFileEditor object
PdfFileEditor pdfEditor = new PdfFileEditor();

MemoryStream ms= new MemoryStream();
MemoryStream out= new MemoryStream();
pdfEditor.Concatenate(fsa,fsb,ms);

fileStamp = new Aspose.Pdf.Kit.PdfFileStamp(ms, out);
FormattedText ft = new FormattedText("#",System.Drawing.Color.FromArgb(0,0,0),Aspose.Pdf.Kit.FontStyle.TimesRoman,EncodingType.Winansi,false,12);
fileStamp.AddPageNumber(ft);
fileStamp.Close();


byte[] outBuf = out.GetBuffer();

//response to user's web.
response.Expires = 0;
response.Buffer = true;
response.ClearContent();
response.AddHeader("content-disposition","inline; filename=" + "output.pdf");
response.ContentType = "application/pdf";
response.BinaryWrite(outBuf);
outStream.Close();
response.End();

Setting alignment of page number is not provided yet. The developers will support properties in near future release.

Please download hotfix 2.3.3.0