You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "James A. Thomas (JIRA)" <ji...@apache.org> on 2009/07/28 21:40:14 UTC

[jira] Created: (PDFBOX-497) COSVisitorException: The handle is invalid

COSVisitorException: The handle is invalid
------------------------------------------

                 Key: PDFBOX-497
                 URL: https://issues.apache.org/jira/browse/PDFBOX-497
             Project: PDFBox
          Issue Type: Bug
          Components: PDModel
         Environment: Windows Vista
            Reporter: James A. Thomas
             Fix For: 0.8.0-incubator


    If I save a PDF document in a method of an application class, I get a COSVisitorException: The handle is invalid.  
-------------------------------------------------------------------------------------------------- 
       I found that I no longer get this exception if I do not close the 
PDDocument "DrawingDoc" in the method "addDrawing".

        However, I do get a warning:

java.lang.Throwable: Warning: You did not close the PDF Document
        at org.apache.pdfbox.cos.COSDocument.finalize(COSDocument.java:391)
        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)

                                            Alan

--------------------------------------------------
From: "Alan Thomas" <ja...@verizon.net>
Sent: Monday, July 27, 2009 6:13 AM
To: <pd...@incubator.apache.org>
Subject: Re: COSVisitorException: The handle is invalid

> It was created by adding pages from other PDF documents, like below.
>
> Is there anything wrong with returning a PDDocument from the method 
> addDrawing like I am doing?
>
> 
> Alan
>
> PDDocument OutputDoc = null;
> . . .
>
> OutputDoc = new PDDocument();
> . . .
> copyPage(OutputDoc, page);
> . . .
> OutputDoc = addDrawing(OutputDoc,
>                                DrawingsDir.getName(), Barcode);
> . . .
>            finally
>            {
>                try
>                {
>                    // Save and close the output file
>                    if (OutputDoc != null)
>                    {
>                        System.out.println("OutPath = " + OutPath);
>                        OutputDoc.save(OutPath);
>                    }
>                    OutputDoc.close();
> . . .
>
> using these methods I created:
>
>    private void copyPage( PDDocument doc, PDPage page) throws Exception
>    {
>        PDPage imported = doc.importPage(page);
>        imported.setCropBox(page.findCropBox());
>        imported.setMediaBox(page.findMediaBox());
>        imported.setResources(page.findResources());
>        imported.setRotation(page.findRotation());
>    }
>
>    private PDDocument addDrawing( PDDocument OutDoc, String 
> DrawingsDirName,
>                                        String barcode)
>    {
>        PDDocument DrawingDoc = null;
>
>      try
>      {
>            .  .  .
>          List pages = DrawingDoc.getDocumentCatalog().getAllPages();
>
>          for (Object obj : pages)
>          {
>              PDPage page = (PDPage)obj;
>              copyPage(OutDoc, page);
>          }
>      }
>      catch (Exception e)
>      {
>          e.printStackTrace();
>      }
>      finally
>      {
>        try
>        {
>          DrawingDoc.close();
>          return OutDoc;
>        }
>        catch (Exception e)
>        {
>            return OutDoc;
>        }
>      }
>    }
>
>
> --------------------------------------------------
> From: "Andreas Lehmkühler" <an...@lehmi.de>
> Sent: Monday, July 27, 2009 5:15 AM
> To: <pd...@incubator.apache.org>
> Subject: Re: COSVisitorException: The handle is invalid
>
>> Hi Alan,
>>
>> how did you create your pdf?
>>
>> BR
>> Andreas Lehmkühler
>>
>> ----- original Nachricht --------
>>
>> Betreff: COSVisitorException: The handle is invalid
>> Gesendet: Mo, 27. Jul 2009
>> Von: Alan Thomas<ja...@verizon.net>
>>
>>> Hi.  When I save a PDF document in my application, I get a
>>> COSVisitorException: "The handle is invalid".
>>>
>>>         However, I do not see anything wrong with it.  I show the error, 
>>> the
>>> string I am giving the PDDocument.save() method, and the code that 
>>> attempts
>>> to save the file.
>>>
>>>         Any idea what I am doing wrong?                Thanks, Alan
>>>
>>> OutPath = C:\Users\Alan\Documents\My Stuff\X Y Z Stuff\Application\Java 
>>> App
>>> Test\New Folder\InsertedPages 2.pdf
>>>
>>> org.apache.pdfbox.exceptions.COSVisitorException: The handle is invalid
>>>         at
>>> org.apache.pdfbox.pdfwriter.COSWriter.visitFromStream(COSWriter.java:939)
>>>         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:768)
>>>         at 
>>> org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:361)
>>>         at 
>>> org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1070)
>>>         at 
>>> org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:787)
>>>         at 
>>> org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:768)
>>>
>>>
>>>                     // Save and close the output file
>>>                     if (OutputDoc != null)
>>>                     {
>>>                         System.out.println("OutPath = " + OutPath);
>>>                         OutputDoc.save(OutPath);
>>>                     }
>>>                     OutputDoc.close();
>>>
>>
>> --- original Nachricht Ende ----
>>
>>
>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-497) COSVisitorException: The handle is invalid

