XtremeDocumentStudio (for Java)
Next-generation multi-format document-processing component suite for Java SE/EE developers
Compatibility
Java 1.6 and later

Print DOCX, PDF and images in Java without using non-native libraries

Learn to print documents using Gnostice XtremeDocumentStudio (for Java).

XtremeDocumentStudio (for Java) is the next-generation multi-format document-processing component suite for Java SE/EE developers. It can display, print and convert DOCX, PDF and image files without requiring any external software. In this article, you will learn how to print a document.

In this code snippet, we have used a DOCX file. We check whether a printer is installed checking the length of the DocumentPrinter.getAvailablePrinterNames() array. If there is a printer, we print the document to the default printer.

import java.awt.print.PrinterException;
import java.io.IOException;

import com.gnostice.core.XDocException;
import com.gnostice.documents.controls.swing.printer.DocumentPrinter;

public class DocumentPrintingDemo {
  
  public static void main(String[] args) {
    try {
      DocumentPrinter prn = new DocumentPrinter();
      if (prn.getAvailablePrinterNames().length > 0) {
        // Load a document
        prn.loadDocument("unicode.docx","");
        // Print to default printer
        prn.print();  
        // Unload IO resources of the document
        prn.closeDocument();
      } else {
        System.out.println("No printer found.");
      }
    } catch (XDocException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (PrinterException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }

}

To demonstrate the print output, we had set an XPS software printer as the default device. Here is the input DOCX and output XPS documents.

---o0O0o---

Our .NET Developer Tools
XtremeDocumentStudio .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
XtremeDocumentStudio 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
XtremeDocumentStudio (for 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-2017 Gnostice Information Technologies Private Limited. All rights reserved.