[]
Linearized PDF documents allow the first page of a PDF to be displayed before the entire document is loaded. This behavior, also known as “fast web view,” improves PDF viewing performance in web browsers.
In DsPdfJS, PDF documents can be saved in linearized mode by specifying the saveMode option with the value SaveMode.Linearized. Linearization and incremental update modes are mutually exclusive and can't be used together.
For information about loading and saving PDF documents, see Create and Save.
You can save a PDF document in linearized mode by specifying SaveMode.Linearized in the saveMode option of the savePdf method.
The following code example shows how to save a PDF document as a linearized PDF.
Note: The examples on this page use helper functions from the Snippet Helpers module. These utilities are provided only to simplify the examples and are not part of the DsPdfJS API.
// load existing PDF
const inputDocData = await Util.loadFile("Wetlands.pdf");
const doc = PdfDocument.load(inputDocData);
// save the document in linearized mode
const docData = doc.savePdf({ saveMode: SaveMode.Linearized });
Util.saveFile("LinearizedPDF.pdf", docData);You can determine whether a PDF document is linearized using the linearized accessor of the PdfDocument class.
The following code example shows how to retrieve the linearization state of a PDF document:
// load existing PDF
const inputDocData = await Util.loadFile("Wetlands.pdf");
const doc = PdfDocument.load(inputDocData);
// get linearized state
console.log(`Linearized: ${doc.linearized}`);