Optimizing PDF files for fast web viewing

Viewer optimized PDF is a unique way of near-instantaneous loading and viewing of remotely stored PDFs regardless of their size or complexity. A Viewer optimized file is an optimized PDF document that allows the Viewer to display a document preview even before all client-side components are loaded. In the past, a Viewer could stream arbitrary large documents for viewing optimization using standard PDF linearization, but we have extended this concept to support fast viewing of complex pages which are slow to render as well.

Create a viewer optimized PDF

To optimize a PDF, use the SaveViewerOptimized function with default or custom settings on desktop or server.

JavaScript

1const main = async () => {
2 const inputFilename = 'newsletter';
3 const inputFilePath = '../files/' + inputFilename + '.pdf';
4 const outputFilePath = '../output/' + inputFilename + '_optimized.pdf';
5 const doc = await PDFNet.PDFDoc.createFromFilePath(inputFilePath);
6
7 const opts = new PDFNet.PDFDoc.ViewerOptimizedOptions();
8
9 // A number from 0 (include all thumbnails) to 100
10 // (include only the first thumbnail). The default value is 50.
11 opts.setThumbnailRenderingThreshold(0);
12
13 // The maximum allowed length for the thumbnail's height/width.
14 // The default thumbnail size is 1024.
15 opts.setThumbnailSize(512);
16
17 // Optimize pdf
18 await doc.saveViewerOptimized(outputFilePath, opts);
19};
20
21// add your own license key as the second parameter, e.g. PDFNet.runWithCleanup(main, 'YOUR_LICENSE_KEY')
22PDFNet.runWithCleanup(main).then(function() {
23 PDFNet.shutdown();
24});

Compress & optimize PDF files
Full sample code shows how to use SaveViewerOptimized to embed thumbnails with a PDF file which will enable fast rendering in the viewer.

Create a viewer optimized PDF using DocPub

DocPub is a command-line utility which provides an alternative way of generating viewer optimized PDF files.

To create a viewer optimized PDF, use the command docpub -f pdf --viewer_optimized file.pdf.

sh

1./docpub -f pdf --viewer_optimized demo.pdf --fname demo.optimized.pdf

Open a viewer optimized PDF

The opening of the optimized PDF is no different than opening regular PDF files. By default, the Viewer is able to recognize a PDF that is Viewer optimized and will utilize this enhancement.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales