A linearized PDF, when opened in a browser, allows the first page of the document to be loaded and displayed before the entire file is loaded on the browser. It makes the web viewing faster and user does not need to wait for the entire PDF to load to start viewing the document. DsPdf allows you to linearize the PDF documents and also lets you fetch the linearized status of a document. For more information on linearization, see PDF specification 2.0 (Annexure F).
With DsPdf library, you can generate a linearized PDF by using Save method of the GcPdfDocument class. The Save method provides overloads which takes SaveMode enumeration as a parameter along with other mandatory parameters. The SaveMode enumeration gives you option to save the PDF documents in default mode, linearized mode or incremental update mode. Linearized document cannot contain incremental updates. That is, linearized and incremental update modes are mutually exclusive modes. To save a document as linearized PDF, you can set the SaveMode enumeration to Linearized while passing it as a parameter to the Save method. For more information regarding incremental update mode, see Incremental Update.
The example below shows how to linearize an existing PDF document.
C# |
Copy Code
|
---|---|
// Create a new PDF document: GcPdfDocument doc = new GcPdfDocument(); // Modify the document as required // ... // Save the document in linearized mode doc.Save("Demo.pdf", SaveMode.Linearized); |
To fetch the linearized state of a PDF document, you can use Linearized property of the GcPdfDocument class.
C# |
Copy Code
|
---|---|
var fs = new FileStream(@"../../docu01.pdf", FileMode.Open, FileAccess.Read); var pdfDoc = new GcPdfDocument(); pdfDoc.Load(fs); Console.WriteLine($"Linearized: {pdfDoc.Linearized}"); |