Best way to add page number to new PDF file?

This Forum is for the use of End Users requiring help and assistance for Tracker Software's PDF-Tools Version 4

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan

Post Reply
Posts: 9
Joined: Sat Jul 06, 2013 8:12 am

Best way to add page number to new PDF file?

Post by black71 » Sat Jul 06, 2013 8:33 am

Hi All, this is my first post!!
I've this problem: I have a source pdf file, and I programmatically merge it with some part of other pdf files (using VB.NET and your API in xppro.DLL - PDTools SDK) , finally I create a big Output.PDF file.
At this point I need to add text at right bottom of each page of Output.pdf file with page number.. but I'm not able to do it!!!
Should I use watermarks? API function AddTExtAnnotation?
Where could I retrieve a sample VB code showing me the right way to do what I'm looking for?
Thanks in advance,

John - Tracker Supp
Site Admin
Posts: 8204
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada

Re: Best way to add page number to new PDF file?

Post by John - Tracker Supp » Mon Jul 08, 2013 9:27 am


You should see the example in the VB source examples folder 'PXCPro_Demo' (VB_PXCProSample.exe in the examples bin folder) - this will provide you with the detail required to do as requested.

If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support

Posts: 9
Joined: Sat Jul 06, 2013 8:12 am

Re: Best way to add page number to new PDF file?

Post by black71 » Mon Jul 08, 2013 11:10 am

That folder has been my bible for weeks regarding merging files and so on...but it doesn't seem having anything useful for adding text to a existing page...
The other demo project seemed interesting for what I need, it uses pxclib40.dll for low level API:
This is what I was going to write:

Code: Select all

origin.x = cr.Right - 100
origin.y = cr.Bottom + 20 
res = PXC_NewDocument(m_pdf, g_initstr, g_initDevCode)

For i = 0 To m_PagesCount - 1
   res = PXC_GetPage(m_pdf, i, Page)
        topt.FontID = fntID
        topt.FontSize = P2L(25)
        PXC_SetTextOptions Page, topt
        PXC_SetCurrentFont Page, topt.FontID, topt.FontSize

        res = PXC_TextOutA(Page, origin, "Page " & i, -1)
Next i
PXC_ReleaseDocument m_pdf
This code obviously lacks one important thing:
an instruction like :

Code: Select all

res = PXCpVB_ReadDocumentW(m_pdf, m_strOutputFile, 0)
to associate the integer "m_pdf" to an existing file .pdf

It seems the only way it works is creating a NEW page, instead of cycling every single page of an existing pdf file..
Should I use a different function? I cannot find solutions, I looked for it all yesterday. :(

Nico - Tracker Supp
Posts: 220
Joined: Fri May 18, 2012 8:41 pm

Re: Best way to add page number to new PDF file?

Post by Nico - Tracker Supp » Mon Jul 08, 2013 6:53 pm

Hi black71,

Thank you for your post and welcome to the forum.
You are right, the only way to add text to an existing pdf document with PDF-Tools is by creating a new document with the PXC functions, and copy all the contents from the existing document to the new document and add the text you want. This can be accomplished but it is quite difficult. A better way would be to use the PDF-XChange Viewer ActiveX SDK and add a text annotation with the page number by using JavaScript (check out the JavaScript example from the Viewer ActiveX SDK and Adobe JavaScript API reference: ... erence.pdf) or you can use the Drivers API to add headers and footers to the document, although printing from PDF to PDF is not a real solution.
Please don't mix up PXC and PXCp functions, they are not interchangeable. PXC functions are for creating new documents and PXCp are for manipulating existing documents and they act on different objects (you cannot use PXCpVB_ReadDocumentW() with PXC_Document())


Post Reply