Posted by "James A. Thomas (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-497?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12736952#action_12736952 ] 

James A. Thomas commented on PDFBOX-497:
----------------------------------------

Andreas,

You (of course) were correct.  I had to redesign my application to load the input document prior to calling the method, and then passing the PDDocument to it.

Is there something inherent in PDF that requires this with the resources, or is it how PDF Box is implemented?

At a minimum, I would think the order of things to do (not obvious to me) needs to be somewhere in the PDF Box documentation.

Thanks, Alan


> COSVisitorException: The handle is invalid
> ------------------------------------------
>
>                 Key: PDFBOX-497
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-497
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>         Environment: Windows Vista
>            Reporter: James A. Thomas
>             Fix For: 0.8.0-incubator
>
>
>     If I save a PDF document in a method of an application class, I get a COSVisitorException: The handle is invalid.  
> -------------------------------------------------------------------------------------------------- 
>        I found that I no longer get this exception if I do not close the 
> PDDocument "DrawingDoc" in the method "addDrawing".
>         However, I do get a warning:
> java.lang.Throwable: Warning: You did not close the PDF Document
>         at org.apache.pdfbox.cos.COSDocument.finalize(COSDocument.java:391)
>         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)
>                                             Alan
> --------------------------------------------------
> From: "Alan Thomas" <ja...@verizon.net>
> Sent: Monday, July 27, 2009 6:13 AM
> To: <pd...@incubator.apache.org>
> Subject: Re: COSVisitorException: The handle is invalid
> > It was created by adding pages from other PDF documents, like below.
> >
> > Is there anything wrong with returning a PDDocument from the method 
> > addDrawing like I am doing?
> >
> > 
> > Alan
> >
> > PDDocument OutputDoc = null;
> > . . .
> >
> > OutputDoc = new PDDocument();
> > . . .
> > copyPage(OutputDoc, page);
> > . . .
> > OutputDoc = addDrawing(OutputDoc,
> >                                DrawingsDir.getName(), Barcode);
> > . . .
> >            finally
> >            {
> >                try
> >                {
> >                    // Save and close the output file
> >                    if (OutputDoc != null)
> >                    {
> >                        System.out.println("OutPath = " + OutPath);
> >                        OutputDoc.save(OutPath);
> >                    }
> >                    OutputDoc.close();
> > . . .
> >
> > using these methods I created:
> >
> >    private void copyPage( PDDocument doc, PDPage page) throws Exception
> >    {
> >        PDPage imported = doc.importPage(page);
> >        imported.setCropBox(page.findCropBox());
> >        imported.setMediaBox(page.findMediaBox());
> >        imported.setResources(page.findResources());
> >        imported.setRotation(page.findRotation());
> >    }
> >
> >    private PDDocument addDrawing( PDDocument OutDoc, String 
> > DrawingsDirName,
> >                                        String barcode)
> >    {
> >        PDDocument DrawingDoc = null;
> >
> >      try
> >      {
> >            .  .  .
> >          List pages = DrawingDoc.getDocumentCatalog().getAllPages();
> >
> >          for (Object obj : pages)
> >          {
> >              PDPage page = (PDPage)obj;
> >              copyPage(OutDoc, page);
> >          }
> >      }
> >      catch (Exception e)
> >      {
> >          e.printStackTrace();
> >      }
> >      finally
> >      {
> >        try
> >        {
> >          DrawingDoc.close();
> >          return OutDoc;
> >        }
> >        catch (Exception e)
> >        {
> >            return OutDoc;
> >        }
> >      }
> >    }
> >
> >
> > --------------------------------------------------
> > From: "Andreas Lehmkühler" <an...@lehmi.de>
> > Sent: Monday, July 27, 2009 5:15 AM
> > To: <pd...@incubator.apache.org>
> > Subject: Re: COSVisitorException: The handle is invalid
> >
> >> Hi Alan,
> >>
> >> how did you create your pdf?
> >>
> >> BR
> >> Andreas Lehmkühler
> >>
> >> ----- original Nachricht --------
> >>
> >> Betreff: COSVisitorException: The handle is invalid
> >> Gesendet: Mo, 27. Jul 2009
> >> Von: Alan Thomas<ja...@verizon.net>
> >>
> >>> Hi.  When I save a PDF document in my application, I get a
> >>> COSVisitorException: "The handle is invalid".
> >>>
> >>>         However, I do not see anything wrong with it.  I show the error, 
> >>> the
> >>> string I am giving the PDDocument.save() method, and the code that 
> >>> attempts
> >>> to save the file.
> >>>
> >>>         Any idea what I am doing wrong?                Thanks, Alan
> >>>
> >>> OutPath = C:\Users\Alan\Documents\My Stuff\X Y Z Stuff\Application\Java 
> >>> App
> >>> Test\New Folder\InsertedPages 2.pdf
> >>>
> >>> org.apache.pdfbox.exceptions.COSVisitorException: The handle is invalid
> >>>         at
> >>> org.apache.pdfbox.pdfwriter.COSWriter.visitFromStream(COSWriter.java:939)
> >>>         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:768)
> >>>         at 
> >>> org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:361)
> >>>         at 
> >>> org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1070)
> >>>         at 
> >>> org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:787)
> >>>         at 
> >>> org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:768)
> >>>
> >>>
> >>>                     // Save and close the output file
> >>>                     if (OutputDoc != null)
> >>>                     {
> >>>                         System.out.println("OutPath = " + OutPath);
> >>>                         OutputDoc.save(OutPath);
> >>>                     }
> >>>                     OutputDoc.close();
> >>>
> >>
> >> --- original Nachricht Ende ----
> >>
> >>
> >

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (PDFBOX-497) COSVisitorException: The handle is invalid

