PowerBuilder Requires Chilkat v11.7.0+
PowerBuilder
Add a CONFIDENTIAL Watermark to Every Page of a PDF
See more PDF Watermark Examples
Demonstrates the simplest watermark: a line of text across every page. "rotation" set to diagonal runs the text from the bottom-left corner to the top-right, computed for each page size, and "scale" with fit page sizes it to fill 80 percent of the page. The watermark is stored as a marked artifact by default, which means viewers show it, text extraction leaves it out, and it can be found and removed again later. Nothing is written until WriteFile is called.Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Pdf
oleobject loo_Json
oleobject loo_JsonOut
li_Success = 0
// 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 long_report.pdf
loo_Pdf = create oleobject
li_rc = loo_Pdf.ConnectToNewObject("Chilkat.Pdf")
if li_rc < 0 then
destroy loo_Pdf
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_Pdf.LoadFile("qa_data/pdf/long_report.pdf")
if li_Success = 0 then
Write-Debug loo_Pdf.LastErrorText
destroy loo_Pdf
return
end if
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("type","text")
loo_Json.UpdateString("text","CONFIDENTIAL")
// An id of your own choosing, so that the watermark can be found and removed later. One is
// generated when you do not give one.
loo_Json.UpdateString("id","confidential")
loo_Json.UpdateString("color","#C00000")
loo_Json.UpdateNumber("opacity","0.25")
loo_Json.UpdateString("rotation","diagonal")
loo_Json.UpdateString("scale.fit","page")
loo_Json.UpdateNumber("scale.fitPercent","80")
loo_JsonOut = create oleobject
li_rc = loo_JsonOut.ConnectToNewObject("Chilkat.JsonObject")
li_Success = loo_Pdf.Watermark("add",loo_Json,loo_JsonOut)
if li_Success = 0 then
Write-Debug loo_Pdf.LastErrorText
destroy loo_Pdf
destroy loo_Json
destroy loo_JsonOut
return
end if
// The id, and the pages it was stamped on. "pages" defaults to all.
Write-Debug "id: " + loo_JsonOut.StringOf("id")
Write-Debug "pages: " + loo_JsonOut.StringOf("pages")
li_Success = loo_Pdf.WriteFile("qa_output/report_confidential.pdf")
if li_Success = 0 then
Write-Debug loo_Pdf.LastErrorText
destroy loo_Pdf
destroy loo_Json
destroy loo_JsonOut
return
end if
// Sample output:
// id: confidential
// pages: 1-3
destroy loo_Pdf
destroy loo_Json
destroy loo_JsonOut