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

Getting Started with XtremeDocumentStudio (for Java)'s multi-format DocumentViewer component

Learn to create a multi-format document-viewer Swing application.

Gnostice XtremeDocumentStudio (for Java) is the next-generation multi-format document-processing component suite for Java SE/EE developers. Currently, it supports viewing, printing, and converting PDF, DOCX, BMP, JPEG, PNG, JPEG2000 and single-page/multi-page TIFF. XtremeDocumentStudio can process PDF and DOCX without requiring external software such as Microsoft Word, Open XML SDK, Adobe PDF library or GhostScript.

In this article, we will see how to create a simple document viewer application in using XtremeDocumentStudio and Swing.

  1. Open a Java project in Eclipse.
  2. Ensure that you have SWT and WindowBuilder plugins installed. Install them if they are not available.
  3. Ensure that XtremeDocumentStudio JAR files are included in the project's build path.
  4. Create a new Java class named DocumentViewerDemo extending javax.swing.JFrame class. Ensure that the "New class" wizard automatically generates the main() method stub too.
  5. In Project Explorer, select the Java file and open it in with WindowBuilder Editor.
  6. Switch to the Design tab.
  7. In the Palette view pane, select the MigLayout and add it to the content pane of the JFrame in the Design tab.
  8. From the Palette, add a JButton to the MigLayout.
  9. If you have not already added a category for XtremeDocumentStudio in the Palette, do so now. Add the following components to the category:
    • com.gnostice.documents.controls.swing.viewer.DocumentViewer
    • com.gnostice.documents.controls.swing.viewer.DocumentPrinter
  10. From the Palette, add the DocumentViewer component to the MigLayout.
  11. Switch to Source tab and set the JFrame size to a reasonable size, say 900x600.
    this.setSize(900, 600);
    
  12. Switch to the Design tab and double-click on the JButton. The editor will switch to Source tab and generate addActionListener() boiler-late code.
  13. Add the following code to display a DOCX document in the actionPerformed() method of the listener.
    DocumentViewer viewer = (DocumentViewer) getContentPane().getComponent(1);
    
    try {
      viewer.loadDocument("Article.docx", "");
    } catch (FormatNotSupportedException e) {
      e.printStackTrace();
    } catch (IncorrectPasswordException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (XDocException e) {
      e.printStackTrace();
    }
    
    This assumes that the viewer control is the second (index 1) on the content pane with the other control being the JButton (index 0). You can of course declare the DocumentViewer instance as a global variable. That way you can easily refer it in other methods. As your application becomes any more sophisticated than this, then a global declaration would be the only way to do it right.
  14. Place a file named "Article.docx" in the current directory set in your Run configuration. Or, place some other file and change the file name in the above code appropriately.
  15. In the main() method, instantiate your JFrame and make it visible.
    DocumentViewerDemo oWindow = new DocumentViewerDemo();
    oWindow.setVisible(true);
    
  16. Run the application and click the JButton. The viewer will then display the DOCX file.

This example demonstrated you how to create a simple document viewer application. The download file of XtremeDocumentStudio contains more elaborate source code demos for the viewer control.

---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.