Pagecraft

resize

Resize PDF pages

Change the page size of a PDF, scaling the content to match.

Reads
a PDF — application/pdf
Writes
one file — PDFs
Tool page
/resize-pdf

Example

Put a mixed pile of pages onto one paper size before printing them.

Given

  • mixed.pdf — an ordinary PDF of 3 pages

From code

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

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

const [output] = await runOperation('resize', [mixed], {
  size: 'a4',
  fit: 'contain',
});
          

From a shell

            pagecraft resize mixed.pdf --size a4 --fit contain
          

What comes back

One PDF of 3 pages.

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

Options

size--size

string, one of

Page size

Default: 'a4'

  • a3 — A3
  • a4 — A4
  • a5 — A5
  • a6 — A6
  • b5 — B5
  • letter — Letter
  • legal — Legal
  • tabloid — Tabloid
  • executive — Executive
  • custom — Custom size

width--width

number

Width

Only when size is 'custom'.

Default: 210

height--height

number

Height

Only when size is 'custom'.

Default: 297

unit--unit

string, one of

Measured in

Only when size is 'custom'.

Default: 'mm'

  • mm — Millimetres
  • cm — Centimetres
  • in — Inches
  • pt — Points

orientation--orientation

string, one of

Orientation

Default: 'auto'

  • auto — Keep each page as it is
  • portrait — Portrait
  • landscape — Landscape

fit--fit

string, one of

Fit

Default: 'contain'

  • contain — The whole page, with margins where the shape differs.
  • cover — No margins; the overflow falls outside the page.
  • stretch — Both edges match exactly, and the content distorts.
  • none — Only the sheet changes; the content stays its own size.

pages--pages

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

Pages

Which pages to resize. The rest keep the size they have.

Default: 'all'