Foxit PDF SDK for Web

How to use PDF Linearization with Foxit PDF SDK for Web

PDF linearization is a quick web viewing format which displays pages instantly without having to wait for an entire file to be completely downloaded. To make use of this feature, PDF SDK for Web’s viewer checks at the initialization stage to programmatically detect if it is a linearization document. If it is, the Web viewer uses the fast web view mode (AsyncReaderCallback) to request the data. Otherwise, it follows the normal process mode.

About readblock (request block)

In some cases, you may have the PDF page opening even faster by correctly configuring the viewerOptions.jr.readBlock parameter. The option readBlock is used for allocating the requested data block size with default size as 8192 kb (8mb).

Setting up readBlock in the constructor

```in JS or Index file```
<script src="../../license-key.js"></script>
<script src="../../../lib/preload-jr-worker.js"></script>
var readyWorker = preloadJrWorker({
workerPath: '../../../lib/',
enginePath: '../lib/jr-engine/gsdk',
fontPath: '../external/brotli',
licenseSN: licenseSN,
licenseKey: licenseKey
<script src="../../../lib/UIExtension.full.js"></script>

You can increase the size to 65536 kb (64mb) for example, but it is not recommended to let the value exceed 131072 kb (128mb). The larger block size will also gather more redundant data and consume more memory. The impact that the block size is on the page rendering speed may vary with different file types and use scenarios. You may test and find out a best suitable block size for your environment.

Take the test file as an example which is a linearization file and will be loaded in our mapped network driver.

Note: the Web viewer is currently unable to detect a PDF file containing cross reference streams. It treats cross references files as a common file and downloads the whole document before rendering the pages on screen. If it is large and non-linearlized, the best way is to enable viewerOptions.jr.readBlock and set a proper block size before opening the file.

Methods for detecting an xref stream:

  • You can search for a stream with /Type/XRef (with variable spaces between the two keywords).
  • If you have any streams of /Type/ObjStm you can deduce that there must be an xref stream, since only xref streams can point to object streams.
  • Last but not least, if the PDF version of the document that you parse is less than 1.5 you can be somewhat sure that no xref stream is included. This heavily depends on the PDF authoring tool that created your document. Some stick to the reference whereas some do not.

Updated on August 16, 2021

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: