Aspose.Words JAVA- Unable to download File in Internet Explorer 11

Ok Thanks. I think I got this part to work correctly. i am still having problems downloading files to IE11. Can you reproduce that with these changes to the war file?

And

I am now getting an class cast exception thrown in my callback method. java.lang.String cannot be cast to a java.io.ByteArrayOutputStream.

This started happening when I use the lastest Aspose jar file for Word. So what else has changed?

public void imageFieldMerging(ImageFieldMergingArgs e) throws Exception {
// The field value is a byte array, just cast it and create a stream on it.

if (e.getFieldValue() == null || e.getFieldValue() == “”)
return;

ByteArrayOutputStream baos = (ByteArrayOutputStream)e.getFieldValue();
ByteArrayInputStream imageStream = new ByteArrayInputStream((byte[]) baos.toByteArray());
e.setImageStream(imageStream);

}

}

Hi John,

Thanks for your inquiry. Please see attached simplified template/output documents and following code:

Document doc = new Document(getMyDir() + "input.docx");
doc.getMailMerge().setFieldMergingCallback(new HandleImageMergeField());
doc.getMailMerge().execute(
        new String[] { "MyImageField" },
        new Object[] { ImageIO.read(new File(getMyDir() + "aspose.words.jpg")) });
doc.save(getMyDir() + "15.12.0.docx");
private static class HandleImageMergeField  implements IFieldMergingCallback {
    public void fieldMerging(FieldMergingArgs args) throws Exception {
        // Do nothing.
    }
public void imageFieldMerging(ImageFieldMergingArgs e) throws Exception 
{ 
ByteArrayOutputStream os = new ByteArrayOutputStream(); I
mageIO.write((BufferedImage) e.getFieldValue(), "jpg", os); 
InputStream is = new ByteArrayInputStream(os.toByteArray()); 
e.setImageStream(is); 
}
}

Hope, this helps in fixing your own issue.

Best regards,

Hi - I use your code snipet and I still get a casting error…

java.lang.ClassCastException: java.lang.String cannot be cast to java.awt.image.BufferedImage

public void imageFieldMerging(ImageFieldMergingArgs e) throws Exception {
// The field value is a byte array, just cast it and create a stream on it.

if (e.getFieldValue() == null || e.getFieldValue() == “”)
return;

/*
ByteArrayOutputStream baos = (ByteArrayOutputStream)e.getFieldValue();
ByteArrayInputStream imageStream = new ByteArrayInputStream((byte[]) baos.toByteArray());
e.setImageStream(imageStream);
*/
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write((BufferedImage) e.getFieldValue(), “jpg”, os);
InputStream is = new ByteArrayInputStream(os.toByteArray());
e.setImageStream(is);
}
}

any help here? Something changed from aspose-words-14.11.0-jdk16.jar to aspose-words-15.11.0-jdk16.jar

If I use the older jar file then this error does not occur.

This code works with aspose-words-14.11.0-jdk16.jar
but not with aspose-words-15.11.0-jdk16.jar…

public void imageFieldMerging(ImageFieldMergingArgs e) throws Exception {
// The field value is a byte array, just cast it and create a stream on it.


if (e.getFieldValue() == null || e.getFieldValue() == “”)
return;


ByteArrayOutputStream baos = (ByteArrayOutputStream)e.getFieldValue();
ByteArrayInputStream imageStream = new ByteArrayInputStream((byte[]) baos.toByteArray());
e.setImageStream(imageStream);

/* this is from aspose to fix this casting error in their version5 jar file
// it didn’t work

ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write((BufferedImage) e.getFieldValue(), “jpg”, os);
InputStream is = new ByteArrayInputStream(os.toByteArray());
e.setImageStream(is);
*/
}
}

Hi John,


Thanks for your inquiry. Please upgrade to Aspose.Words for Java 15.12.0. Hope, this helps.
John:
java.lang.ClassCastException: java.lang.String cannot be cast to java.awt.image.BufferedImage
In case the problem still remains, please create a simplified standalone Java application (code without compilation error) that helps us reproduce this exception on our end and attach it here for testing. Thanks for your cooperation.

Best regards,

I get this error…

Error with aspose licenseThe subscription included in this license allows free upgrades until 08 Dec 2015, but this version of the product was released on 31 Dec 2015. Please renew the subscription or use a previous version of the product.

