Some test text!

menu
Viewer optimizedkeyboard_arrow_down

Optimizing PDF files in Android for fast 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.

linkCreate a viewer optimized PDF

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

import java.io.File;
import java.io.IOException;

import com.pdftron.common.PDFNetException;
import com.pdftron.pdf.*;
import com.pdftron.sdf.SDFDoc;
import com.pdftron.sdf.ObjSet;
import com.pdftron.sdf.Obj;

public class myApp {
  public static void main(String[] args) {
    String filename = "input.pdf";
    String output = "output.pdf";

    // PDFNet must be initialized before accessing any PDFTron API
    PDFNet.initialize();
    try {
      // Open document from the filesystem
      PDFDoc doc = new PDFDoc(filename);

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

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

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

      // Optimize pdf
      doc.saveViewerOptimized(output, options);
    }
    catch(PDFNetException e) {
      e.printStackTrace();
      System.out.println(e);
    }

    System.out.println("Done!");
  }
}

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.

linkCreate 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.

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

linkOpen 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.

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.