Xojo Plugin Requires Chilkat v11.7.0+
Xojo Plugin
Page Numbers, Dates and the File Name in a PDF Watermark
See more PDF Watermark Examples
Demonstrates the placeholders a text watermark understands, each replaced per page as the watermark is added: {page} is the page number, {pages} the page count, {date:FORMAT} the current local date and time, and {filename} the name of the file that was loaded. Two braces give a literal brace. pageNumber.start sets what {page} is on the first page, which is how a numbering that ignores a cover is produced, and pageNumber.style formats both {page} and {pages} as decimal, romanUpper, romanLower, letterUpper or letterLower.Chilkat Xojo Plugin Downloads
Dim success As Boolean
success = False
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The PDF used in this example is available at four_pages.pdf
Dim pdf As New Chilkat.Pdf
success = pdf.LoadFile("qa_data/pdf/four_pages.pdf")
If (success = False) Then
System.DebugLog(pdf.LastErrorText)
Return
End If
Dim json As New Chilkat.JsonObject
success = json.UpdateString("type","text")
success = json.UpdateString("text","Page {page} of {pages} - printed {date:yyyy-MM-dd HH:mm} - {filename}")
success = json.UpdateString("id","pagefoot")
success = json.UpdateString("position.align","bottom")
success = json.UpdateNumber("position.margin","24")
success = json.UpdateNumber("font.size","9")
success = json.UpdateString("color","#505050")
Dim jsonOut As New Chilkat.JsonObject
success = pdf.Watermark("add",json,jsonOut)
If (success = False) Then
System.DebugLog(pdf.LastErrorText)
Return
End If
System.DebugLog("footer pages: " + jsonOut.StringOf("pages"))
// Roman numerals that start at i on page 2, so that a cover page is not numbered.
Dim pdf2 As New Chilkat.Pdf
success = pdf2.LoadFile("qa_data/pdf/four_pages.pdf")
If (success = False) Then
System.DebugLog(pdf2.LastErrorText)
Return
End If
Dim json2 As New Chilkat.JsonObject
success = json2.UpdateString("type","text")
success = json2.UpdateString("text","- {page} -")
success = json2.UpdateString("id","roman")
success = json2.UpdateString("pages","2-")
success = json2.UpdateInt("pageNumber.start",1)
success = json2.UpdateString("pageNumber.style","romanLower")
success = json2.UpdateString("position.align","bottom")
success = json2.UpdateNumber("font.size","10")
success = pdf2.Watermark("add",json2,jsonOut)
If (success = False) Then
System.DebugLog(pdf2.LastErrorText)
Return
End If
System.DebugLog("roman pages: " + jsonOut.StringOf("pages"))
success = pdf.WriteFile("qa_output/four_pages_numbered.pdf")
If (success = False) Then
System.DebugLog(pdf.LastErrorText)
Return
End If
// Sample output:
// footer pages: 1-4
// roman pages: 2-4