Some test text!

menu
Viewer optimized PDFkeyboard_arrow_down

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 WebViewer to display a document preview even before all client-side components (such as WebAssembly) are downloaded and compiled. In the past WebViewer could stream arbitrary large documents using the standard PDF linearization, but in the 6.0.0 version of WebViewer, we extended this concept to support fast viewing of pages that are slow to render.

linkHow to create viewer optimized PDF file using DocPub

The command to create optimized PDF is ./docpub -f pdf --viewer_optimized file.pdf, see example below.

$ ./docpub -f pdf --viewer_optimized demo.pdf --fname demo.optimized.pdf
Processing...
/User/username/Documents/demo.pdf

linkCreate viewer optimized PDF using PDFTron SDK

Use PDFTron SDK API doc.SaveViewerOptimized() for converting regular PDF to viewer optimized PDF.

// Open document from the filesystem
PDFDoc doc = new PDFDoc("myFile.pdf");

// Options for SaveViewerOptimized
ViewerOptimizedOptions options = new ViewerOptimizedOptions();

// The maximum allowed length for the thumbnail's height/width.
// The default thumbnail size is 1024.
options.SetThumbnailSize(1024);

// A number from 0 (include all thumbnails) to 100
// (include only the first thumbnail). The default value is 50.
options.SetThumbnailRenderingThreshold(40);


// optimize pdf
doc.SaveViewerOptimized("path/to/output", options);
// open document from the filesystem
PDFDoc doc(filename);

// Options for SaveViewerOptimized
ViewerOptimizedOptions viewer_optimized_opts;

// The maximum allowed length for the thumbnail's height/width.
// The default thumbnail size is 1024.
viewer_optimized_opts.SetThumbnailSize(1024);

// A number from 0 (include all thumbnails) to 100
// (include only the first thumbnail). The default value is 50.
viewer_optimized_opts.SetThumbnailRenderingThreshold(40);

// optimize pdf
doc.SaveViewerOptimized("output/path/", viewer_optimized_opts);
// open document from the filesystem
PDFDoc doc = new PDFDoc(filename);

// Options for SaveViewerOptimized
ViewerOptimizedOptions options = new ViewerOptimizedOptions();

// The maximum allowed length for the thumbnail's height/width.
// The default thumbnail size is 1024.
options.setThumbnailSize(1024);

// optimize pdf
doc.saveViewerOptimized('./output/path', options);

linkHow to open viewer optimized PDF file

In order to make viewer optimized PDF work properly with WebViewer, the optimized files need to be hosted on a static server. The opening of the optimized PDF is no different than opening regular PDF files. Demo

WebViewer({
  path: './lib',
  initialDoc: 'https://pdftron.s3.amazonaws.com/downloads/pl/demo-optimized.pdf',
}, document.getElementById('viewer')).then(instance => { })

// or using loadDocument

instance.loadDocument('https://pdftron.s3.amazonaws.com/downloads/pl/demo-optimized.pdf');

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

Join our live demo to learn about use cases & capabilities for WebViewer

Learn more
close