compare
Compare two PDFs
Show what changed between two versions of a document, word by word.
- Reads
- two PDFs — application/pdf, 2 or more
- Writes
- one file — text files or JSON
- Tool page
- /compare-pdf
Example
Say what changed between the version you sent and the one that came back.
Given
- before.pdf — an ordinary PDF of 2 pages
- after.pdf — an ordinary PDF of 3 pages
From code
import { loadDocument, runOperation } from '@pagecraft/core';
const before = await loadDocument({ bytes, name: 'before.pdf' });
const after = await loadDocument({ bytes, name: 'after.pdf' });
const [output] = await runOperation('compare', [before, after], {
format: 'text',
visual: false,
});
From a shell
pagecraft compare before.pdf after.pdf --no-visual --format text
What comes back
One text file.
This example is run by the test suite. If it stopped being true, the build would fail.
Options
visual--visual
boolean
Compare how the pages look
Also draw the pages whose words are identical, to catch a change no words record.
Default: true
format--format
string, one of
As
Default: 'text'
text— A report to readjson— Data for a tool to work with
What it cannot do
- The pages are compared in order: page one with page one. A page inserted at the front makes every page after it look changed, because to a reader it is.
- A word is compared as it reads, not as it is drawn. A change of font, colour or position that leaves the words alone is a visual difference, and is reported as one.
- Comparing how the pages look needs somewhere to draw them. Without it, turn that off and the words are still compared.
- A scanned page holds no words to compare. Two scans are compared by how they look and nothing else.