What do I need to do next?

Hi - I have successfully implemented the use of the latest Aspose for words .jar file. but I still need your help. When I first started this project you guys helped me figure out how to loop through a data result set and how to use mail merge tags to fill in the corresponding data.

When I use the latest Jar file - my old source code for this does not work. I have included a very scaled down version of that source code within the provided web application.

If you look at the createReportFile3() - this method does not work.

The method createReportFile4() does indeed work - but it does not use result sets.

Once again - the createReportFile3() works with aspose-words-14.11.0-jdk16.jar but fails with the latest version of your jar file.

Any help that you can provide me will be very beneficial.


Hi John,


Thanks for the additional information. We are working over your query and will get back to you soon.

Best regards,

Hi - is there any status update on this latest issue.

Hi John,


Thanks for being patient. We managed to reproduce this “java.lang.String cannot be cast to java.io.ByteArrayOutputStream” exception with latest version of Aspose.Words for Java 15.12.0 on our end. For the sake of correction, we have logged this problem in our issue tracking system as WORDSJAVA-1287. Our product team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

Best regards,

Hi John,

Thanks for being patient. Regarding WORDSJAVA-1287, the problem occurs because the ADO API of Aspose.Words for Java had been reworked since version 14.10.0. Now, please specify types of columns before you put value in DataRow. Otherwise ByteArrayOutputStrem will be serialized to String. Please see the following sample:

Document doc = new Document(getMyDir() + “Aspose.doc”);

DataSet allRiskData = new DataSet();
DataTable riskDataTable = new DataTable(“RiskList”);

// Set data type for column explicitly
DataColumn riskIdCol    = new DataColumn(“riskIDString”, String.class);
DataColumn testImageCol = new DataColumn(“testImage”, ByteArrayOutputStream.class);
DataColumn testTextCol  = new DataColumn(“testText”, String.class);

riskDataTable.getColumns().add(riskIdCol);
riskDataTable.getColumns().add(testImageCol);
riskDataTable.getColumns().add(testTextCol);

allRiskData.getTables().add(riskDataTable);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedImage img = ImageIO.read(new File(getMyDir() + “Aspose.jpg”));
ImageIO.write(img, “jpg”, baos);

DataRow row = riskDataTable.newRow();
row.set(0, “_9999”);
row.set(1, baos);
row.set(2, “testdata”);
riskDataTable.getRows().add(row);

doc.getMailMerge().setFieldMergingCallback(new HandleMergeImageFieldFromBlob());
doc.getMailMerge().executeWithRegions(allRiskData);

doc.save(getMyDir() + “awjava-15.12.0.docx”);
private static class HandleMergeImageFieldFromBlob implements IFieldMergingCallback {

    public void fieldMerging(FieldMergingArgs e) throws Exception {
        // Do nothing
    }

    public void imageFieldMerging(ImageFieldMergingArgs e) throws Exception {
        // The field value is a byte array, just cast it and create a stream on it.
        if ( “testImage”.equals(e.getFieldName()) ) {
            if (e.getFieldValue() == null)
                return;

            ByteArrayOutputStream baos = (ByteArrayOutputStream) e.getFieldValue();
            ByteArrayInputStream imageStream = new ByteArrayInputStream(baos.toByteArray());
            e.setImageStream(imageStream);
        }
    }
}

Hope, this helps.

Best regards,

My existing code was based on how you guys instructed and advised via examples etc.
I have 260 data elements and now I have to modify source code that is
working in the field at client sites bug free. This is going to cost my
company re-coding, re-testing, and re-dcoumenting money - big time.

That
all being said - I am attaching a zip file that I had attached in an
earlier reply. It does not contain all of my data elements but it does
contain enough source code that you can direct me on what to do from
here. It uses DataRelations and I want to be sure I only have to
re-code once to get my product working.

Please advise on how to engineer my existing source code to the new API.

Thanks

–John

Hi John,


Thanks for your inquiry and sorry for the inconvenience. Regarding WORDSJAVA-1250, you can update your code using the methods mentioned in my this post and to fix the problem (WORDSJAVA-1287), please follow the method as mentioned here. Please let us know if we can be of any further assistance.

Best regards,