Pagecraft

extract-images

Extract images from PDF

Pull every picture out of a PDF at the resolution it was stored at.

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

Example

Get the photographs back out of a report at the size they were embedded.

Given

  • illustrated.pdf — a PDF with a photograph in it

From code

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

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

const [output] = await runOperation('extract-images', [illustrated], {
  pages: 'all',
});
          

From a shell

            pagecraft extract-images illustrated.pdf --pages all
          

What comes back

One image.

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

Options

pages--pages

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

Pages

Which pages to take the pictures from.

Default: 'all'

What it cannot do

  • This gives back the pictures the file stores, not a picture of the page. To turn a whole page into an image, use PDF to image.
  • A JPEG comes out exactly as it was stored. Everything else is re-wrapped as PNG, which loses nothing but is usually larger.
  • Scans stored as CCITT fax or JBIG2 are left alone: they cannot be turned into a common image file without re-encoding them.
  • A JPEG 2000 picture comes out as a .jp2, which is what the file stored. Pagecraft can hand it to you but cannot read it back in.