Documents for PDF .NET Edition
Features / Linearization
In This Topic
    Linearization
    In This Topic

    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. GcPdf 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 1.7 (Annexure F).

    Linearize a Document

    With GcPdf 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.

    Note: For customers using Linearized property to linearize PDF documents, please note that the Linearized property has been changed to readonly in v5.0 release. If you are using v5.0 build or later, you must now use the Save(xxxx, SaveMode) method as mentioned above in order to linearize the documents.

    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);
    

    Get Linearized State

    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}");