# Compare PDF revisions before replacing a form

When someone sends a revised form, find the changed text and form fields before replacing the file your automation uses. The PDF Compare API returns before/after excerpts, page references, changed field definitions and review steps as JSON, with a readable HTML report in the run’s Output.

[Run the prefilled PDF sample](https://apify.com/merciful_goldenlarch/pdf-text-form-comparison/examples/compare-fillable-pdf-revisions-using-irs-forms)

Sign in to Apify, click Start with the included IRS sample, then open the Dataset. You do not need to upload a file or configure a store for this example.

The hosted sample compares the 2025 and 2026 editions of IRS Form 1040-ES and returns one `CHANGES_FOUND` row:

| Check | Recorded result |
| --- | --- |
| Pages | 12 before, 16 after |
| Field and grouping names | 127 missing, 128 added |
| Word occurrences | 273 missing, 2,276 added |

Legacy field counts include AcroForm grouping nodes, so use the typed `fieldChanges` findings to distinguish fillable fields from containers. The counts are a summary, while `textChanges` contains before/after excerpts and page references, and `fieldChanges` lists the exact field or grouping names and changed definitions. A renamed field can count as one removal and one addition; the tool does not guess which new field replaces an old one. Word counts describe extracted occurrences rather than a visual redline.

## See what someone would do with the result

[Open a real W-9 change report](../examples/pdf-w9/report.html), produced by comparing the official [2018 W-9](https://www.irs.gov/pub/irs-prior/fw9--2018.pdf) with the [March 2024 W-9](https://www.irs.gov/pub/irs-pdf/fw9.pdf). Open the first page pair to see the new line 3b wording and its added explanatory passage.

For this controlled example, we declared an old Address field name as a required automation mapping. The revised file does not have that exact name, so the report puts the missing mapping first and asks you to verify a replacement and test the workflow before switching files. It does not claim that the address question disappeared or that the form is legally unsuitable.

This is the handoff: read the changed passage, review any instruction or mapping that depends on it, then test that affected case. The tool shows evidence and a conditional review step; it does not decide which tax rules apply to you. W-9 contains XFA, so this example explicitly requires checking the form in its intended application.

Text comparison follows extracted PDF reading order. Reordered text may appear as additions or removals, and side-by-side fragments are not a verified semantic replacement. Scans, ambiguous page matches and truncated output are flagged for manual review.

## Run the PDF comparison by API

Set `APIFY_TOKEN` in your environment using an [Apify API token](https://console.apify.com/settings/integrations), then paste this block into a terminal from any folder. It downloads the sample input before making one live request, with a $0.02 maximum total charge. Apify may charge your account.

```sh
curl --fail --silent --show-error https://toolshed-guides.vercel.app/examples/pdf/input.json -o toolshed-pdf-input.json &&
curl --fail-with-body --silent --show-error --max-time 110 \
  'https://api.apify.com/v2/actors/koHaO9g0bPo9j1HrG/run-sync-get-dataset-items?maxTotalChargeUsd=0.02&timeout=90&format=json' \
  -H "Authorization: Bearer $APIFY_TOKEN" -H 'Content-Type: application/json' \
  --data-binary @toolshed-pdf-input.json
```

[Download the request JSON](../examples/pdf/input.json) or [inspect the recorded result](../examples/pdf/expected.json) before running. If a live request times out, check [Apify Runs](https://console.apify.com/actors/runs) before retrying, because the run may already have started. [Current pricing](https://apify.com/merciful_goldenlarch/pdf-text-form-comparison/pricing).

Prefer Python? [Download the source ZIP](https://toolshed-guides.vercel.app/source.zip), unzip it, and run `python3 run_demo.py pdf --live` from its folder. Python 3.8+ is enough, with no packages to install. Leaving off `--live` prints a recorded preview without making a request.

## Check the unchanged-file control

In the Actor input, set PDF pair to **Same-file control: two copies of the 2025 edition** and run it. The expected result is `PRESERVED_ON_CHECKS`, with 12 pages in each copy and zero added or missing field names and word occurrences. This status means the implemented checks passed; it does not certify layout or form behavior.

The same control is available as [request JSON](../examples/pdf-control/input.json), [recorded result](../examples/pdf-control/expected.json), or `python3 run_demo.py pdf-control --live` in the source download.

## Compare your own PDFs

1. In Apify Storage, create a private key-value store and upload the original as `BEFORE.pdf` and the revision as `AFTER.pdf`, using `application/pdf` content type.
2. Open the [Actor input](https://apify.com/merciful_goldenlarch/pdf-text-form-comparison/input), choose **My two PDFs in a private Apify store**, and select that store in **Private PDF store**. Grant read access when prompted, then enter the two record keys.
3. Optionally supply `requiredFieldNames` with the exact names your integration uses. A missing name is a mapping review item, not a guessed rename.
4. Run the comparison and open **CHANGE_REPORT.html** in Output, or use `textChanges`, `fieldChanges`, `requiredFieldChecks` and `reviewWarnings` from JSON. Route `MISSING_REQUIRED_FIELDS` and `MANUAL_REVIEW_REQUIRED` to human review; only switch files after testing the affected workflow.

Both files must be valid, readable PDFs. The Actor checks extracted text and AcroForm field definitions, including names, types, flags, choices and known page locations. It does not perform OCR, visual comparison, validation of filled values or signature validation. `NO_SUPPORTED_CHANGES` means the supported checks found no change, while downstream compatibility remains `NOT_TESTED`. Limits are 12 MiB and 100 pages per PDF, with explicit finding and excerpt caps. For a recurring form update, keep the original file as your baseline and compare each revision before replacing it. The Actor does not watch your files automatically.

For coding agents, the stable Actor ID is `koHaO9g0bPo9j1HrG`. Read the [current OpenAPI schema](https://api.apify.com/v2/actors/koHaO9g0bPo9j1HrG/builds/default/openapi.json) and use the exact sample input above before sending authorized private files. A run success alone is not the comparison result.

## Agent payment budgets

For a prepaid agent token, current permissions and prices, and recovery after an interrupted request, use the [agent payment guide](https://toolshed-guides.vercel.app/agent-payments/). Its preflight command does not spend money. A funded AGI run remains a separate, untested validation step.

## Check form templates before replacing them

For an automated fillable-form workflow, supply requiredFieldNames to flag missing saved mappings, then review changed AcroForm names, types, flags, choices and page references in CHANGE_REPORT.html. This is a supported-definition comparison, not a promise that downstream filling, visual layout, signatures or XFA behavior remain compatible. ChatGPT or a local PDF library may be simpler for a one-off readable-text question.
