Pagecraft

image-to-pdf

Image to PDF

Turn photos and scans into a PDF, one page each.

Reads
the images to combine — image/png, image/jpeg, image/webp, 1 or more
Writes
one file — PDFs
Tool page
/image-to-pdf

Example

Collect the photographs of a receipt into one PDF to file.

Given

  • receipt-front.png — a PNG
  • receipt-back.png — a PNG

From code

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

const receiptFront = await loadDocument({ bytes, name: 'receipt-front.png' });
const receiptBack = await loadDocument({ bytes, name: 'receipt-back.png' });

const [output] = await runOperation('image-to-pdf', [receiptFront, receiptBack], {
  filename: 'receipt.pdf',
});
          

From a shell

            pagecraft image-to-pdf receipt-front.png receipt-back.png --filename receipt.pdf
          

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

filename--filename

string

Filename

What the PDF will be called.

Default: 'images.pdf'

size--size

string, one of

Page size

Default: 'fit'

  • fit — Every page comes out exactly the size of its picture.
  • 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

orientation--orientation

string, one of

Orientation

Default: 'auto'

  • auto — To suit each image
  • portrait — Portrait
  • landscape — Landscape

margin--margin

number

Margin

Default: 0

unit--unit

string, one of

Measured in

Default: 'mm'

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

fit--fit

string, one of

Fit

How the picture sits on the sheet. Ignored when the page is fitted to it.

Default: 'contain'

  • contain — The whole picture, with blank where the shapes differ.
  • cover — No blank; the overflow falls outside the page.
  • stretch — Both edges match exactly, and the picture distorts.
  • none — The picture keeps its own size, one pixel to the point.

What it cannot do

  • PNG and JPEG go in exactly as they arrived, with nothing decoded and nothing lost.
  • WebP has no place in the PDF format at all, so it has to be decoded and re-stored as PNG — lossless, but usually larger, and only possible where the host can decode WebP.