Convert a multi paged document to images using Java

Hi,
I downloaded the GroupDocs.Conversion-for-Java and tried to use the convertToImageAsFilePath and got the error:
Exception in thread “main” com.groupdocs.conversion.internal.c.a.ms.System.NotSupportedException: Saving complete multipage document to image is not supported. Please save by page.
at com.groupdocs.conversion.domain.savers.image.e.save(Unknown Source)
at com.groupdocs.conversion.domain.documents.h.a(Unknown Source)
at com.groupdocs.conversion.handler.ConvertedDocument.save(Unknown Source)
at com.groupdocs.conversion.examples.Conversion.convertToImageAsFilePath(Conversion.java:302)
at com.groupdocs.conversion.examples.MainClass.main(MainClass.java:48)

I’m using version 18.7 and according to this post, it was solved in version 17.12.

Can you help me?

Thanks,
Shahar.

@shaharh,

Thanks for taking interest in GroupDocs.Conversion for Java and posting your concerns.
Can you please use following code in order to avoid exception/error:

SaveOptions saveOption = new ImageSaveOptions();
saveOption.setConvertFileType(ImageSaveOptions.ImageFileType.JPG);
ConvertedDocument result = conversionHandler.<List<String>>convert("document.pdf", saveOption);
for (int i = 1; i <= result.getPageCount(); i++) {
result.save("output" + i + "." + result.getFileType(), i);
}

Hi,
Thanks but this creates multiple output files. That’s not exactly what I was looking for.
I’m trying to convert a multipage pdf file into a multipage image file such as a tiff file.

It seems that it works when I change it to:
saveOption.setConvertFileType(ImageSaveOptions.ImageFileType.TIFF);
but the example that I downloaded from git was with jpg file type and is not supported which was very confusing.

1 Like

@shaharh,

Good to know that.
Actually, there are multiple image file types (e.g. jpg, tiff, png) and conversion process is same so we set it to JPG but you can change it to other supported formats as well.