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

Convert DOCX, DOC, PDF to images in Java

Using XtremeDocumentStudio (for Java) library.

The DocumentConverter class is used to convert DOCX and PDF documents and images to other formats. In this article, we will see how to convert documents to images and also use the various conversion settings in the process.

This code snippet converts a DOCX document to an image. It is aligned to the top of the page. The content from the original document is not resized. The pixel density of the image is 96.

public class ConvertToImage {
  
  public static void main(String[] args) {    
    DocumentConverter dc = new DocumentConverter();
    try {
      ImageEncoderSettings ies = 
          (ImageEncoderSettings) dc.getPreferences().getEncoderSettings("image/png");
      
      ies.setPageAlignment(new PageAlignment(Horizontal.CENTER, Vertical.CENTER));
      ies.setPageScaling(com.gnostice.documents.image.PageScaling.NONE);
      ies.setPageSizingMode(PageSizingMode.USE_PAGE_SIZE);      
      dc.getPreferences().getRenderingSettings().getResolution().setDpi(96);
      
      dc.convertToFile("./ad.pdf", "./sample.png");      
    } catch (FormatNotSupportedException e) {
      e.printStackTrace();
    } catch (ConverterException e) {
      e.printStackTrace();
    } catch (XDocException e) {
      e.printStackTrace();
    }
  }
}

The image looks unwieldy. Some changes...

ies.setPageScaling(com.gnostice.documents.image.PageScaling.NONE);
ies.setPageSize(new PageSize(PaperSize.A4));
ies.setPageSizingMode(PageSizingMode.USE_RELATIVE_SIZE);      
dc.getPreferences().getRenderingSettings().getResolution().setDpi(150);

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