Skip to main content

PDF Library (Pdf)

Pdf is in the Python package, the CLI, and Rust with the pdf feature. It isn't in the JavaScript package, so the examples below don't run on this site. A PDF parsed or imported into a document (with the pdf format, see Import & Export) becomes a Data<Pdf> value, which both functions on this page work on. Importing a file from disk needs the host to allow it with allow_system(); parsing PDF bytes the host hands over doesn't.

Pdf::extract_text(pdf: Data<Pdf>) -> str​

Every page's text, concatenated into one string.

import "./document.pdf" as self.pdf;

const text = self.pdf.extract_text();
pln(text);

Pdf::extract_images(pdf: Data<Pdf>) -> list​

Every image on every page, as a list of maps carrying the image data alongside its dimensions.

import "./document.pdf" as self.pdf;

const images = self.pdf.extract_images();
pln(images.len());
pln(images[0].get('width'), ' ', images[0].get('height'));