Automatic Page Numbering
Aloaha contains several APIs to apply text to existing documents. For the page numbering example we will use the API
create_text_line.
public function create_text_line(T_X_Pos As Double, T_Y_Pos As Double, Alignment As Long, fontname As String, fontsize As Double, FontRed As Double, FontGreen As Double, FontBlue As Double, pdftext As String, pageno As Long) As Boolean
Please find below the full example how to apply automatic page number on every page of the pdf document.
Dim InFile
Dim OutFile
Dim pdf
Dim pages
Dim PageDimX
Dim PageDimY
Dim T_X_Pos
Dim T_Y_Pos
Dim Alignment
Dim fontname
Dim FontSize
Dim FontRed
Dim FontGreen
Dim FontBlue
Dim PDFText
Dim PWidth
InFile = "d:\mymerged-notok.pdf"
OutFile = "d:\out.pdf"
PWidth = 595 'A4
Set pdf = CreateObject("aloahapdf.edit")
If pdf.load_pdf_to_mem(CStr(InFile)) = true Then
pages = pdf.pdfpages
If pages>0 Then
fontname="Helvetica"
For i = 1 to pages
If pdf.go_to_page(CLng(i)) = true Then
'get page size in points
PageDimX=pdf.PageDimX
PageDimY=pdf.PageDimY
Call pdf.set_pagesize(CDbl(PWidth), CLng(i), false)
T_X_Pos=PWidth/2
T_Y_Pos=10
'Alignment Values
'0 = left, 1=center, 2=right, 3=justified
Alignment=1
FontSize=15
'Font Colors range from 0-1, 0.5 for example means 50%
FontRed=0
FontGreen=0
FontBlue=0
PDFText=CStr("Page "&CStr(i)& " of " &CStr(pages))
Call pdf.create_text_line(CDbl(T_X_Pos), CDbl(T_Y_Pos), CLng(Alignment), CStr(FontName), CDbl(FontSize), CDbl(FontRed), CDbl(FontGreen), CDbl(FontBlue), CStr(PDFText), CLng(i))
End If
Next
If pdf.save_pdf_to_file(CStr(OutFile)) = true Then
MsgBox "OK"
End If
Call pdf.unload_pdf_from_mem
End If
End If
Set pdf = nothing
If you need further information or help for this API please do not hesitate to contact us via the webform below.
Aloaha Software / Knowledge Base / PDF SDK / Text Stamps / Page Numbering