Java: Convert Word to PCL

Andrew Wilson
1 min readDec 31, 2021

A PCL file is a digital printed document created in the Printer Command Language. It can be printed to HP LaserJet printers directly without having to be opened in an application. At some point, you might need to convert Word document to PCL. This article will introduce how to implement the conversion programmatically using Free Spire.Doc for Java.

Import JAR Dependency

Method 1: Download the Free API and unzip it. Then add the Spire.Doc.jar file to your Java application 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>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc.free</artifactId>
<version>3.9.0</version>
</dependency>
</dependencies>

Convert Word to PCL

Step 1. Create an instance of Document class.

Step 2. Load a Word document using Document.loadFromFile() method.

Step 3. Save the document to PCL using Document.saveToFile() method.

import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class ConvertWordToPCL {
public static void main(String[] args){
//Create a Document instance
Document document= new Document();
//Load a Word document
document.loadFromFile("Sample.docx");

//Save the document to PCL
document.saveToFile("ToPCL.pcl", FileFormat.PCL);
}
}

--

--

Andrew Wilson

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