Posted by "Andreas Lehmkühler (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-497?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andreas Lehmkühler updated PDFBOX-497:
--------------------------------------

        Fix Version/s:     (was: 0.8.0-incubator)
    Affects Version/s: 0.8.0-incubator

> COSVisitorException: The handle is invalid
> ------------------------------------------
>
>                 Key: PDFBOX-497
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-497
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 0.8.0-incubator
>         Environment: Windows Vista
>            Reporter: James A. Thomas
>
>     If I save a PDF document in a method of an application class, I get a COSVisitorException: The handle is invalid.  
> -------------------------------------------------------------------------------------------------- 
>        I found that I no longer get this exception if I do not close the 
> PDDocument "DrawingDoc" in the method "addDrawing".
>         However, I do get a warning:
> java.lang.Throwable: Warning: You did not close the PDF Document
>         at org.apache.pdfbox.cos.COSDocument.finalize(COSDocument.java:391)
>         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)
>                                             Alan
> --------------------------------------------------
> From: "Alan Thomas" <ja...@verizon.net>
> Sent: Monday, July 27, 2009 6:13 AM
> To: <pd...@incubator.apache.org>
> Subject: Re: COSVisitorException: The handle is invalid
> > It was created by adding pages from other PDF documents, like below.
> >
> > Is there anything wrong with returning a PDDocument from the method 
> > addDrawing like I am doing?
> >
> > 
> > Alan
> >
> > PDDocument OutputDoc = null;
> > . . .
> >
> > OutputDoc = new PDDocument();
> > . . .
> > copyPage(OutputDoc, page);
> > . . .
> > OutputDoc = addDrawing(OutputDoc,
> >                                DrawingsDir.getName(), Barcode);
> > . . .
> >            finally
> >            {
> >                try
> >                {
> >                    // Save and close the output file
> >                    if (OutputDoc != null)
> >                    {
> >                        System.out.println("OutPath = " + OutPath);
> >                        OutputDoc.save(OutPath);
> >                    }
> >                    OutputDoc.close();
> > . . .
> >
> > using these methods I created:
> >
> >    private void copyPage( PDDocument doc, PDPage page) throws Exception
> >    {
> >        PDPage imported = doc.importPage(page);
> >        imported.setCropBox(page.findCropBox());
> >        imported.setMediaBox(page.findMediaBox());
> >        imported.setResources(page.findResources());
> >        imported.setRotation(page.findRotation());
> >    }
> >
> >    private PDDocument addDrawing( PDDocument OutDoc, String 
> > DrawingsDirName,
> >                                        String barcode)
> >    {
> >        PDDocument DrawingDoc = null;
> >
> >      try
> >      {
> >            .  .  .
> >          List pages = DrawingDoc.getDocumentCatalog().getAllPages();
> >
> >          for (Object obj : pages)
> >          {
> >              PDPage page = (PDPage)obj;
> >              copyPage(OutDoc, page);
> >          }
> >      }
> >      catch (Exception e)
> >      {
> >          e.printStackTrace();
> >      }
> >      finally
> >      {
> >        try
> >        {
> >          DrawingDoc.close();
> >          return OutDoc;
> >        }
> >        catch (Exception e)
> >        {
> >            return OutDoc;
> >        }
> >      }
> >    }
> >
> >
> > --------------------------------------------------
> > From: "Andreas Lehmkühler" <an...@lehmi.de>
> > Sent: Monday, July 27, 2009 5:15 AM
> > To: <pd...@incubator.apache.org>
> > Subject: Re: COSVisitorException: The handle is invalid
> >
> >> Hi Alan,
> >>
> >> how did you create your pdf?
> >>
> >> BR
> >> Andreas Lehmkühler
> >>
> >> ----- original Nachricht --------
> >>
> >> Betreff: COSVisitorException: The handle is invalid
> >> Gesendet: Mo, 27. Jul 2009
> >> Von: Alan Thomas<ja...@verizon.net>
> >>
> >>> Hi.  When I save a PDF document in my application, I get a
> >>> COSVisitorException: "The handle is invalid".
> >>>
> >>>         However, I do not see anything wrong with it.  I show the error, 
> >>> the
> >>> string I am giving the PDDocument.save() method, and the code that 
> >>> attempts
> >>> to save the file.
> >>>
> >>>         Any idea what I am doing wrong?                Thanks, Alan
> >>>
> >>> OutPath = C:\Users\Alan\Documents\My Stuff\X Y Z Stuff\Application\Java 
> >>> App
> >>> Test\New Folder\InsertedPages 2.pdf
> >>>
> >>> org.apache.pdfbox.exceptions.COSVisitorException: The handle is invalid
> >>>         at
> >>> org.apache.pdfbox.pdfwriter.COSWriter.visitFromStream(COSWriter.java:939)
> >>>         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:768)
> >>>         at 
> >>> org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:361)
> >>>         at 
> >>> org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1070)
> >>>         at 
> >>> org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:787)
> >>>         at 
> >>> org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:768)
> >>>
> >>>
> >>>                     // Save and close the output file
> >>>                     if (OutputDoc != null)
> >>>                     {
> >>>                         System.out.println("OutPath = " + OutPath);
> >>>                         OutputDoc.save(OutPath);
> >>>                     }
> >>>                     OutputDoc.close();
> >>>
> >>
> >> --- original Nachricht Ende ----
> >>
> >>
> >

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-497) COSVisitorException: The handle is invalid

