DEV Community

IronSoftware
IronSoftware

Posted on

Linearize PDF for Fast Web View in C# (.NET Guide)

Our document portal served 500-page policy manuals that took 30+ seconds to display the first page. Users clicked away before seeing content. Loading times killed engagement.

Linearizing PDFs solved this. First page appears instantly while the rest streams in background. Here's the implementation.

What Is PDF Linearization?

Linearization reorganizes PDF internal structure so browsers can display the first page before downloading the entire file. Adobe calls this "Fast Web View."

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var pdf = PdfDocument.FromFile("large-document.pdf");
pdf.SaveAsLinearized("optimized.pdf");
Enter fullscreen mode Exit fullscreen mode

The linearized PDF loads page 1 in under a second, even if the full document is 50MB.

How Does Linearization Work?

Standard PDFs store page data throughout the file. To display page 1, the viewer must download significant portions of the file first.

Linearized PDFs reorganize so page 1 data appears at the file beginning. The viewer renders it immediately, then streams remaining pages as they download.

Can I Linearize During PDF Generation?

Yes. Generate and linearize in one step:

using IronPdf;

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Report</h1>");

// Save as linearized PDF
pdf.SaveAsLinearized("linearized-report.pdf");
Enter fullscreen mode Exit fullscreen mode

No need to save twice.

How Do I Linearize Existing PDFs?

Load and re-save:

var pdf = PdfDocument.FromFile("existing.pdf");
pdf.SaveAsLinearized("linearized-existing.pdf");
Enter fullscreen mode Exit fullscreen mode

This works on any PDF, regardless of how it was created.

Can I Linearize from Byte Arrays?

Yes. Useful when PDFs come from APIs or databases:

byte[] pdfBytes = GetPdfFromDatabase();

PdfDocument.SaveAsLinearized(pdfBytes, "output.pdf");
Enter fullscreen mode Exit fullscreen mode

Static method handles byte arrays directly.

How Do I Linearize from Streams?

using System.IO;

using (var stream = File.OpenRead("input.pdf"))
{
    PdfDocument.SaveAsLinearized(stream, "linearized.pdf");
}
Enter fullscreen mode Exit fullscreen mode

Streams work identically to byte arrays.

Does Linearization Increase File Size?

Slightly. Linearization adds metadata (typically 1-5KB) to describe page locations. For a 10MB PDF, expect ~10.02MB linearized.

The speed benefit far outweighs the minimal size increase.

How Do I Verify a PDF Is Linearized?

Check the IsLinearized property:

var pdf = PdfDocument.FromFile("document.pdf");

if (pdf.IsLinearized)
{
    Console.WriteLine("PDF is linearized");
}
else
{
    Console.WriteLine("PDF is not linearized");
}
Enter fullscreen mode Exit fullscreen mode

Adobe Acrobat also shows "Fast Web View: Yes" in document properties.

What's the Performance Impact?

Linearizing a 10MB PDF takes 500-1000ms. For batch processing:

var files = Directory.GetFiles("pdfs", "*.pdf");

foreach (var file in files)
{
    var pdf = PdfDocument.FromFile(file);
    var outputPath = file.Replace(".pdf", "-linearized.pdf");
    pdf.SaveAsLinearized(outputPath);
}
Enter fullscreen mode Exit fullscreen mode

I linearize 1,000 PDFs in under 15 minutes on a standard server.

Does Linearization Work with Password-Protected PDFs?

Yes. Provide the password when loading:

var pdf = PdfDocument.FromFile("protected.pdf", "password123");
pdf.SaveAsLinearized("linearized-protected.pdf");
Enter fullscreen mode Exit fullscreen mode

The output PDF retains the original password protection.

Can I Linearize and Apply Other Modifications?

Yes. Combine operations:

var pdf = PdfDocument.FromFile("input.pdf");

// Add watermark
pdf.ApplyWatermark("<h1>CONFIDENTIAL</h1>");

// Linearize
pdf.SaveAsLinearized("watermarked-linear.pdf");
Enter fullscreen mode Exit fullscreen mode

Linearization is the final save step.

How Do Browsers Handle Linearized PDFs?

Most modern browsers support linearized PDFs:

  • Chrome: Full support
  • Firefox: Full support
  • Edge: Full support
  • Safari: Partial support (macOS/iOS)

Older browsers may ignore linearization and download the full file first.

Should I Linearize All PDFs?

Linearize when:

  • PDFs are served over HTTP/HTTPS
  • Documents exceed 1MB
  • First-page load time matters
  • Users have slow connections

Skip linearization for:

  • Small PDFs (<500KB) - negligible benefit
  • PDFs never viewed in browsers
  • Local-only documents

I linearize all web-served PDFs automatically as part of our upload pipeline.

Can I Linearize PDFs in Azure Functions?

Yes:

[FunctionName("LinearizePdf")]
public async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequest req)
{
    using (var stream = new MemoryStream())
    {
        await req.Body.CopyToAsync(stream);
        stream.Position = 0;

        var outputStream = new MemoryStream();
        PdfDocument.SaveAsLinearized(stream, outputStream);

        return new FileContentResult(outputStream.ToArray(), "application/pdf");
    }
}
Enter fullscreen mode Exit fullscreen mode

Users upload PDFs, get linearized versions back.

What About CDN Caching?

Linearized PDFs cache identically to standard PDFs. Set cache headers:

Response.Headers.Add("Cache-Control", "public, max-age=31536000");
Response.ContentType = "application/pdf";
Response.BinaryWrite(linearizedPdfBytes);
Enter fullscreen mode Exit fullscreen mode

First-time visitors get fast page 1 load. Subsequent visits load instantly from cache.

How Do I Test Linearization?

Use browser dev tools:

  1. Open linearized PDF in Chrome
  2. Open Dev Tools → Network tab
  3. Reload the PDF
  4. Watch for "partial content" 206 responses

These indicate the browser is streaming chunks, not downloading the full file.


Written by Jacob Mellor, CTO at Iron Software. Jacob created IronPDF and leads a team of 50+ engineers building .NET document processing libraries.

Top comments (0)