File

PDF Manipulation

Trelae provides focused PDF utilities plus type-aware manipulation:

  • PDF → Images — render selected pages as JPEG/PNG images
  • PDF → Markdown — extract structured Markdown with images
  • Compress — optimize size for images and PDFs
  • Type rules — image operations apply only to images; for PDFs, only compress() is allowed in a .save() chain

PDF → Images

Turn one or more PDF pages into image files you can preview, download, or further manipulate with image operations.

Method: file.pdfToImages(options){ pagesExtracted, files }

Options

  • pageSelection: 'all' | number[] | { start: number; end: number }[]
    Select all pages, an explicit list (e.g. [1,3,6]), or inclusive ranges (e.g. [{ start: 1, end: 3 }]).
  • format?: 'jpeg' | 'png' (default: 'jpeg')
  • imageLocation?: string — destination path within the namespace (default: root "")

Returns

  • pagesExtracted: number – total pages converted
  • files: File[] – Trelae File instances (one per output image)

Throws if the source is not a PDF or the API call fails.


PDF → Markdown

Run full-document OCR on a PDF. You can either save the Markdown + images to Trelae or receive inline results without persisting.

Method: file.pdfToMarkdown(opts?)PdfToMarkdownResultFile

Options

  • saveMarkdown?: boolean — default true
  • location?: string — when saving, the folder to write outputs to

Returns (discriminated by saveMarkdown)

  • When true (default):
    • markdown: string
    • file: File — the stored Markdown file
    • images: File[] — stored image files extracted from the PDF
  • When false:
    • markdown: string
    • images: { id: string; imageBase64: string }[] — inline base64 assets (not saved)

Throws if the source is not a PDF or OCR fails.


Compress

Reduce file size. Behavior depends on the file type:

  • Images — lossy/loss-less compression; quality (0–100) optional
  • PDFs — stream optimization & font subsetting; quality is ignored

Method: file.compress({ quality? })this (chainable, call .save())


Chaining & Type Rules

Call .save() to apply queued operations. The queue is validated against the file type:

  • Images — may chain any image operation (resize, crop, rotate, flip, convert, border, background, grayscale, blur, sharpen, tint, adjust, threshold, trim, composite, addText, removeBackground) and optionally compress, then .save().
  • PDFsonly compress is permitted in the chain; any other operation throws. Use pdfToImages() or pdfToMarkdown() for PDF transformations.

Image example

PDF example