PDFBox
  1. PDFBox
  2. PDFBOX-811

EmbeddedFiles example does not work

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.1
    • Fix Version/s: 1.8.0
    • Component/s: PDModel
    • Labels:
      None
    • Environment:
      Java 1.6, Windows XP

      Description

      Running the EmbeddedFiles example does not work properly. Obviously it has stopped working with Version 1.1.0 already at least. I've tried the same example with pdfbox 0.7.3 and there it is working without any problems. Although it seems (according to the document's size) that the file is embedded, there is no entry visible in the PDF's attachment/document section ...

        Issue Links

          Activity

          Markus Horehled created issue -
          Hide
          Markus Horehled added a comment -

          Tested the EmbeddedFiles example with pdfbox version 1.5.0 and it still does not seem to work. It creates the pdf file, but it apparently does not attach any files. Any news on this!?

          Show
          Markus Horehled added a comment - Tested the EmbeddedFiles example with pdfbox version 1.5.0 and it still does not seem to work. It creates the pdf file, but it apparently does not attach any files. Any news on this!?
          Hide
          Daniel Deng added a comment -

          It is still not working on 1.6.0. I can see the attached content is actually in the output pdf file with UltraEdit. It is just not showing up in the attachment list.

          Show
          Daniel Deng added a comment - It is still not working on 1.6.0. I can see the attached content is actually in the output pdf file with UltraEdit. It is just not showing up in the attachment list.
          Hide
          Daniel Deng added a comment -

          I compared the output pdfs between version 0.7.3 and version 1.6.0. The 1.6.0 one has the following extra statement under the EmbeddedFilesNameTreeNode obj :

          /Limits [(My first attachment) (My first attachment)]

          It seems that this line is the cause of the problem. However I couldn't find any API to get rid of this line, so I copied the setNames method in org.apache.pdfbox.pdmodel.common.PDNameTreeNode and modified it to a new method :

          /**

          • A patched setName method to resolve the problem that attachment does not
          • show up on the list.
          • @param names
            */
            public void setNamesWithoutLimit( Map<String, ? extends COSObjectable> names )
            {
            if( names == null ) { node.setItem( "Names", (COSObjectable)null ); node.setItem( COSName.LIMITS, (COSObjectable)null); }

            else

            Unknown macro: { COSArray array = new COSArray(); List<String> keys = new ArrayList<String>(names.keySet()); Collections.sort(keys); for (String key }

            }

          and called this method instead of efTree.setName() in the example. It seems solve the problem and works fine in my project. But I am new to pdf so that I don't know whether it will cause any side effect.

          Show
          Daniel Deng added a comment - I compared the output pdfs between version 0.7.3 and version 1.6.0. The 1.6.0 one has the following extra statement under the EmbeddedFilesNameTreeNode obj : /Limits [(My first attachment) (My first attachment)] It seems that this line is the cause of the problem. However I couldn't find any API to get rid of this line, so I copied the setNames method in org.apache.pdfbox.pdmodel.common.PDNameTreeNode and modified it to a new method : /** A patched setName method to resolve the problem that attachment does not show up on the list. @param names */ public void setNamesWithoutLimit( Map<String, ? extends COSObjectable> names ) { if( names == null ) { node.setItem( "Names", (COSObjectable)null ); node.setItem( COSName.LIMITS, (COSObjectable)null); } else Unknown macro: { COSArray array = new COSArray(); List<String> keys = new ArrayList<String>(names.keySet()); Collections.sort(keys); for (String key } } and called this method instead of efTree.setName() in the example. It seems solve the problem and works fine in my project. But I am new to pdf so that I don't know whether it will cause any side effect.
          Hide
          Cole Ferrier added a comment -

          the other work around i found is after you call setNames on your PDEmbeddedFilesNameTreeNode

          remove the limits:

          ((COSDictionary )efTree.getCOSObject()).removeItem(COSName.LIMITS);

          ugly hack, but it works, without having to recompile pdfbox

          Show
          Cole Ferrier added a comment - the other work around i found is after you call setNames on your PDEmbeddedFilesNameTreeNode remove the limits: ((COSDictionary )efTree.getCOSObject()).removeItem(COSName.LIMITS); ugly hack, but it works, without having to recompile pdfbox
          Andreas Lehmkühler made changes -
          Field Original Value New Value
          Link This issue depends on PDFBOX-1380 [ PDFBOX-1380 ]
          Andreas Lehmkühler made changes -
          Link This issue is duplicated by PDFBOX-933 [ PDFBOX-933 ]
          Hide
          Andreas Lehmkühler added a comment -

          Works fine after solving PDFBOX-1380 and adding a new child NameTreeNode representing the embedded file in revision 1454883.

          Show
          Andreas Lehmkühler added a comment - Works fine after solving PDFBOX-1380 and adding a new child NameTreeNode representing the embedded file in revision 1454883.
          Andreas Lehmkühler made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Assignee Andreas Lehmkühler [ lehmi ]
          Fix Version/s 1.8.0 [ 12321650 ]
          Resolution Fixed [ 1 ]
          Andreas Lehmkühler made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Gavin made changes -
          Link This issue depends on PDFBOX-1380 [ PDFBOX-1380 ]
          Gavin made changes -
          Link This issue depends upon PDFBOX-1380 [ PDFBOX-1380 ]
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Resolved Resolved
          920d 6h 11m 1 Andreas Lehmkühler 10/Mar/13 17:27
          Resolved Resolved Closed Closed
          12d 19h 28m 1 Andreas Lehmkühler 23/Mar/13 12:56

            People

            • Assignee:
              Andreas Lehmkühler
              Reporter:
              Markus Horehled
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development