Posted by "Andreas Lehmkühler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-497?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12736568#action_12736568 ] 

Andreas Lehmkühler commented on PDFBOX-497:
-------------------------------------------

I guess you have to close your docs in the right order.

- open your input-doc
- create one or more docs as part of your input-doc
- save the new doc(s)
- close the new doc(s)
- close your input-doc

Please try this and give us a feedback.

> COSVisitorException: The handle is invalid
> ------------------------------------------
>
>                 Key: PDFBOX-497
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-497
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>         Environment: Windows Vista
>            Reporter: James A. Thomas
>             Fix For: 0.8.0-incubator
>
>
>     If I save a PDF document in a method of an application class, I get a COSVisitorException: The handle is invalid.  
> -------------------------------------------------------------------------------------------------- 
>        I found that I no longer get this exception if I do not close the 
> PDDocument "DrawingDoc" in the method "addDrawing".
>         However, I do get a warning:
> java.lang.Throwable: Warning: You did not close the PDF Document
>         at org.apache.pdfbox.cos.COSDocument.finalize(COSDocument.java:391)
>         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)
>                                             Alan
> --------------------------------------------------
> From: "Alan Thomas" <ja...@verizon.net>
> Sent: Monday, July 27, 2009 6:13 AM
> To: <pd...@incubator.apache.org>
> Subject: Re: COSVisitorException: The handle is invalid
> > It was created by adding pages from other PDF documents, like below.
> >
> > Is there anything wrong with returning a PDDocument from the method 
> > addDrawing like I am doing?
> >
> > 
> > Alan
> >
> > PDDocument OutputDoc = null;
> > . . .
> >
> > OutputDoc = new PDDocument();
> > . . .
> > copyPage(OutputDoc, page);
> > . . .
> > OutputDoc = addDrawing(OutputDoc,
> >                                DrawingsDir.getName(), Barcode);
> > . . .
> >            finally
> >            {
> >                try
> >                {
> >                    // Save and close the output file
> >                    if (OutputDoc != null)
> >                    {
> >                        System.out.println("OutPath = " + OutPath);
> >                        OutputDoc.save(OutPath);
> >                    }
> >                    OutputDoc.close();
> > . . .
> >
> > using these methods I created:
> >
> >    private void copyPage( PDDocument doc, PDPage page) throws Exception
> >    {
> >        PDPage imported = doc.importPage(page);
> >        imported.setCropBox(page.findCropBox());
> >        imported.setMediaBox(page.findMediaBox());
> >        imported.setResources(page.findResources());
> >        imported.setRotation(page.findRotation());
> >    }
> >
> >    private PDDocument addDrawing( PDDocument OutDoc, String 
> > DrawingsDirName,
> >                                        String barcode)
> >    {
> >        PDDocument DrawingDoc = null;
> >
> >      try
> >      {
> >            .  .  .
> >          List pages = DrawingDoc.getDocumentCatalog().getAllPages();
> >
> >          for (Object obj : pages)
> >          {
> >              PDPage page = (PDPage)obj;
> >              copyPage(OutDoc, page);
> >          }
> >      }
> >      catch (Exception e)
> >      {
> >          e.printStackTrace();
> >      }
> >      finally
> >      {
> >        try
> >        {
> >          DrawingDoc.close();
> >          return OutDoc;
> >        }
> >        catch (Exception e)
> >        {
> >            return OutDoc;
> >        }
> >      }
> >    }
> >
> >
> > --------------------------------------------------
> > From: "Andreas Lehmkühler" <an...@lehmi.de>
> > Sent: Monday, July 27, 2009 5:15 AM
> > To: <pd...@incubator.apache.org>
> > Subject: Re: COSVisitorException: The handle is invalid
> >
> >> Hi Alan,
> >>
> >> how did you create your pdf?
> >>
> >> BR
> >> Andreas Lehmkühler
> >>
> >> ----- original Nachricht --------
> >>
> >> Betreff: COSVisitorException: The handle is invalid
> >> Gesendet: Mo, 27. Jul 2009
> >> Von: Alan Thomas<ja...@verizon.net>
> >>
> >>> Hi.  When I save a PDF document in my application, I get a
> >>> COSVisitorException: "The handle is invalid".
> >>>
> >>>         However, I do not see anything wrong with it.  I show the error, 
> >>> the
> >>> string I am giving the PDDocument.save() method, and the code that 
> >>> attempts
> >>> to save the file.
> >>>
> >>>         Any idea what I am doing wrong?                Thanks, Alan
> >>>
> >>> OutPath = C:\Users\Alan\Documents\My Stuff\X Y Z Stuff\Application\Java 
> >>> App
> >>> Test\New Folder\InsertedPages 2.pdf
> >>>
> >>> org.apache.pdfbox.exceptions.COSVisitorException: The handle is invalid
> >>>         at
> >>> org.apache.pdfbox.pdfwriter.COSWriter.visitFromStream(COSWriter.java:939)
> >>>         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:768)
> >>>         at 
> >>> org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:361)
> >>>         at 
> >>> org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1070)
> >>>         at 
> >>> org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:787)
> >>>         at 
> >>> org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:768)
> >>>
> >>>
> >>>                     // Save and close the output file
> >>>                     if (OutputDoc != null)
> >>>                     {
> >>>                         System.out.println("OutPath = " + OutPath);
> >>>                         OutputDoc.save(OutPath);
> >>>                     }
> >>>                     OutputDoc.close();
> >>>
> >>
> >> --- original Nachricht Ende ----
> >>
> >>
> >

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-497) COSVisitorException: The handle is invalid

