What are Linearized PDF files?
Linearized PDF files are specially organized PDF files designed to display before the PDF file has finished loading. Ordinary PDF files cannot be displayed until the whole file is available which can cause issues if the file is being accessed from the Internet.
How to tell if a PDF is linearized?
If a file is linearized, the word (linearized) will appear in the title bar of the JPedal viewer. If you open the PDF in Adobe Acrobat, it will show that the PDF has a fast web view in properties. There is an article explaining this in more detail.
Access a Linearized PDF file (PDF Viewer examples)
If you are using the JPedal Java PDF Viewer, all the work is done for you. If you open a file as a URL, JPedal will open the file and check to see if it is Linearized, popping up the display as soon as the Linearized part has loaded.
Linearized file functionality in PdfDecoder or PdfDecoderServer class
- openPdfFileFromURL(String pdfUrl, boolean supportLinearized). If supportLinearized is set to true, JPedal will open the PDF. If the file is Linearized, it will retuen true as soon as the linearized part has been read and continue to load the rest fo the file in the background.
- isPDFLinearized(String pdfUrl) returns true if the PDF file is Linearized. It only scans the first 100 bytes of the file so is fast on any PDF file.
- isLoadingLinearizedPDF() returns true is the rest of a linearized PDF file is being loaded in the background.
- isPageAvailable(int pageNumber) returns true if a PDF page can now be displayed.
Example code for using linearization in your own code
If you are using the PDFDecoder or PdfDecoderServer object and wish to use Linearization, there is sample java code showing how to access it in the example Commands file.
Viewing other pages in a PDF Linearized file
Acrobat is able to jump to any PDF page in a Linearized PDF file. Java does not have support for this flexiblity, so JPedal cannot jump to any page. However, JPedal is able to track which page data has now been loaded and display those pages. This is done automatically for you in our PDF Viewer. If you wish to add it to your own java code, here is how to see if the PDF page is available.
//if loading on linearized thread, see if we can actually display
//if non-linearized or linearized and loaded, always returns true
currentGUI.showMessageDialog("Page "+pageNumber+" is not yet loaded");