Yes, that overcame that exception. I was confused, as I included this
library for Ant,
but not for PDFBox. I guess 1.1.0 uses common logging now.
However, now I get another exception, having to do with closing a PDF
document,
on this code:
PDDocument OutputDoc;
. . . . .
// Save and close the output file
if (OutputDoc != null)
{
OutputDoc.save(OutPath); <--- Exception occurs here
OutputDoc.close();
}
The exception is:
java.lang.Throwable: Warning: You did not close the PDF Document
at org.apache.pdfbox.cos.COSDocument.finalize(COSDocument.java:404)
at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)
org.apache.pdfbox.exceptions.COSVisitorException: The handle is invalid
at
org.apache.pdfbox.pdfwriter.COSWriter.visitFromStream(COSWriter.java:938)
at org.apache.pdfbox.cos.COSStream.accept(COSStream.java:201)
at org.apache.pdfbox.cos.COSObject.accept(COSObject.java:206)
at
org.apache.pdfbox.pdfwriter.COSWriter.doWriteObject(COSWriter.java:430)
at
org.apache.pdfbox.pdfwriter.COSWriter.doWriteBody(COSWriter.java:361)
at
org.apache.pdfbox.pdfwriter.COSWriter.visitFromDocument(COSWriter.java:767)
at org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:372)
at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1082)
at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:899)
at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:880)
at
autoinsertpdf.AutoInsertPDF.InsertDrawings(AutoInsertPDF.java:294)
at autoinsertpdf.AutoInsertPDF.main(AutoInsertPDF.java:60)
With the incubating version of PDFBox, I my code was a little different
(wrong I think), but that order does not work either in 1.1.0:
if (OutputDoc != null)
{
OutputDoc.save(OutPath); <--- Exception occurs here
}
OutputDoc.close();
Thanks, Alan
--------------------------------------------------
From: "Andreas Lehmkuehler" <[email protected]>
Sent: Sunday, April 11, 2010 8:29 AM
To: <[email protected]>
Subject: Re: Problem Moving to version 1.1.0
Hi,
Alan Thomas schrieb:
I have some code that worked fine in PDF Box 0.8.0-incubating version,
but now it throws an exception when using version 1.1.0:
try
{
System.out.println("--- Processing input file: " +
InDirName
+ "\\" + InFile.getName());
InputDoc = PDDocument.load(InFile);
. . .
}
catch (Exception e)
{
e.printStackTrace();
}
It fails on the line: "InputDoc = PDDocument.load(InFile);", giving the
following exception:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/commons/logging/LogFactory
at
org.apache.pdfbox.pdfparser.BaseParser.<clinit>(BaseParser.java:58)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:846)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:814)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:785)
at
autoinsertpdf.AutoInsertPDF.InsertDrawings(AutoInsertPDF.java:212)
at autoinsertpdf.AutoInsertPDF.main(AutoInsertPDF.java:60)
Caused by: java.lang.ClassNotFoundException:
org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 6 more
Any idea why?
Is commons-logging-1.1.1.jar part of your classpath?
BR
Andreas Lehmkühler