Page 1 of 1

Page number in Header/Footer starts at 2

Posted: Thu Feb 17, 2022 4:57 pm
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
Try
m_pxcInst.Init(g_RegKey)
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)
PDF.WriteToFile(DestinationPDF)
PDF.Close()
Catch ex As Exception
MsgBox("AddHeaderAndFooter Error: " & ex.Message)
Finally
Try
m_pxcInst.Finalize()
Catch
End Try
End Try
End Sub

Re: Page number in Header/Footer starts at 2

Posted: Sat Feb 26, 2022 5:11 am
by Vasyl-Tracker Dev Team
Hi mmanuel.

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

firstHeaderFooter.Start = 0

Cheers.