Zig Requires Chilkat v11.7.0+
Zig
Why a PDF Optimization Was Skipped
See more PDF Optimization Examples
Demonstrates the "skipped" array, which lists the options that were asked for but not applied, each with a reason and, where it is page-specific, the pages. An option is skipped when it is reserved for a later release (mergeFontSubsets, compactType1Fonts), when the rules of the file forbid it (objectStreams in a PDF/A-1 file), or when the content could not be parsed safely (tidyContent and coalesceContent on a page whose content stream the parser does not understand). Nothing is ever changed on a guess: an option that cannot be applied safely is skipped and reported.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 grand_canyon_hiking_guide.pdf
const pdf = try chilkat.Pdf.init();
defer pdf.deinit();
pdf.loadFile("qa_data/pdf/grand_canyon_hiking_guide.pdf") catch {
std.debug.print("{s}\n", .{try pdf.getLastErrorText(alloc)});
return;
};
// Ask for the two options that are reserved for a later release.
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateBool("mergeFontSubsets", true) catch {};
json.updateBool("compactType1Fonts", true) catch {};
const json_out = try chilkat.JsonObject.init();
defer json_out.deinit();
pdf.optimize("audit", json, json_out) catch {
std.debug.print("{s}\n", .{try pdf.getLastErrorText(alloc)});
return;
};
var i: i32 = 0;
const num_skipped = json_out.sizeOfArray("skipped");
std.debug.print("skipped: {d}\n", .{num_skipped});
while (i < num_skipped) {
json_out.setI(i);
std.debug.print(" {s} - {s}\n", .{ try json_out.stringOf(alloc, "skipped[i].option"), try json_out.stringOf(alloc, "skipped[i].reason") });
i = i + 1;
}
// A skipped option is not a failure: Optimize returns true, the other options are applied, and the
// report says exactly what was left undone.
}