Using Qoppa’s PDF library, jPDFProcess, you can check if a document is formatted for fast web view using 2 methods:
// Open a PDF document PDFDocument pdfdocument = new PDFDocument("C:\test.pdf", null); // Returns true if document is formatted for Fast Web View System.out.println("Document is linearized: " + pdfdocument.isLinearized()); // Returns the linearization version number System.out.println("LInearization Version: " + pdfdocument.getLinearizationVersionNumber());
Linearized PDF files start with a Linearization Parameter Dictionary at the beginning of the file.
To verify that a file is linearized, there are two entries to check in the Linearization Parameter Dictionary:
- The “Linearized” entry basically confirms yes indeed this is a Linearization Parameter Dictionary and it gives the Linearization version (which I think probably is always 1).
- The “L” entry is the length of the file when it was linearized and if it is not equal to the current file’s length then the PDF should not be considered linearized.
PS: In v2020R2.06, we fixed our verification code to check for both these entries. Previously, our code was just looking at the first 1024 bytes of the file for an occurrence of the character sequence “Linearized” and whatever text immediately followed that was used as the version. We weren’t verifying the file length entry.