Zig Requires Chilkat v11.7.0+
Zig
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 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 two_page_memo.pdf
// The PDF used in this example is available at letterhead.pdf
const pdf = try chilkat.Pdf.init();
defer pdf.deinit();
pdf.loadFile("qa_data/pdf/two_page_memo.pdf") catch {
std.debug.print("{s}\n", .{try pdf.getLastErrorText(alloc)});
return;
};
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("type", "pdfPage") catch {};
json.updateString("pdf.path", "qa_data/pdf/letterhead.pdf") catch {};
// 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.
json.updateInt("pdf.page", 1) catch {};
// Behind the memo's own text, on page one, scaled to the page.
json.updateString("zOrder", "back") catch {};
json.updateString("pages", "first") catch {};
json.updateString("scale.fit", "page") catch {};
json.updateString("id", "letterhead") 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/memo_letterhead.pdf") catch {
std.debug.print("{s}\n", .{try pdf.getLastErrorText(alloc)});
return;
};
// Sample output:
// id: letterhead pages: 1
}