Issue
I insert two image to template: "logo" and "background" But only background image presented in template.
I create ImageProdiver
private IImageProvider createImageProvider(IXDocReport ixDocReport, String fieldName, Blob image) {
FieldsMetadata metadata = ixDocReport.createFieldsMetadata();
metadata.addFieldAsImage( fieldName);
ixDocReport.setFieldsMetadata(metadata);
InputStream inputStream = null;
try {
inputStream = image.getBinaryStream();
IImageProvider logo = new ByteArrayImageProvider(inputStream);
logo.setUseImageSize(true);
logo.setResize(true);
inputStream.close();
return logo;
} catch (SQLException | IOException e) {
throw new GeneralException("Error reading logo");
} finally {
if(inputStream != null) {
IOUtils.closeQuietly(inputStream);
}
}
}
Create two Image provider
IImageProvider logo = createImageProdider(report, "logo", blobimage));
IImageProvider background = createImageProdider(report, "logo", blobimagebacground));
and insert to context in builder
context = this.report.createContext();
context.put("logo", logo);
context.put("background", background);
after generate document, exist only background image.
I do not understand why there is this problem, why only one picture is displayed.
How to solve this problem?
Solution
This is because you set FieldsMetadata to report two times. You need to create one FieldsMetadata metadata = ixDocReport.createFieldsMetadata() and add two image to it. Foe example:
FieldsMetadata metadata = new FieldsMetadata();
metadata.addFieldAsImage("chart1");
metadata.addFieldAsImage("chart2");
report.setFieldsMetadata(metadata);
IImageProvider logo = new FileImageProvider(new File("path/to/image1"), true);
context.put("chart1", logo);
IImageProvider logo2 = new FileImageProvider(new File("path/to/image2"), true);
context.put("chart2", logo2);
Answered By - Magomed Gamzatov
Answer Checked By - Mildred Charles (JavaFixing Admin)