Convert a .docx to png options.setPageIndex: does not work

Aspose-Word Trial version :
I tried to convert a word document with code but it does not work : Only the first page is taken

for (int indexP = 0; indexP < doc.getPageCount(); indexP++) { 

options.setPageIndex(indexP); // Only the first page is taken 
doc.save(outStream, options); 
…

Hi Madal,

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

It’s not just one document, it’s all the documents I’ve tested,

public Boolean convertPage(int indexP) throws Exception {

    ByteArrayOutputStream outStream = new ByteArrayOutputStream();

    ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);

    options.setPageIndex(indexP);

    this.doc.save(outStream, options);

    byte[] docBytes = outStream.toByteArray();

    InputStream in = new ByteArrayInputStream(docBytes);
    BufferedImage bImageFromConvert = ImageIO.read(in);

    ImageIO.write(bImageFromConvert, "png", new File(resultName + indexP +".png"));

    return true;
}

Excuse me it is rather this code that does not work
It’s not just one document, it’s all the documents I’ve tested:

    public Boolean convertDoc(String source) throws Exception {

        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);

        for (int indexP = 0; indexP < this.doc.getPageCount(); indexP++) {
            options.setPageIndex(indexP);

            this.doc.save(outStream, options);

            byte[] docBytes = outStream.toByteArray();

            InputStream in = new ByteArrayInputStream(docBytes);
            BufferedImage bImageFromConvert = ImageIO.read(in);

            ImageIO.write(bImageFromConvert, "png", new File(resultName + indexP + ".png"));
            // outStream.flush();
            // outStream.reset(); 

        }

        return true;
    }

Hi Madal,

Thanks for your inquiry. Please note that in evaluation mode there are some limitations applied. E.g. Aspose.Words injects an evaluation watermark at the top of the document. The document’s contents are truncated after a certain number of paragraphs during import or export.

Please request for 30-days temporary license from here:

Get temporary license

Please apply the license before importing document into Aspose.Words’ DOM. Please refer to the following article.

Applying License