This article describes linearized .pdf files and how to create them with Teigha.
What is a linearized .pdf file? Linearization, also known as “fast web view” is a special way to organize a .pdf file that makes it easier to read on the internet in a web browser. In general, a .pdf file is a set of objects such as geometry, text, forms etc., and it is organized with streams. These streams are placed in the file in an arbitrary order, and the references to these streams are at the end of the document. So when the file is opened over the internet, you have to wait while the whole file is downloaded. It is not a problem if the file is small, but it becomes problematic for big files with multiple pages.
If we apply linearization to a .pdf document, it creates a special structure of data at the beginning of the document. The data contains references for the first page and for the rest of the objects in the document. So, when the document is opened through the web, the first page can be displayed almost immediately even while the other pages are still downloading. If the user goes to another page (using the navigation bar or inner link), that page can be also downloaded and displayed independently from other pages. This makes reading .pdf files easier and faster.
When to use linearization? If the .pdf file size is small (the whole file can be quickly downloaded) or it contains only one page, there is no point to make it linearized. Also, it is pointless if the .pdf file is not supposed to be viewed through the web; on a local computer we already have the whole file and we don’t need to open it incrementally, page-by-page. In addition, linearization is not needed when creating .pdf files for long-term archiving (PDF/A files which are described in previous blog articles) because viewers are required to ignore linearization information for PDF/A documents. Linearization is best for large, multi-paged .pdf documents that are supposed to be viewed through a network (corporate web site for example).
Producing linearized .pdf files using Teigha is quite simple. Just put the corresponding flag in the PDFExport parameters before export:
PDFExportParams params; params.setExportFlags(PDFExportParams::PDFExportFlags(PDFExportParams::kDefault | PDFExportParams::kLinearized));
And then export the drawing.
That’s it — the resulting .pdf will be linearized. To check if the .pdf document is linearized, use Adobe® Reader®. Just open the document properties:
Note that there is a known issue with Adobe Acrobat® and Adobe Reader. If the file size is less than about 4Kb, the “Fast Web View” property displays as “No” even when the .pdf file is linearized. However, as mentioned previously, using linearization with small .pdf files is pointless, so most users won’t be affected by this issue.