Monday, 27 July 2020 07:54

Convert Word to PDF in Java

Written by  support iceblue
Rate this item
(0 votes)

This article will show you how to convert Word documents to PDF using Spire.Doc for Java. By using the method of doc.saveToFile(),Spire.Doc supports to convert Word document to XPS,SVG, XML, RTF, PDF etc.

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

public class WordToPDF {
    public static void main(String[] args)  {

        //Create Document object
        Document doc = new Document();

        //Load the file from disk.
        doc.loadFromFile("Sample.docx");

        //create an instance of ToPdfParameterList.
        ToPdfParameterList ppl=new ToPdfParameterList();

        //embeds full fonts by default when IsEmbeddedAllFonts is set to true.
        ppl.isEmbeddedAllFonts(true);

        //set setDisableLink to true to remove the hyperlink effect for the result PDF page.
        //set setDisableLink to false to preserve the hyperlink effect for the result PDF page.
        ppl.setDisableLink(true);

        //Set the output image quality as 40% of the original image. 80% is the default setting.
        doc.setJPEGQuality(40);

        //Save to file.
        doc.saveToFile("output/ToPDF.pdf",FileFormat.PDF);
    }
}

Additional Info

  • tutorial_title: