Page number in Header/Footer starts at 2

A forum for questions or concerns related to the PDF-XChange Core API SDK

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

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
Posts: 1
Joined: Thu Feb 17, 2022 4:39 pm

Page number in Header/Footer starts at 2

Post by mmanuel »

I'm currently trying to implement Page numbers in the footer of PDFs using PDFXChange Core API version 7.0.0327.1 using the following code. Is there way to get the number to start at 1? Currently with the current code below the first page shows 2 of ? and not 1 of ? so %[Page] is getting replaced with a 2 on the first page causing the last page to have 16 of 15 for example.

Public Shared Sub AddHeaderAndFooter(ByVal PDF As IPXC_Document, ByVal DestinationPDF As String)
Dim m_pxcInst As New PXC_Inst
Dim auxInst = CType(m_pxcInst.GetExtension("AUX"), IAUX_Inst)
Dim firstHeaderFooter = m_pxcInst.CreateHeaderAndFooterParams()
Dim font = PDF.CreateNewFont("Arial", CUInt(PXC_CreateFontFlags.CreateFont_Serif), 400)
Dim fillColor As IColor = auxInst.CreateColor(ColorType.ColorType_RGB)
fillColor.SetRGB(0, 0, 0)
firstHeaderFooter.Font = font
firstHeaderFooter.FillColor = fillColor
firstHeaderFooter.CenterFooterText = "%[Page] of %[Pages] %[Date:MM.dd.yyyy] %[Time]"
firstHeaderFooter.BottomMargin = 30.0F
firstHeaderFooter.TopMargin = 36.0F
firstHeaderFooter.RightMargin = 36.0F
firstHeaderFooter.LeftMargin = 36.0F
firstHeaderFooter.FontSize = 10.0F
Dim pages As IPXC_Pages
pages = PDF.Pages
Dim bitset As IBitSet = auxInst.CreateBitSet(CUInt(pages.Count))
bitset.Set(0, CUInt(pages.Count))
PDF.PlaceHeadersAndFooters(bitset, firstHeaderFooter)
Catch ex As Exception
MsgBox("AddHeaderAndFooter Error: " & ex.Message)
End Try
End Try
End Sub
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2234
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Page number in Header/Footer starts at 2

Post by Vasyl-Tracker Dev Team »

Hi mmanuel.

Sorry for delay with the answer. Try to use this workaround:

firstHeaderFooter.Start = 0

Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Post Reply