Hi Team,
We are facing an issue when loading PDF file with the below error.
com.aspose.pdf.exceptions.InvalidPdfFileFormatException: Incorect file format
at com.aspose.pdf.internal.l9u.ld.lI(Unknown Source)
at com.aspose.pdf.internal.l5h.l1t$lI.deserialize(Unknown Source)
at com.aspose.pdf.internal.l9p.le.deserialize(Unknown Source)
at com.aspose.pdf.internal.l8n.l0v.(Unknown Source)
at com.aspose.pdf.internal.l8n.l0v.(Unknown Source)
at com.aspose.pdf.internal.l6if.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l8n.l0t.(Unknown Source)
at com.aspose.pdf.internal.l6if.lf.lb(Unknown Source)
at com.aspose.pdf.internal.l0y.l0p.lf(Unknown Source)
at com.aspose.pdf.internal.l0y.l0p.(Unknown Source)
at com.aspose.pdf.ADocument.lI(Unknown Source)
at com.aspose.pdf.ADocument.(Unknown Source)
at com.aspose.pdf.ADocument.(Unknown Source)
at com.aspose.pdf.Document.(Unknown Source)
But when the client tries again the same file, it works fine.
Below is the code snippet and highlighted the line where we see the issue:
public static MergeStream mergePdfApsose(List inputStreams) throws SystemException {
MergeStream mergeStream = new MergeStream();
com.aspose.pdf.Document doc0 = null;
ByteArrayOutputStream outputStream = null;
int totalpagecount=0;
InputStream inptstream;
try {
outputStream = new ByteArrayOutputStream();
doc0 = new com.aspose.pdf.Document();
for (int i = 0; i < inputStreams.size(); i++) {
if (i == 0) {
doc0 = new com.aspose.pdf.Document(inputStreams.get(i));
} else {
com.aspose.pdf.Document doc1 = new com.aspose.pdf.Document(inputStreams.get(i));
doc0.getPages().add(doc1.getPages());
}
}
totalpagecount = doc0.getPages().size();
doc0.save(outputStream);
byte[] bytearr = outputStream.toByteArray();
inptstream = new ByteArrayInputStream(bytearr);
} catch (Exception e) {
log.error(DOCUMENT_MERGE_EXCEPTION,e);
throw new SystemException(e);
} finally {
try {
outputStream.close();
} catch (IOException e) {
log.error(OUTPUT_STREAM_EXCEPTION,e);
throw new RuntimeException(e);
}
}
mergeStream.setInputstream(inptstream);
mergeStream.setToatlapgecnt(totalpagecount);
return mergeStream;
}
The PDF file in question is 45MB in size with 2010 pages