[
https://issues.apache.org/jira/browse/PDFBOX-382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12704099#action_12704099
]
Thomas Modeneis commented on PDFBOX-382:
----------------------------------------
This bug is not invalid, this bug really exists:
take a loook at this two methods:
public static PDDocument loadPdfFromByte(byte [] pdf){
PDDocument document = null;
try {
document = PDDocument.load(new ByteArrayInputStream(pdf));
} catch (IOException e) {}
return document;
}
--
public static List<PDPage> getAllPages(PDDocument document){
int numberOfPages = document.getNumberOfPages();
List<PDPage> paginas = new ArrayList<PDPage>();
List pages = document.getDocumentCatalog().getAllPages();
for (int i = 0; i < numberOfPages; i++) {
paginas.add((PDPage)pages.get(i));
}
return paginas;
}
--
so, after i got document reference i will try to use, paginate and add
another“s to them...
PDDocument document = PDFUtils.loadPdfFromByte(pdf);
List<PDPage> paginas = PDFUtils.getAllPages(document);
for(PDPage pagina:paginas){
document.addPage(pagina);
}
and after two or tree times that i add pages to docFinal, this exception
allways appears on log:
java.lang.Throwable: Warning: You did not close the PDF Document
at org.pdfbox.cos.COSDocument.finalize(COSDocument.java:418)
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)
so, if i try to close document....and then add pages to ANOTHER document
reference....
like this:
public void addPagesToDocument(PDDocument docFinal,byte[] pdf){
PDDocument document = PDFUtils.loadPdfFromByte(pdf);
List<PDPage> paginas = PDFUtils.getAllPages(document);
PDFUtils.close(document);
for(PDPage pagina:paginas){
docFinal.addPage(pagina);
}
}
then i cant create valid PDF...
this exception appears to me when i try to save:
docFinal.save(outputStream);
Exception:
"org.pdfbox.exceptions.COSVisitorException: invalid identifier"
i dont think this is not a bug.....cause for me, it appears to be like a bug.
regards,
Thomas.
> PDDocument apparently unclosed even after calling close()
> ---------------------------------------------------------
>
> Key: PDFBOX-382
> URL: https://issues.apache.org/jira/browse/PDFBOX-382
> Project: PDFBox
> Issue Type: Bug
> Components: PDModel
> Affects Versions: 0.7.3
> Environment: OS X 10.5.5, Java 1.5.0_16
> Reporter: Norman Gray
> Fix For: 0.7.3
>
>
> I can open a PDDocument, extract information from it, and then close it.
> However if I then open another PDDocument, I get an exception 'You did not
> close the PDF Document'. Looking at the relevant code in incubator svn,
> nothing stands out as being obviously wrong.
> To reproduce:
> % cat PDFBoxBugReduction.java
> import org.pdfbox.pdmodel.PDDocument;
> import org.pdfbox.pdmodel.PDDocumentInformation;
> public class PDFBoxBugReduction {
> public static void main(String[] args) {
> for (String s : args) {
> PDFBoxBugReduction fi = new PDFBoxBugReduction(s);
> System.err.println("File " + s);
> }
> }
>
> public PDFBoxBugReduction(String filename) {
> PDDocument doc = null;
> try {
> try {
> doc = new PDDocument().load(filename);
> PDDocumentInformation info = doc.getDocumentInformation();
> } finally {
> if (doc != null) {
> System.err.println("Closing document " + filename +
> "...");
> org.pdfbox.cos.COSDocument cos = doc.getDocument();
> cos.close();
> System.err.println("Closed " + cos);
> doc.close();
> }
>
> }
>
> } catch (java.io.IOException e) {
> System.err.println("IOException=" + e);
> System.exit(1);
> }
> }
> }
> % java -version
> java version "1.5.0_16"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)
> Java HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)
> % javac -cp PDFBox-0.7.3.jar PDFBoxBugReduction.java
> % java -cp PDFBox-0.7.3.jar:. PDFBoxBugReduction ../part1.pdf ../part2.pdf
> Closing document ../part1.pdf...
> Closed org.pdfbox.cos.cosdocum...@2a54f9
> File ../part1.pdf
> java.lang.Throwable: Warning: You did not close the PDF Document
> at org.pdfbox.cos.COSDocument.finalize(COSDocument.java:418)
> 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)
> Closing document ../part2.pdf...
> Closed org.pdfbox.cos.cosdocum...@6672d6
> File ../part2.pdf
> %
> Oddly, replacing
>
> doc = new PDDocument().load(filename);
> by
> doc = new PDDocument();
> doc.load(filename);
> ...makes the problem go away. Is the wrong thing perhaps being returned by
> load()?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.