Foreword
This article describes how to use Word free Java components Free Spire.Doc for Java in the Java application to convert in the Word document in PDF format. Free Spire.Doc for Java in the conversion process can recognize Chinese characters and supports a rich word document elements: text boxes, headers, footers, bullets and numbering, tables, text, hyperlinks, watermark, images, shapes and so on.
Free Spire.Doc for Java Overview
Free Spire.Doc for Java by E-iceblue developed a free Java Word API, covering the Word document creation, editing, reading, writing, translation and printing functions, and does not rely on Microsoft Office.
Jar file import method
method one:
1: Download the latest Free Spire.Doc for Java package and unzip Download .
2: New Java Application and click File -> Project Structure -> Modules -> Dependencies, under the Dependencies tab interface, right click the green "+" sign, select the first option "JARs or directories ...", select package lib Spire.Doc-FE_2.7.3 Spire.Doc.jar file folder, point "OK", jar file import is successful, the successful introduction as shown below:
3. after completing the above steps, the new Java Class ( here I named WordtoPDF.Java), and add the code.
Method two:
introduced through maven. The method of introducing the reference link ( https://www.e-iceblue.cn/licensing/install-spirepdf-for-java-from-maven-repository.html )
Java code example Word to PDF's:
import com.spire.doc.*;
public class WordtoPDF {
public static void main(String[] args) {
//加载word示例文档
Document document = new Document();
document.loadFromFile("Sample.docx");
//保存为PDF格式
document.saveToFile("out/toPDF.pdf", FileFormat.PDF);
}
}
Word documents before converting shown:
FIG code execution results to PDF: