PowerBuilder Requires Chilkat v11.7.0+
PowerBuilder
Put a Letterhead Behind the First Page of a PDF
See more PDF Watermark Examples
Demonstrates the pdfPage type, which places a page of another PDF as the watermark. It is the way to use a letterhead, a cover overlay or a vector logo that was saved as a PDF, and unlike an image it stays sharp at any size because it is drawn, not resampled. "zOrder" set to back puts it behind the existing content, where a letterhead belongs, and "pages" set to first restricts it to page one.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 two_page_memo.pdf
// The PDF used in this example is available at letterhead.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/two_page_memo.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","pdfPage")
loo_Json.UpdateString("pdf.path","qa_data/pdf/letterhead.pdf")
// The page of the source PDF to use (1 by default). "match" instead of a number places source
// page n on target page n, which suits a set of per-page backgrounds.
loo_Json.UpdateInt("pdf.page",1)
// Behind the memo's own text, on page one, scaled to the page.
loo_Json.UpdateString("zOrder","back")
loo_Json.UpdateString("pages","first")
loo_Json.UpdateString("scale.fit","page")
loo_Json.UpdateString("id","letterhead")
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
Write-Debug "id: " + loo_JsonOut.StringOf("id") + " pages: " + loo_JsonOut.StringOf("pages")
li_Success = loo_Pdf.WriteFile("qa_output/memo_letterhead.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: letterhead pages: 1
destroy loo_Pdf
destroy loo_Json
destroy loo_JsonOut