Gnostice Document Studio Java
Next-generation multi-format document-processing component suite for Java SE/EE developers
Compatibility
Java 1.6 and later

How to convert DOCX files to PDF in Java

Learn to convert documents using XtremeDocumentStudio for Java.

Gnostice XtremeDocumentStudio (for Java) is the next-generation multi-format document-processing component suite for J2SE/J2EE developers. Currently, it supports viewing, printing, and converting PDF, DOCX, BMP, JPEG, PNG, JPEG2000 and single-page/multi-page TIFF. In this article, we will see how to convert documents.

The component to use for converting documents is com.gnostice.documents.DocumentConverter. You can pass the names of the input and output files and then DocumentConverter will automatically guess the input and output formats. DocumentConverter also has overloads with which you can specify the output format using a mime type. And, it also has overloads with which you read/write from/to streams and byte arrays.

import com.gnostice.core.XDocException;
import com.gnostice.documents.ConverterException;
import com.gnostice.documents.DocumentConverter;
import com.gnostice.documents.FormatNotSupportedException;
import com.gnostice.xtremedocumentstudio.Framework;

public class DocumentConversionDemo {  
  public static void main(String[] args) {
    
    // Directory path to refer the Font files used in source
    // document(s) that are not installed in OS Fonts Directory.
    Framework.setUserFontsDirectory("C:\\FontsCollection\\");
    
    // Create instance of DocumentConverter.
    DocumentConverter dc = new DocumentConverter();
    try {
      // Specify the input and output file names.
      dc.convertToFile("./sample.docx", "./sample.pdf");
    } catch (FormatNotSupportedException e) {
      e.printStackTrace();
    } catch (ConverterException e) {
      e.printStackTrace();
    } catch (XDocException e) {
      e.printStackTrace();
    }    
  }
}

---o0O0o---

Our .NET Developer Tools
Gnostice Document Studio .NET

Multi-format document-processing component suite for .NET developers.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
Gnostice Document Studio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
Gnostice Document Studio Java

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs
StarDocs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2024 Gnostice Information Technologies Private Limited. All rights reserved.