Hi,
When opening a PDF file, if the PDF file is corrupted, an exception is thrown
and but the file handle seems not to be closed properly. I cannot delete the
file after that. Is it a bug ? Any suggestion ?
I'm using Java 1.6, Windows 7, iText 5.4.0.
Here the trace:
2013-05-09 23:33:07,702 ERROR [IncomingDocUtil:106] Error
com.itextpdf.text.exceptions.InvalidPdfException: PDF header signature not
found.
at com.itextpdf.text.pdf.PRTokeniser.getHeaderOffset(PRTokeniser.java:214)
at com.itextpdf.text.pdf.PdfReader.getOffsetTokeniser(PdfReader.java:387)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:166)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:190)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:180)
Code:
public static int getNumOfPages(String filePath) {
int numOfPages = 0;
PdfReader reader = null;
try {
reader = new PdfReader(filePath);
numOfPages = reader.getNumberOfPages();
} catch (Exception e) {
MiscUtils.getLogger().error("Error", e);
} finally {
if (reader != null) {
reader.close();
}
}
return numOfPages;
}
Thanks,
Tan
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and
their applications. This 200-page book is written by three acclaimed
leaders in the field. The early access version is available now.
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php