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


Please ask...

Although we really tried hard, there are always questions left open.

Please send us your question.
We would be glad to answer it.

Suggested Fonts

Below find a list of suggested fonts. These fonts do not increase the filesize of the PDF Document

Courier
CourierBold
CourierBoldOblique
CourierOblique
Helvetica
HelveticaBold
HelveticaBoldOblique
HelveticaOblique
TimesRoman
TimesBold
TimesItalic
TimesBoldItalic
Symbol
ZapfDingbats
PDF SDKPDF Signature APICertificate PropertiesSample CodeText StampsPage NumberingPDF AttachmentsImage 2 PDFPDF to Multipage TIFFAppend PDFInsert Blank PageRender ImageStamp PDF with PDFDraw PDF as LetterheadApply LetterheadPDF BackgroundsAdd NotesURL HotspotSecure PDF ViewerPDF OptimizerPDF Encryption APIPDF Printing APIPDF BookmarksPDF BarcodingMerge PDF DocumentsSample APIsResize PDFCrop PDF PagePDF InformationPDF2TXTNormalize PagesDirect PDF ConversionPDF Form Saver SDKSmart Card APIAloaha Web ServicesAloaha Print MonitorAloaha Remote ConfigurationWebDAVLDAP ClientProgramming Office MacrosIIS Event Sinks