Conversion from docx to image fails

Hi guys,
I’m using version 22.12.1 for java on OpenJDK 11, Windows 10.
I’m trying to convert this docx to a png file and I get a weird error, here’s the stackTrace:

com.groupdocs.conversion.internal.c.a.ms.System.NotSupportedException: Saving complete multi page document to an image is not supported. Please save by page.
at com.groupdocs.conversion.savers.image.ImageToImageSaver.save(Unknown Source) ~[groupdocs-conversion-22.12.1.jar:22.12.1]
at com.groupdocs.conversion.savers.Saver.save(Unknown Source) ~[groupdocs-conversion-22.12.1.jar:22.12.1]
at com.groupdocs.conversion.documents.h.save(Unknown Source) ~[groupdocs-conversion-22.12.1.jar:22.12.1]
at com.groupdocs.conversion.c.a(Unknown Source) ~[groupdocs-conversion-22.12.1.jar:22.12.1]
at com.groupdocs.conversion.b.convert(Unknown Source) ~[groupdocs-conversion-22.12.1.jar:22.12.1]
at com.groupdocs.conversion.Converter.convert(Unknown Source) ~[groupdocs-conversion-22.12.1.jar:22.12.1]
at com.groupdocs.conversion.Converter.convert(Unknown Source) ~[groupdocs-conversion-22.12.1.jar:22.12.1]
at com.groupdocs.conversion.Converter.convert(Unknown Source) ~[groupdocs-conversion-22.12.1.jar:22.12.1]

Input file: Flight+receipt.docx (172.6 KB)

My code is in fact converting page by page, so I don’t understand why this error is thrown.
Can you please help?
Thank you,
Niro

@nirm

Please use latest version of he API that is 22.12.1 and he following code:

//Java code to convert DOCX to PNG 
Converter converter = new Converter("sample.docx");
final ImageConvertOptions convertOptions = new ImageConvertOptions();
convertOptions.setFormat(ImageFileType.Png);
converter.convert((SavePageStream) i -> {
    try {
        return new FileOutputStream("output" + i + ".png");
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    }
}, convertOptions);

Take a look at the output.zip (538.6 KB).

Hi thanks for the response, but this code doesn’t suit my needs.
I’m initiating the Converter using an inputstream from AWS S3 and the conversion output should be received as an outputstream (not FileOutputStream, but rather ByteArrayOutputStream).
Can you manage that? Does the flow work that way?
I’m using the exact example from here: Load document from Amazon S3 Storage | Documentation and still it doesn’t work. Also, I think this example also doesn’t use the new API for the Converter class.

Why am I getting that weird error if I do convert page by page ? I’m always setting the pageCount to be 1.

@nirm
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CONVERSIONJAVA-1893

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Does this mean you managed to recreate the error?
I will be having paid support in the upcoming days.

@nirm

Yes, and we are already working on this ticket (it’s in progress).

@nirm

Below is the complete working example of saving from AWS to output stream. You just have to write your AWS key, AWS secret, bucket name, region and the object key.

package com.groupdocs.xlsxtopdf;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectInputStream;
import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static void main(String[] args) throws IOException {
        String key = "sample.docx";
        String convertedFile = "converted.pdf";
        Converter converter = new Converter(downloadFile(key));
        PdfConvertOptions options = new PdfConvertOptions();
        try(ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
            converter.convert(() -> outputStream, options);
            System.out.println(outputStream.size());

            // do something with the output stream here

        }
    }

    public static InputStream downloadFile(String key)
    {
        AWSCredentials credentials = new BasicAWSCredentials(
                "AWS accesskey",
                "AWS secretkey"
        );
        AmazonS3 s3client = AmazonS3ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withRegion(Regions.US_EAST_1)
                .build();
        String bucketName = "my-bucket-name";

        S3Object s3object = s3client.getObject(bucketName, key);
        S3ObjectInputStream inputStream = s3object.getObjectContent();
        return inputStream;
    }
}