PDF Output
output_format="pdf" returns the extracted document as a PDF file. The PDF is laid out from the document’s Markdown rendering after every post-processor has run, so it holds the same content Markdown output would, including any redaction.
Quick Start
Section titled “Quick Start”import base64
from xberg import ExtractInput, ExtractionConfig, extract
config = ExtractionConfig(output_format="pdf")output = await extract(ExtractInput(kind="uri", uri="report.docx"), config=config)result = output.results[0]if result.metadata.output_format == "pdf": with open("report.pdf", "wb") as f: f.write(base64.b64decode(result.content))use base64::Engine as _;use xberg::{extract, ExtractInput, ExtractionConfig, OutputFormat};
let config = ExtractionConfig { // "pdf" is reached through the renderer registry via `OutputFormat::Custom`. output_format: OutputFormat::Custom("pdf".to_string()), ..Default::default()};let output = extract(ExtractInput::from_uri("report.docx"), &config).await?;let result = &output.results[0];if result.metadata.output_format.as_deref() == Some("pdf") { let document = base64::engine::general_purpose::STANDARD.decode(&result.content)?; std::fs::write("report.pdf", document)?;}xberg extract report.docx --content-format pdf > report.pdfcontent holds the PDF base64-encoded, because content is a string in every binding. metadata.output_format reads "pdf" when it does. The CLI decodes it and writes the file itself to stdout, and refuses to write it to a terminal.
Check metadata.output_format before decoding. When a post-processor rewrites the document text without updating its rendering, the pipeline discards that rendering and returns the post-processed plain text instead, with an output_format processing warning, exactly as it does for Markdown or HTML. metadata.output_format then reads "plain", and the CLI exits with an error rather than writing text into a .pdf file.
What Carries Over
Section titled “What Carries Over”The PDF is laid out from the Markdown rendering, so it holds what Markdown can express:
- headings, at six sizes, each listed in the PDF’s outline (bookmarks),
- paragraphs, with bold, italic, strikethrough, underline, highlight, superscript, subscript and inline code,
- links to
http,https,mailtoandftptargets, which can be clicked (a link to a fragment or a relative path keeps its text and drops the link), - bulleted and numbered lists, nested, with their start numbers,
- tables, with a grid and a shaded header row that is repeated at the top of each page the table continues onto,
- code blocks, with tabs expanded and long lines wrapped,
- block quotes, definition lists and horizontal rules,
- footnotes, as superscript markers with the note text in a paragraph.
Pages are US Letter with one-inch margins. Images are not embedded; an image’s alt text is kept as text. Layout from the source document (page size, columns, fonts, positions) is not reproduced, and no document properties such as title or author are written.
Text and Fonts
Section titled “Text and Fonts”Text is written as text, never as an image, so it can be selected, searched and copied, and extracting the PDF again returns it.
Text is set in DejaVu Sans, which is embedded, reduced to the characters the document uses. It covers Latin, Greek and Cyrillic. Bold and italic are drawn from its regular face. Code is set in Courier, a standard font every PDF reader provides, which is not embedded.
A character DejaVu Sans has no glyph for, such as Chinese, Japanese, Korean or Devanagari text or emoji, is drawn as an empty box. It still copies and extracts as the original character. Right-to-left scripts such as Arabic and Hebrew are drawn left to right, and Arabic letters are not joined.
Redaction
Section titled “Redaction”With redaction configured, the redaction post-processor rewrites the Markdown rendering like any other text output, and the PDF is laid out only afterwards, so a redacted term appears nowhere in it: not in the page text, the outline or a link target. Each archive member or email attachment runs its own extraction with the same configuration, and its content is its own base64-encoded PDF.
This lays out a new document. It does not redact an input PDF in place, and nothing of the input’s own layout survives.
Chunking
Section titled “Chunking”Chunking runs before the PDF is laid out. chunks and their byte offsets therefore describe the Markdown the PDF was built from, not the base64 text in content.