Zig Requires Chilkat v11.7.0+
Zig
Tile a Watermark Across a PDF Page
See more PDF Watermark Examples
Demonstrates a tiled watermark, which repeats the stamp over the whole page instead of placing it once. Tiling overrides position.align; tile.spacingX and spacingY set the gaps, and tile.stagger offsets alternate rows by half a tile so the pattern does not line up in columns. A faint tiled stamp carrying the name or address is the usual way to mark a document so that a leaked copy can be traced back, and zOrder back keeps it behind the text where it does not hinder reading.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 {};
// {date:FORMAT} is replaced per page when the watermark is added. The other placeholders are
// {page}, {pages} and {filename}; {{ gives a literal brace.
json.updateString("text", "jdoe@example.com {date:yyyy-MM-dd}") catch {};
json.updateString("id", "trace") catch {};
json.updateString("zOrder", "back") catch {};
json.updateNumber("font.size", "14") catch {};
json.updateNumber("opacity", "0.15") catch {};
json.updateNumber("rotation", "30") catch {};
json.updateBool("tile.enabled", true) catch {};
json.updateNumber("tile.spacingX", "60") catch {};
json.updateNumber("tile.spacingY", "80") catch {};
json.updateBool("tile.stagger", true) 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;
};
std.debug.print("id: {s} pages: {s}\n", .{ try json_out.stringOf(alloc, "id"), try json_out.stringOf(alloc, "pages") });
pdf.writeFile("qa_output/report_traced.pdf") catch {
std.debug.print("{s}\n", .{try pdf.getLastErrorText(alloc)});
return;
};
// Sample output:
// id: trace pages: 1-3
}