Hi Mamatha,
Thanks for your patience.
I have again tested the scenario where I have tried loading the Image file into BufferImage object, then created a Byte array, instantiated the BinaryFileStream object with Byte array contents and then I have passed these contents to setImageStream(…) and as per my observations, I am getting an Exception while saving the PDF document. For
the sake of correction, I have logged it in our issue tracking system as PDFJAVA-33153. We
will investigate this issue in details and will keep you updated on the status
of a correction. I have used the following code snippet to test the scenario.
We
apologize for your inconvenience.
[Java]
<span style=“font-size:
10.0pt;font-family:“Courier New”;color:#3F7F5F”>// load the source image file<span style=“font-size:10.0pt;font-family:“Courier New””><o:p></o:p>
BufferedImage img = ImageIO.read(new File("d:/pdftest/Question.png"));
ByteArrayOutputStream bas = new
ByteArrayOutputStream();
ImageIO.write(img, "pnm", bas);
// instantiage byte
array with image contents
byte[] data =
bas.toByteArray();
// instantiate Pdf
object
Pdf pdf1 = new Pdf();
// bind the source XML
pdf1.bindXML("d:/pdftest/Template_new
(1).xml", null);
// get Section object already
specified in XML file
Section sec1 =
pdf1.getSections().getSection("Section1");
// get the Image Object as
specified in XML file
aspose.pdf.Image image3 =
(Image)sec1.getObjectByID("signatureImage");
// Read the source Image file
BinaryFileStream binarydata = new
BinaryFileStream(data);
//binarydata.read(data, 0, data.length);
// set contents of
BinaryFileStream to Image object
image3.getImageInfo().setImageStream(binarydata);
// specify the type of image
file
image3.getImageInfo().setImageFileType(ImageFileType.Png);
// save PDF document
pdf1.save("d:/pdftest/StreamImage-Test.pdf");
// close the Binary Stream
binarydata.close();