Pagecraft

crop

Crop PDF

Trim the margins of a PDF, or set an exact visible area.

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

Example

Trim ten millimetres of white margin off every edge.

Given

  • wide-margins.pdf — an ordinary PDF of 2 pages

From code

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

const wideMargins = await loadDocument({ bytes, name: 'wide-margins.pdf' });

const [output] = await runOperation('crop', [wideMargins], {
  mode: 'margins',
  unit: 'mm',
  top: 10,
  right: 10,
  bottom: 10,
  left: 10,
});
          

From a shell

            pagecraft crop wide-margins.pdf --mode margins --unit mm --top 10 --right 10 --bottom 10 --left 10
          

What comes back

One PDF of 2 pages.

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

Options

mode--mode

string, one of

Crop by

Default: 'margins'

  • margins — Take a margin off each side.
  • box — Give the visible rectangle directly.

unit--unit

string, one of

Measured in

Default: 'mm'

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

top--top

number

Top

Only when mode is 'margins'.

Default: 0

right--right

number

Right

Only when mode is 'margins'.

Default: 0

bottom--bottom

number

Bottom

Only when mode is 'margins'.

Default: 0

left--left

number

Left

Only when mode is 'margins'.

Default: 0

x--x

number

Left edge

Measured in from the left of the page as a reader sees it.

Only when mode is 'box'.

Default: 0

y--y

number

Bottom edge

Measured up from the foot of the page as a reader sees it.

Only when mode is 'box'.

Default: 0

width--width

number

Width

Only when mode is 'box'.

Default: 100

height--height

number

Height

Only when mode is 'box'.

Default: 100

uniform--uniform

boolean

Use one box for every page

Take the box from the first page in the Selection and apply it to all of them.

Default: false

pages--pages

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

Pages

Which pages to crop. The rest keep their full area.

Default: 'all'

What it cannot do

  • Cropping hides content rather than deleting it. To remove it for good, redact it.