PDF reports and extraction
Create paginated scientific reports, embed native charts, reuse metadata templates, and extract page text with source provenance.
ImplementedAner 0.0.10 or newerRequires Aner 0.0.10 or greater.
aner.pdf creates scientific PDF reports and extracts document text into
page records. It is an optional native module. Install its worker before
importing it. The worker package version is independent of the Aner runtime.
The chart bridge requires PDF module 0.1.1 or greater.
Check the runtime selected by your terminal, then install the worker:
aner --versionaner install pdf
aner install pdf=0.1.1The first command selects the newest compatible package from
the public PDF catalog; the second selects an exact
package version. Set ANER_MODULE_CATALOG to an HTTPS catalog URL for a private
deployment. ANER_MODULE_CA_FILE may point to a trusted CA PEM for a private
HTTPS server; peer and hostname verification remain enabled. Catalog and asset
URLs must respond directly with HTTP 200; this first version rejects redirects.
Importing a module never installs or downloads it automatically.
PDF packages are published independently of the Aner runtime. The catalog lists
the available platforms and compatibility floors; a missing compatible entry
fails without changing the active module. Use an installed runtime meeting the minimum version above. For offline installation, obtain the matching .anermodule package on a
connected computer using the public catalog. Compare its complete SHA256 with
the catalog entry before transferring the unchanged file. The catalog also
links the worker source and corresponding dependency sources and their hashes.
On Linux, use sha256sum pdf-0.1.1.anermodule; on Mac, use
shasum -a 256 pdf-0.1.1.anermodule; in PowerShell, use
Get-FileHash .\pdf-0.1.1.anermodule -Algorithm SHA256.
Then install the verified local package explicitly:
aner install pdf=0.1.1 --file pdf-0.1.1.anermoduleANER_MODULES_DIR selects an absolute module store directory. Otherwise the
store is ANER_HOME/modules when ANER_HOME is set, ~/.aner/modules on Unix,
or %LOCALAPPDATA%/Aner/modules on Windows. Use the same setting for installation
and execution. A managed aner forwards PDF installation to its selected
runtime; select a runtime that supports this feature first.
Uninstall or change the active version
Remove all installed PDF module versions:
aner uninstall pdfRemove one exact version:
aner uninstall pdf=0.1.1Removal uses the same module store as installation, needs no network, and
succeeds when the requested module or version is already absent. Removing the
active version clears its activation. Other installed versions remain on disk,
but none becomes active automatically. Select a retained version explicitly
with aner install pdf=VERSION, using --file for an offline package.
Uninstall removes the managed worker packages. It preserves generated PDFs,
template JSON and application assets outside those package directories.
Always include pdf: bare aner uninstall removes the managed Aner
installation and has its own confirmation flow. Close programs using the PDF
worker before removing a package. Install and uninstall share a module lock;
inspect an interrupted installation before retrying when a lock is reported.
Module location and private catalogs
Set ANER_MODULES_DIR to an absolute directory when a project needs a separate
module store. Use the same setting for installation, execution and uninstall:
export ANER_MODULES_DIR="$HOME/.aner-project/modules"
aner install pdf
aner run report.anerIn PowerShell, use $env:ANER_MODULES_DIR for the equivalent setting.
The default locations are described above. Module installation is per user;
it does not require an administrator account.
For a private distribution, set ANER_MODULE_CATALOG to its trusted HTTPS
catalog. ANER_MODULE_CA_FILE can select its trusted CA PEM. The client still
verifies the certificate and hostname. Catalogs and package assets must return
HTTP 200 directly, with no redirects. The package manifest must match the
selected module, version, ABI, platform and compatibility floor. Downloads are
verified by size and SHA256 before atomic activation. A failed installation
preserves the previously active package.
Create a report
import aner.pdf
let report = pdf.document(title: "Model evaluation", author: "Research team")
pdf.heading(report, "Evaluation summary")
pdf.text(report, "Scores use the held-out evaluation set.")
pdf.table(report, List("Model", "RMSE"),
List(List("Baseline", "1.24"), List("Candidate", "0.97")))
let receipt = pdf.create("evaluation.pdf", report)
print(pdf.to_json(receipt))The output path must be new. PDF creation lays out the report before publishing
the complete file. Text wraps to the available width, and tables repeat their
column headings when they continue on another page. Table values in this
example are formatted strings so the analyst controls numerical precision and
units. JSON integer values must fit the exact range
-9007199254740991..9007199254740991; format larger integers, Decimal values,
and identifiers as Strings. JSON floating values use binary64. Nonfinite
numbers, collection cycles, and non String Dictionary keys are rejected.
For an existing Aner DataTable, call
pdf.data_table(report, table, max_rows: 1000) instead of building cell Lists.
The adapter formats typed cells explicitly, retains unit labels and records
table provenance in document metadata. It rejects a table larger than the
selected row budget instead of silently dropping rows. Select or aggregate the
data before reporting when a full table would make an unreadable document.
max_rows must be 1..10000, and a report table supports at most 16 columns.
Use pdf.image(report, "chart.png", width: 400.0, height: 240.0) for a local
PNG chart or illustration. Image dimensions and page coordinates use PDF points
(72 points per inch). pdf.page_break(report) starts a new body page. The first
version supports local PNG images; export other chart formats to PNG first.
Export a DataTable
Save this synthetic teaching CSV as metrics.csv:
model,rmse,samples
Baseline,0.42,120
Candidate,0.31,120Declare the columns explicitly. Decimal values retain their reporting scale, and the report records the table source provenance:
import aner.pdf
import aner.data
var schema = data.schema()
schema = data.column(schema, "model", "String", false)
schema = data.column(schema, "rmse", "Decimal", false)
schema = data.column(schema, "samples", "Int64", false)
let table = data.collect(data.scan_csv("metrics.csv", schema, missing: "NA"),
max_rows: 1000, max_bytes: 1048576, batch_rows: 128)
let report = pdf.document(title: "Model metrics")
pdf.data_table(report, table, max_rows: 1000)
let receipt = pdf.create("metrics-report.pdf", report)Select, filter or aggregate a wider or larger table before reporting it. A PDF is a presentation artifact; retain the original typed table and source records for further numerical analysis.
Insert an Aner Plot chart
Import both modules and pass the chart directly to pdf.plot. No temporary
SVG or PNG file is needed:
import aner.pdf
import aner.plot
let chart = plot.line(List(1.0, 2.0, 3.0), List(0.42, 0.35, 0.31))
.title("Validation error")
.labels("Iteration", "RMSE")
.size(width: 640, height: 400)
let report = pdf.document(title: "Model evaluation")
pdf.heading(report, "Held out performance")
pdf.plot(report, chart, width: 400.0, height: 240.0)
let receipt = pdf.create("model-evaluation.pdf", report)Requires PDF module 0.1.1 or greater. pdf.plot snapshots the chart when it
is appended. Later chart transformations cannot change that snapshot. Native
vector marks and text remain vector content in the PDF. The result is a static
view: interactive controls, notebook selection, animation and HTML scripts do
not become interactive PDF content. Set the desired chart view, theme, title,
labels and caption before appending it. Each snapshot appends a plot_sources entry to document metadata. It records
svg_sha256, the chart summary, static rendering method, width and height in
points, and data_provenance. Table or image adapters retain their structured
source provenance; charts built from plain Lists record null source provenance.
pdf.read recovers these entries. The original dataset and SVG are not copied
into PDF metadata, so retain the source data and report descriptor separately.
Size arguments use PDF points, so 72 points equals one inch.
The chart snapshot has a 4 MiB SVG budget, at most 100000 elements and 64 nesting levels, and scalar dimensions or viewBox dimensions no greater than 16384 pixels per axis. Embedded PNG resources have a decoded budget of 64 MiB per chart. All chart, body and template images share a 128 MiB decoded budget for the whole document. External files, network resources, scripts and foreign HTML objects are rejected. Charts that include image previews retain those previews as raster content; native vector marks and text stay scalable.
The chart itself remains an ordinary immutable Chart. Continue using it in a
notebook or export it separately with chart.save("figure.svg") or
chart.save("figure.html"). See Aner Plot for the chart contracts.
The complete chart report combines chart
insertion, a reusable template, explicit tables and extracted page records.
Reuse a template
Provide your local logo.png and seal.png files in the working directory
before running this example. They are user supplied template assets.
import aner.pdf
let branding = pdf.template(
header: "Research laboratory",
footer: "Internal report - page {page} of {pages}")
pdf.header_image(branding, "logo.png", width: 80.0, height: 30.0)
pdf.footer_image(branding, "seal.png", width: 24.0, height: 24.0)
let report = pdf.document(title: "Experiment 42", author: "Research team")
pdf.with_template(report, branding)
pdf.heading(report, "Experiment 42")
pdf.text(report, "Method and results go here.")
let receipt = pdf.create("experiment-42.pdf", report)The template belongs to the document metadata and is embedded in the generated
PDF as custom metadata. Header and footer text and images repeat on every page.
{page} and {pages} are replaced with the current and total page count.
pdf.footer_image adds an image to the footer in the same way as
pdf.header_image.
pdf.with_template copies the template into the report so later changes to a
shared template do not change reports already prepared from it. Without a
template there is no generated header or footer, including automatic page
numbers.
Templates and reports use ordinary Dictionary and List values. Serialize a
template with pdf.to_json(branding) and restore it with
pdf.from_json(template_json). Store that JSON using the application's normal
configuration mechanism. Local image paths must still exist on the rendering
machine when a saved template is reused before rendering. Generated PDFs also
embed the template's PNG image bytes in metadata; a template recovered from
that metadata can be reused without its original image files.
pdf.metadata(report, values) merges a Dictionary of metadata into the report.
Supported standard fields are title, author, subject, and keywords.
For example:
let values = Dictionary()
values.set("subject", "Held-out model evaluation")
values.set("keywords", "experiment-42,rmse")
pdf.metadata(report, values)Extract data from a PDF
import aner.pdf
import aner.data
let extracted = pdf.read("source.pdf", max_pages: 100, max_bytes: 67108864)
print(pdf.extract_text(extracted))
let pages = pdf.pages(extracted)
print(pages.rows())pdf.read returns a Dictionary with document metadata, page records, source,
input source_sha256 and source_bytes, extraction method, and warnings.
pdf.pages converts its page records into an
Aner DataTable with source, page, text, width, and height columns.
Page numbers are one based; dimensions use points. pdf.extract_text joins the
extracted page text for downstream text analysis.
The page table preserves the source of every record. It does not infer experimental variables or numerical tables from visual alignment. Review warnings and retain the original PDF. Image only scans require a separate OCR workflow; extraction can return empty text for those pages. Complex columns, mathematics, unusual font encodings, and non Latin documents may require manual inspection. The module does not edit an existing PDF or execute its embedded JavaScript.
Requests and responses are bounded to 8 MiB, source PDFs and generated PDFs to 64 MiB, extracted text to 2 MiB, and reading/creation to at most 1000 pages. The default read page budget is 100; exceeding it fails rather than returning a silently truncated document. Individual template images are limited to 1 MiB, and template metadata including encoded images to 4 MiB. The native worker has a 120 second execution deadline. These are admission limits; the worker is a separate process running with the user's filesystem permissions.
API reference
All helpers require import aner.pdf. Document/template/result parameters are
ordinary Dictionaries; columns and rows are Lists. Schema and resource errors
are reported before a successful output is returned.
| Function | Result |
|---|---|
pdf.document(title: String = "", author: String = "") | New report Dictionary with metadata and body blocks. |
pdf.template(header: String = "", footer: String = "") | New template Dictionary. |
pdf.with_template(document, template) | Copy the template into the document metadata. |
pdf.header_image(template, path, width: Float64 = 80.0, height: Float64 = 30.0) | Add a header PNG. |
pdf.footer_image(template, path, width: Float64 = 80.0, height: Float64 = 30.0) | Add a footer PNG. |
pdf.metadata(document, metadata) | Merge document metadata fields. |
pdf.heading(document, text) | Append a heading. |
pdf.text(document, text) | Append a paragraph. |
pdf.table(document, columns, rows) | Append a table. |
pdf.data_table(document, table: DataTable, max_rows: Int64 = 1000) | Append formatted DataTable cells, units, and provenance; fail if the row budget is exceeded. |
pdf.plot(document, chart: Chart, width: Float64 = 400.0, height: Float64 = 240.0) | Append an immutable static chart snapshot. Requires PDF module 0.1.1 or greater. |
pdf.image(document, path, width: Float64 = 400.0, height: Float64 = 240.0) | Append a body PNG. |
pdf.page_break(document) | Append a page break. |
pdf.create(path, document) | Write a new PDF and return a receipt Dictionary. |
pdf.read(path, max_pages: Int64 = 100, max_bytes: Int64 = 67108864) | Extract metadata and page records into a Dictionary. |
pdf.pages(result) | Convert page records to a DataTable. |
pdf.extract_text(result) | Return page text as a String. |
pdf.to_json(value) | Serialize a Dictionary to a JSON String. |
pdf.from_json(text) | Parse a JSON object into a Dictionary. |
Creation and reading run a separately installed native worker. Chart insertion uses the worker’s native SVG renderer. Font availability can change glyph coverage and page layout across machines. Pin the module version and retain package checksums, source data, template JSON, assets, and font environment for reproducible reports. Keep the original PDF, exact package version and source data with every extraction result.
Troubleshooting
| Symptom | Action |
|---|---|
aner install pdf is rejected | Check aner --version and select a runtime meeting the minimum requirement. |
Import reports E1001 | Install a compatible worker and use the same module store for installation and execution. |
| No compatible package is available | Inspect the public catalog for your operating system, processor and version floors. |
| Plot insertion requires a newer worker | Install PDF module 0.1.1 or greater. Runtime and worker versions are separate. |
Creation reports R4601 | Read the source located message. Use a new output path, valid local assets, and admitted resource budgets. |
| Header or footer is absent | Attach a template explicitly with pdf.with_template. Reports without a template have no generated bands. |
| A scanned page has no extracted text | The module does not perform OCR. Retain the original PDF and use a separately reviewed OCR workflow. |
| Uninstall reports unexpected files or links | Inspect the selected package directory. Uninstall preserves unknown entries instead of deleting unrelated content. |
| An installation lock remains | Confirm no install or uninstall is running and inspect the interrupted operation before retrying. |
Complete examples
Create and read a PDF report requires no input
files and writes experiment-report.pdf. It prints the creation receipt, page
count and extracted report text. Download the linked source as pdf_report.aner
into a fresh writable directory, then run from that directory:
aner install pdf
aner run pdf_report.anerEmbed native plots in a PDF report uses synthetic values included in its source. It requires the chart capable worker version stated above. Every source download is ordinary Aner code that can be inspected before execution.
See the complete callable index for the native module and method name catalogue.