Convert Microsoft Document (Word) To Image

Hello,
I can’t seem to find an example of this, and saw an old post that said it’s not supported - but I wanted to confirm.
I am attempting to create an internal “image viewer” and am hoping to support several document formats. i.e. Tiff, PNG, JPEG, DOC, DOCX, PDF.
For my viewer, I just need to convert the page to an image format supported by the JavaFX8 ImageView and display it.
I have tiff working (though it’s a little slow at the moment), but I would like to move on to work.
Use Case

  1. Load the document from disk
  2. Get the page request
  3. Convert from Word to PNG (or JPEG)
  4. Display

Can this be done?
Thanks!

Hi Derek,

Thank you for contacting Aspose support.

I am afraid, Aspose.Imaging APIs do not provide the functionality to convert Word documents and PDF files to image format because these features are out of its scope. However, you can use Aspose.Words for Java to convert Word documents and Aspose.Pdf for Java to convert PDF files accordingly.

Please check the following links for better understanding.

Hello,

I don’t mind using the Words. SDK - however I would need to convert the page to either a PNG or JPEG for viewing. I don’t think it’s processor friendly to convert first to TIFF then to a viewable format.

I have the PDF working just fine, but I couldn’t find an example doing it in word.

java.io.OutputStream imageStream = new java.io.FileOutputStream(path);
// Create Resolution object
com.aspose.pdf.devices.Resolution resolution = new com.aspose.pdf.devices.Resolution(300);
// Create JpegDevice object where second argument indicates the quality of resultant image
com.aspose.pdf.devices.PngDevice pngDevice = new com.aspose.pdf.devices.PngDevice();
// Convert a particular page and save the image to stream
pngDevice.process(pdfPages.get_Item(pageToOpen), imageStream);
imageStream.flush();
// Close the stream
imageStream.close();

Hi Derek,

I am going to move this thread to Aspose.Words support forum in order to get an expert’s opinion on this matter. Hopefully soon, my colleagues from the concerned department will get back to you with updates in this regard.

Hi Derek,

Thanks for your inquiry. In order to save all pages in Word document to separate JPEG image files, please use the following code snippet:

Document doc = new Document("C:\Temp\in.docx");

ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);
options.setPageCount(1);

// Save each page of the document as Jpeg.
for (int i = 0; i < doc.getPageCount(); i++)
{
    options.setPageIndex(i);
    doc.save("C:\Temp\out_" + i + ".jpg", options);
}

I hope, this helps.

Best regards,

Just what I needed - thank you.

One question on this. Is WORD 1 based like PDF or 0 based like Tiff Frame?
You example tends to lean to 0 based - but I wanted to make sure.

Hi Derek,

Thanks for your inquiry. Yes, ImageSaveOptions.PageIndex is used to get or set the 0-based index of the first page to render.

Best regards,

I can’t have this ImageSaveOptions available… What’s namespaces?

Here’re my namespaces:

Imports Aspose.Words
Imports Aspose.Words.Drawing

@TECHS,

Thanks for your inquiry. The namespace for this class is Aspose.Words.Saving. Please check Aspose.Words.Saving.ImageSaveOptions.

Dim infilePathName As String = "C:\\Aspose\\Files\\FRB\\inMyFileDOC.docx"

Dim doc As New Aspose.Words.Document(infilePathName)
Dim docBuilder As DocumentBuilder = New DocumentBuilder(doc)

Dim opt As ImageSaveOptions = New ImageSaveOptions(Aspose.Words.SaveFormat.Jpeg)
opt.PageCount = 1
doc.Save("C:\\Aspose\\Files\\FRB\\outMyIshikawa.jpeg", opt)

The jpeg image looks blurry after saving using the above codesoutMyIshikawa.jpeg (127.7 KB)

@TECHS,

Thanks for your inquiry. Please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.

MyTestFile.zip (133.3 KB)

Attached are input& jpeg output.

Thanks

@TECHS,

Thanks for sharing the detail. Please use ImageSaveOptions.Resolution property to set both horizontal and vertical resolution for the generated images, in dots per inch. Please check the following code example. Hope this helps you.

Dim options As ImageSaveOptions = New ImageSaveOptions(SaveFormat.Jpeg)
options.PageIndex = 0
options.PageCount = 1
options.Resolution = 300
doc.Save("out.jpeg", options)