Convert PDF to Linearized in Java

Andrew Wilson
2 min readApr 21, 2023

PDF Linearization or “Fast Web View” is special way of optimizing PDFs to make them easier to read when the file is streamed over a network connection. To meet requirements of certain scenarios, this article will share how to convet a PDF to a linearized PDF in Java using Free Spire.PDF for Java.

Import Dependency (2 methods)

Method 1: Download the free library and unzip it. Then add the Spire.Pdf.jar file to your project as dependency.

Method 2: Directly add the jar dependency to maven project by adding the following configurations to the pom.xml.

<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.pdf.free</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>

Sample Code

The PdfToLinearizedPdfConverter.ToLinearizedPdf() method allows to convert a PDF to linearized. The following is the complete sample code.

import com.spire.pdf.conversion.PdfToLinearizedPdfConverter;

public class toLinearizedPdf {
public static void main(String[] args) {
//Specify the input and output files
String input="C:\\Users\\Administrator\\Desktop\\input.pdf";
String output="toLinearizedPdf.pdf";

//Create a PdfToLinearizedPdfConverter instance and pass in a sample PDF file as a parameter
PdfToLinearizedPdfConverter converter = new PdfToLinearizedPdfConverter(input);

//Convert the file to linearized Pdf
converter.toLinearizedPdf(output);
}
}

Open the result file in Adobe Acrobat and take a look at the document properties, you can see the value of “Fast Web View” is Yes which means the file is linearized.

--

--

Andrew Wilson

Explore C#, Java and Python solutions for processing Word/Excel/PowerPoint/PDF files.