Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-4540

COSWriter sometimes retrieves wrong ObjectKey

    XMLWordPrintableJSON

Details

    • Patch

    Description

      If a COSBase is directly embedded in a COSObject, it should not be assigned a new object number by the writer. We suggest the following implementation for `COSWriter.getObjectKey(COSBase)`:

      /**
       * This will get the object key for the object.
       *
       * @param obj The object to get the key for.
       *
       * @return The object key for the object.
      */
      protected COSObjectKey getObjectKey( COSBase obj )
      {
          COSBase actual = obj;
          if( actual instanceof COSObject )
          {
              actual = ((COSObject)obj).getObject();
          }
          COSObjectKey key = null;
          key = objectKeys.get(obj);
          if( key == null && actual != null )
          {
              key = objectKeys.get(actual);
          } 
          if (key == null)
          {
              setNumber(getNumber()+1);
              key = new COSObjectKey(getNumber(),0);
              objectKeys.put(obj, key);
              if( actual != null )
              {
                  objectKeys.put(actual, key);
              }
          }
          return key;
      }
      

      Attachments

        1. sample.pdf
          54 kB
          Jonathan

        Activity

          People

            tilman Tilman Hausherr
            Rahn2 Jonathan
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: