2 creditsCompare PDFs API — see exactly what changed
A page-by-page visual diff with a change ratio, a marked-up PDF showing where it changed, and the added and removed lines.
Compare PDFs aligns the two documents by page position and reports, for each page, a change ratio and whether it changed at all, plus the lines added and removed. It returns a marked-up copy of the new document with the changed regions highlighted, so you can see *where* a page changed rather than only that it did. Pages are compared as rendered images, which catches changes that a text diff misses entirely — a moved logo, a different signature block, an altered table rule. A small per-pixel tolerance means re-rendering identical content doesn't register as a change. Documents of different lengths are compared over their common pages, with the extra pages reported as added or removed; pages are matched by position, so an inserted page shifts the pages after it rather than being detected as an insertion.
How does the Compare PDFs API work?
One HTTP request from any language. Every ASHDOCS endpoint uses the same X-API-Key header.
curl -X POST https://www.ashdocs.com/api/v2/tools/pdf-compare \
-H "X-API-Key: ash_live_..." \
-F "old=@v1.pdf" \
-F "new=@v2.pdf" \
-F 'options={"include_text":true}'import requests
r = requests.post(
"https://www.ashdocs.com/api/v2/tools/pdf-compare",
headers={"X-API-Key": "ash_live_..."},
files=[("old", open("v1.pdf", "rb")), ("new", open("v2.pdf", "rb"))],
data={"options": '{"include_text":true}'},
)
job = r.json()
print(job["status"], job.get("url"))import { readFile } from "node:fs/promises";
const form = new FormData();
form.append("old", new Blob([await readFile("v1.pdf")]), "v1.pdf");
form.append("new", new Blob([await readFile("v2.pdf")]), "v2.pdf");
form.append("options", JSON.stringify({"include_text":true}));
const res = await fetch("https://www.ashdocs.com/api/v2/tools/pdf-compare", {
method: "POST",
headers: { "X-API-Key": "ash_live_..." },
body: form,
});
const job = await res.json();
console.log(job.status, job.url);using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-Key", "ash_live_...");
using var form = new MultipartFormDataContent();
form.Add(new ByteArrayContent(await File.ReadAllBytesAsync("v1.pdf")), "old", "v1.pdf");
form.Add(new ByteArrayContent(await File.ReadAllBytesAsync("v2.pdf")), "new", "v2.pdf");
form.Add(new StringContent("{\"include_text\":true}"), "options");
var res = await client.PostAsync("https://www.ashdocs.com/api/v2/tools/pdf-compare", form);
var job = await res.Content.ReadAsStringAsync();
Console.WriteLine(job);import java.io.ByteArrayOutputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
public class Sample {
static final String BOUNDARY = "AshdocsBoundary7MA4YWxkTrZu0gW";
public static void main(String[] args) throws Exception {
ByteArrayOutputStream body = new ByteArrayOutputStream();
addFile(body, "old", "v1.pdf");
addFile(body, "new", "v2.pdf");
addField(body, "options", "{\"include_text\":true}");
body.write(("--" + BOUNDARY + "--\r\n").getBytes(StandardCharsets.UTF_8));
HttpRequest req = HttpRequest.newBuilder(URI.create("https://www.ashdocs.com/api/v2/tools/pdf-compare"))
.header("X-API-Key", "ash_live_...")
.header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY)
.POST(HttpRequest.BodyPublishers.ofByteArray(body.toByteArray()))
.build();
HttpResponse<String> res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(res.body());
}
static void addFile(ByteArrayOutputStream body, String name, String path) throws Exception {
body.write(("--" + BOUNDARY + "\r\nContent-Disposition: form-data; name=\"" + name + "\"; filename=\""
+ Path.of(path).getFileName() + "\"\r\nContent-Type: application/octet-stream\r\n\r\n").getBytes(StandardCharsets.UTF_8));
body.write(Files.readAllBytes(Path.of(path)));
body.write("\r\n".getBytes(StandardCharsets.UTF_8));
}
static void addField(ByteArrayOutputStream body, String name, String value) throws Exception {
body.write(("--" + BOUNDARY + "\r\nContent-Disposition: form-data; name=\"" + name + "\"\r\n\r\n"
+ value + "\r\n").getBytes(StandardCharsets.UTF_8));
}
}#include <stdio.h>
#include <curl/curl.h>
int main(void) {
CURL *curl = curl_easy_init();
if (!curl) return 1;
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "X-API-Key: ash_live_...");
curl_mime *mime = curl_mime_init(curl);
curl_mimepart *part;
part = curl_mime_addpart(mime);
curl_mime_name(part, "old");
curl_mime_filedata(part, "v1.pdf");
part = curl_mime_addpart(mime);
curl_mime_name(part, "new");
curl_mime_filedata(part, "v2.pdf");
part = curl_mime_addpart(mime);
curl_mime_name(part, "options");
curl_mime_data(part, "{\"include_text\":true}", CURL_ZERO_TERMINATED);
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
curl_easy_setopt(curl, CURLOPT_URL, "https://www.ashdocs.com/api/v2/tools/pdf-compare");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
CURLcode rc = curl_easy_perform(curl);
printf("\n");
curl_mime_free(mime);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return rc == CURLE_OK ? 0 : 1;
}Common use cases
- →Checking what a counterparty altered in a returned contract
- →Verifying a regenerated document matches the previous run
- →Reviewing revisions between two versions of a report
Frequently asked questions
What does Compare PDFs return?+
For each page, a change ratio and whether it changed, the lines added and removed, and a marked-up copy of the new document with the changed areas highlighted.
Will it catch changes that aren't text?+
Yes. Pages are compared as rendered images, so a moved logo or a different signature block shows up; a small per-pixel tolerance ignores identical content rendered again.
What if the documents have different page counts?+
They're compared over their common pages, and extra pages are reported as added or removed. Pages are matched by position, so an inserted page shifts the pages after it. Each comparison costs 2 credits with a live key.