this is how I am saving the pdf to memStream. MemStream ms = new MemStream(); pdf.save(ms);
byte[] b = ms.toArray(); ByteArrayInputStream byteStream = new ByteArrayInputStream(b); List inStreams = new ArrayList(); inStreams.add(byteStream);
PdfFileEditor pdfEditor = new PdfFileEditor();
InputStream[] ins = new InputStream[inStreams.size()]; for(int i=0;i<inStreams.size();i++) { ins[i] = inStreams.get(i); } FileOutputStream outStream = new FileOutputStream("d:\\docName.pdf"); pdfEditor.concatenate(ins, outStream);
When there is only one pdf file then I am getting following exception java.lang.IllegalArgumentException: Invalid image or template handle in PlaceImage method. at aspose.pdf.figure.Aba.a(SourceFile:521) at aspose.pdf.xml.Abi.a(SourceFile:729) at aspose.pdf.xml.Aaj.a(SourceFile:630) at aspose.pdf.xml.Aca.a(SourceFile:246) at aspose.pdf.xml.Aci.a(SourceFile:545) at aspose.pdf.xml.Abt.a(SourceFile:152) at aspose.pdf.xml.Aas.a(SourceFile:100) at aspose.pdf.xml.Aba.a(SourceFile:122) at aspose.pdf.Pdf.save(SourceFile:1167) at aspose.pdf.Pdf.save(SourceFile:1113)
But if there are one file then I am not getting any exception.
Can you please tell what am I doing wrong. And why do we get that exception.
Hi Mamatha,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thank you for sharing the
sample code and template file.
Regarding your issue, I
checked it using Aspose.Pdf.Java
v3.0.1 and the code runs fine without any exception. The code for
generating PDF file is working fine and generates a proper PDF file (using Aspose.Pdf
for Java, file is attached for reference). However, the concatenate method of Aspose.Pdf.Kit for java in your
code generates a corrupt PDF file. But regarding the concatenation, could you
please re-check your code as there is only one file and you are passing it to
concatenate method. I am also moving this issue to Aspose.Pdf.Kit forum, so our
team can check this issue regarding concatenate method and get back to you.
I would like to share that the concatenate method requires at least two files to work properly. If you pass a single file as input it will not work as expected. So, in case, you have only single file you could check the size of the input array before hand and skip the concatenate method at all.
I hope this helps. If you still find any issue or have further questions, please do let us know. Regards,
I’m glad to know that the issue is resolved for your particular scenario. As far as handling single file scenario for concatenate method is concerned, it is the prerequisite of the method to have at least two files to concatenate. Moreover, we haven’t yet received any other such requests to handle single file scenarios automatically. However, we’ll further look into this and see if it would be feasible for us to cater such scenario in the future.
If you find any further questions, please do let us know. Regards,