Skip to main content

PDF Library (Pdf)

Pdf needs the pdf feature flag, which isn't part of this docs site's browser build — every example below is reference only, not runnable here. A PDF imported into a document (via the pdf format, from Import & Export) becomes a Data<Pdf> value, which both functions on this page operate on.

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'));