Posted by "Andreas Lehmkühler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-497?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12737027#action_12737027 ] 

Andreas Lehmkühler commented on PDFBOX-497:
-------------------------------------------

Alan,

thanks for your feedback. 

The problem is that copyPage() doesn't really copy all the data, it just uses references to them. If the source doc is closed before the target doc is saved some of these references get lost and the described exception is thrown. If we want to change that behaviour we have to improve the copy mechanism to really copy the whole content of a page. AFAIK the code of the importPage method already copies all data, but the other 4 findXXX methods are just returning references and not a copy of the data.

I'm afraid that the pdfbox documentation is as complete and up-to-date as many other project documentations all over the world. ;-))



> COSVisitorException: The handle is invalid
> ------------------------------------------
>
>                 Key: PDFBOX-497
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-497
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>         Environment: Windows Vista
>            Reporter: James A. Thomas
>             Fix For: 0.8.0-incubator
>
>
>     If I save a PDF document in a method of an application class, I get a COSVisitorException: The handle is invalid.  
> -------------------------------------------------------------------------------------------------- 
>        I found that I no longer get this exception if I do not close the 
> PDDocument "DrawingDoc" in the method "addDrawing".
>         However, I do get a warning:
> java.lang.Throwable: Warning: You did not close the PDF Document
>         at org.apache.pdfbox.cos.COSDocument.finalize(COSDocument.java:391)
>         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)
>                                             Alan
> --------------------------------------------------
> From: "Alan Thomas" <ja...@verizon.net>
> Sent: Monday, July 27, 2009 6:13 AM
> To: <pd...@incubator.apache.org>
> Subject: Re: COSVisitorException: The handle is invalid
> > It was created by adding pages from other PDF documents, like below.
> >
> > Is there anything wrong with returning a PDDocument from the method 
> > addDrawing like I am doing?
> >
> > 
> > Alan
> >
> > PDDocument OutputDoc = null;
> > . . .
> >
> > OutputDoc = new PDDocument();
> > . . .
> > copyPage(OutputDoc, page);
> > . . .
> > OutputDoc = addDrawing(OutputDoc,
> >                                DrawingsDir.getName(), Barcode);
> > . . .
> >            finally
> >            {
> >                try
> >                {
> >                    // Save and close the output file
> >                    if (OutputDoc != null)
> >                    {
> >                        System.out.println("OutPath = " + OutPath);
> >                        OutputDoc.save(OutPath);
> >                    }
> >                    OutputDoc.close();
> > . . .
> >
> > using these methods I created:
> >
> >    private void copyPage( PDDocument doc, PDPage page) throws Exception
> >    {
> >        PDPage imported = doc.importPage(page);
> >        imported.setCropBox(page.findCropBox());
> >        imported.setMediaBox(page.findMediaBox());
> >        imported.setResources(page.findResources());
> >        imported.setRotation(page.findRotation());
> >    }
> >
> >    private PDDocument addDrawing( PDDocument OutDoc, String 
> > DrawingsDirName,
> >                                        String barcode)
> >    {
> >        PDDocument DrawingDoc = null;
> >
> >      try
> >      {
> >            .  .  .
> >          List pages = DrawingDoc.getDocumentCatalog().getAllPages();
> >
> >          for (Object obj : pages)
> >          {
> >              PDPage page = (PDPage)obj;
> >              copyPage(OutDoc, page);
> >          }
> >      }
> >      catch (Exception e)
> >      {
> >          e.printStackTrace();
> >      }
> >      finally
> >      {
> >        try
> >        {
> >          DrawingDoc.close();
> >          return OutDoc;
> >        }
> >        catch (Exception e)
> >        {
> >            return OutDoc;
> >        }
> >      }
> >    }
> >
> >
> > --------------------------------------------------
> > From: "Andreas Lehmkühler" <an...@lehmi.de>
> > Sent: Monday, July 27, 2009 5:15 AM
> > To: <pd...@incubator.apache.org>
> > Subject: Re: COSVisitorException: The handle is invalid
> >
> >> Hi Alan,
> >>
> >> how did you create your pdf?
> >>
> >> BR
> >> Andreas Lehmkühler
> >>
> >> ----- original Nachricht --------
> >>
> >> Betreff: COSVisitorException: The handle is invalid
> >> Gesendet: Mo, 27. Jul 2009
> >> Von: Alan Thomas<ja...@verizon.net>
> >>
> >>> Hi.  When I save a PDF document in my application, I get a
> >>> COSVisitorException: "The handle is invalid".
> >>>
> >>>         However, I do not see anything wrong with it.  I show the error, 
> >>> the
> >>> string I am giving the PDDocument.save() method, and the code that 
> >>> attempts
> >>> to save the file.
> >>>
> >>>         Any idea what I am doing wrong?                Thanks, Alan
> >>>
> >>> OutPath = C:\Users\Alan\Documents\My Stuff\X Y Z Stuff\Application\Java 
> >>> App
> >>> Test\New Folder\InsertedPages 2.pdf
> >>>
> >>> org.apache.pdfbox.exceptions.COSVisitorException: The handle is invalid
> >>>         at
> >>> org.apache.pdfbox.pdfwriter.COSWriter.visitFromStream(COSWriter.java:939)
> >>>         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:768)
> >>>         at 
> >>> org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:361)
> >>>         at 
> >>> org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1070)
> >>>         at 
> >>> org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:787)
> >>>         at 
> >>> org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:768)
> >>>
> >>>
> >>>                     // Save and close the output file
> >>>                     if (OutputDoc != null)
> >>>                     {
> >>>                         System.out.println("OutPath = " + OutPath);
> >>>                         OutputDoc.save(OutPath);
> >>>                     }
> >>>                     OutputDoc.close();
> >>>
> >>
> >> --- original Nachricht Ende ----
> >>
> >>
> >

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.