Zig Requires Chilkat v11.7.0+
Zig
Exclude Rotated Margin Text from PDF Extraction
See more PDF Text Extraction Examples
Demonstrates the "rotatedText" filter. Text that is not aligned with the page, such as a vertical "CONFIDENTIAL" label in the margin, is included by default (after the upright text) and flagged in the quality report; "exclude" leaves it out.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 rotated_margin.pdf
const pdf = try chilkat.Pdf.init();
defer pdf.deinit();
pdf.loadFile("qa_data/pdf/rotated_margin.pdf") catch {
std.debug.print("{s}\n", .{try pdf.getLastErrorText(alloc)});
return;
};
const json = try chilkat.JsonObject.init();
defer json.deinit();
const json_out = try chilkat.JsonObject.init();
defer json_out.deinit();
// The page has a paragraph and, rotated 90 degrees along the left margin, "CONFIDENTIAL - DRAFT - NOT FOR DISTRIBUTION".
pdf.extractText("text", json, json_out) catch {
std.debug.print("{s}\n", .{try pdf.getLastErrorText(alloc)});
return;
};
std.debug.print("---- default (rotated text included) ----\n", .{});
std.debug.print("{s}\n", .{try json_out.stringOf(alloc, "text")});
std.debug.print("issue: {s}\n", .{try json_out.stringOf(alloc, "quality.pages[0].issues[0].code")});
json.updateString("rotatedText", "exclude") catch {};
pdf.extractText("text", json, json_out) catch {
std.debug.print("{s}\n", .{try pdf.getLastErrorText(alloc)});
return;
};
std.debug.print("---- rotatedText: exclude ----\n", .{});
std.debug.print("{s}\n", .{try json_out.stringOf(alloc, "text")});
// Sample output:
// ---- default (rotated text included) ----
// Restoration Budget Summary
//
// Spending for the season came in slightly under the approved budget, largely because the parapet work took less time than expected. The lens loan carries no fee, but the society is responsible for insurance and for the specialist cleaning.
//
// CONFIDENTIAL - DRAFT - NOT FOR DISTRIBUTION
// issue: rotatedText
// ---- rotatedText: exclude ----
// Restoration Budget Summary
//
// Spending for the season came in slightly under the approved budget, largely because the parapet work took less time than expected. The lens loan carries no fee, but the society is responsible for insurance and for the specialist cleaning.
}