Tcl Requires Chilkat v11.7.0+
Tcl
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 Tcl Downloads
load ./chilkat.dll
set 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
set pdf [new_CkPdf]
set success [CkPdf_LoadFile $pdf "qa_data/pdf/two_page_memo.pdf"]
if {$success == 0} then {
puts [CkPdf_lastErrorText $pdf]
delete_CkPdf $pdf
exit
}
set json [new_CkJsonObject]
CkJsonObject_UpdateString $json "type" "pdfPage"
CkJsonObject_UpdateString $json "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.
CkJsonObject_UpdateInt $json "pdf.page" 1
# Behind the memo's own text, on page one, scaled to the page.
CkJsonObject_UpdateString $json "zOrder" "back"
CkJsonObject_UpdateString $json "pages" "first"
CkJsonObject_UpdateString $json "scale.fit" "page"
CkJsonObject_UpdateString $json "id" "letterhead"
set jsonOut [new_CkJsonObject]
set success [CkPdf_Watermark $pdf "add" $json $jsonOut]
if {$success == 0} then {
puts [CkPdf_lastErrorText $pdf]
delete_CkPdf $pdf
delete_CkJsonObject $json
delete_CkJsonObject $jsonOut
exit
}
puts "id: [CkJsonObject_stringOf $jsonOut id] pages: [CkJsonObject_stringOf $jsonOut pages]"
set success [CkPdf_WriteFile $pdf "qa_output/memo_letterhead.pdf"]
if {$success == 0} then {
puts [CkPdf_lastErrorText $pdf]
delete_CkPdf $pdf
delete_CkJsonObject $json
delete_CkJsonObject $jsonOut
exit
}
# Sample output:
# id: letterhead pages: 1
delete_CkPdf $pdf
delete_CkJsonObject $json
delete_CkJsonObject $jsonOut