Lua Requires Chilkat v11.7.0+
Lua
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 Lua Downloads
local chilkat = require("chilkat")
-- 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
local pdf = chilkat.Pdf.new()
local success = pdf:load_file("qa_data/pdf/long_report.pdf")
if not success then
print(pdf.last_error_text)
return
end
local json = chilkat.JsonObject.new()
json:update_string("type", "text")
json:update_string("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.
json:update_string("id", "confidential")
json:update_string("color", "#C00000")
json:update_number("opacity", "0.25")
json:update_string("rotation", "diagonal")
json:update_string("scale.fit", "page")
json:update_number("scale.fitPercent", "80")
local jsonOut = chilkat.JsonObject.new()
success = pdf:watermark("add", json, jsonOut)
if not success then
print(pdf.last_error_text)
return
end
-- The id, and the pages it was stamped on. "pages" defaults to all.
print("id: " .. jsonOut:string_of("id"))
print("pages: " .. jsonOut:string_of("pages"))
success = pdf:write_file("qa_output/report_confidential.pdf")
if not success then
print(pdf.last_error_text)
return
end
-- Sample output:
-- id: confidential
-- pages: 1-3