Zig Requires Chilkat v11.7.0+
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// 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
const pdf = try chilkat.Pdf.init();
defer pdf.deinit();
pdf.loadFile("qa_data/pdf/long_report.pdf") catch {
std.debug.print("{s}\n", .{try pdf.getLastErrorText(alloc)});
return;
};
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("type", "text") catch {};
json.updateString("text", "CONFIDENTIAL") catch {};
// 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.updateString("id", "confidential") catch {};
json.updateString("color", "#C00000") catch {};
json.updateNumber("opacity", "0.25") catch {};
json.updateString("rotation", "diagonal") catch {};
json.updateString("scale.fit", "page") catch {};
json.updateNumber("scale.fitPercent", "80") catch {};
const json_out = try chilkat.JsonObject.init();
defer json_out.deinit();
pdf.watermark("add", json, json_out) catch {
std.debug.print("{s}\n", .{try pdf.getLastErrorText(alloc)});
return;
};
// The id, and the pages it was stamped on. "pages" defaults to all.
std.debug.print("id: {s}\n", .{try json_out.stringOf(alloc, "id")});
std.debug.print("pages: {s}\n", .{try json_out.stringOf(alloc, "pages")});
pdf.writeFile("qa_output/report_confidential.pdf") catch {
std.debug.print("{s}\n", .{try pdf.getLastErrorText(alloc)});
return;
};
// Sample output:
// id: confidential
// pages: 1-3
}