Skip to Content
NexPDF

Compare and optimise

Let users compare a PDF with another version, make files smaller and save them for Fast Web View in an Electron window with NexPDF, and keep the engine's memory in check.

English

License module

Comparing documents and the Fast Web View download work without a key. Optimize needs the editor module (Startup tier and above).

The user runs these in the window. To compare or optimise in code, for example in a batch, use the document API in the main process, with the calls of the Node.js SDK.

Compare two versions

Compare documents in the Convert mode (ai) asks for another PDF and shows an overlay of the first page of both documents: red marks the current document, blue the compared one.

await openPdfWindow({
  file,
  license,
  config: { modeConfig: { availableModes: ['viewer', 'ai'] } },
});

The window compares the first page only. For a page-by-page report of which pages changed and by how much, use doc.raw.compareJson(other.raw, dpi) in the document API (see the Node.js SDK).

To see which words changed (inserted, deleted, replaced and moved text, and an annotated PDF of the changes), use Word-level comparison.

Make files smaller

Optimize in the Pages mode (pages) compresses uncompressed streams and removes objects nothing refers to, then reports how many streams it compressed and how many bytes it saved. Save the document afterwards with Download, File, Save As… or pdf.save(path).

The window does not subset fonts. doc.raw.subsetFonts() in the document API does (see the Node.js SDK).

Fast Web View

The More menu's Download for the web (Fast Web View) saves a linearized PDF, which shows its first page before the whole file has downloaded. A signed document is saved as signed, unchanged.

Memory

Each window runs its own engine process, which holds the document and the renderer's caches of fonts, glyphs and decoded images (bounded by size, up to about 1.3 GB in total). Closing the window ends the engine and frees all of it. For an engine you started with startEngine, call engine.close(). See Platform notes.

Documents of the document API live in the main process. doc.trimMemory() (1.1) compacts the buffers of a long-lived, often edited document and returns the approximate number of bytes reclaimed; doc.memoryUsage() estimates what a document uses; doc.close() frees it all.

On this page