Pagecraft

pdf-to-image

PDF to image

Turn pages into PNG, JPEG or WebP images at a density you choose.

Reads
a PDF — application/pdf
Writes
any number of files — images
Tool page
/pdf-to-image

Example

Turn each page into a PNG to drop into a slide.

Given

  • poster.pdf — an ordinary PDF of 2 pages

From code

            import { loadDocument, runOperation } from '@pagecraft/core';

const poster = await loadDocument({ bytes, name: 'poster.pdf' });

const outputs = await runOperation('pdf-to-image', [poster], {
  format: 'png',
  dpi: 150,
});
          

From a shell

            pagecraft pdf-to-image poster.pdf --format png --dpi 150
          

What comes back

2 images.

This example is run by the test suite. If it stopped being true, the build would fail.

Options

format--format

string, one of

Format

Default: 'png'

  • png — Lossless, and the only one that keeps transparency well.
  • jpeg — Much smaller for photographs and scans.
  • webp — Smaller again, and read by every current browser.

dpi--dpi

integer (dpi)

Density

Pixels per inch. 150 reads well on screen; 300 is print quality.

Default: 150

quality--quality

integer (%)

Quality

How much detail to keep. Ignored by PNG, which discards nothing.

Default: 90

background--background

string, '#rrggbb'

Background

What shows through where the page draws nothing.

Default: '#ffffff'

transparent--transparent

boolean

Transparent background

PNG and WebP only. JPEG has no way to store transparency.

Default: false

pages--pages

string, a page selection: '1-3, 7, 9-', 'even', 'last'

Pages

Which pages to render, and in what order: '1-3, 7, 9-'.

Default: 'all'

What it cannot do

  • A page renders to pixels, so the text in the result can no longer be selected or searched.
  • JPEG cannot store transparency; a transparent background falls back to the background colour.
  • A very large page at a very high density comes to more pixels than any browser will draw on. Where that happens the run stops and says which density would have fitted, rather than handing back a blank image.