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

ContainsKey don't work for the Map<String, Object> returned by PDStructureTreeRoot.getRoleMap

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: 1.8.12, 2.0.1
    • Fix Version/s: 1.8.13, 2.0.2, 3.0.0 PDFBox
    • Component/s: PDModel
    • Labels:
    • Environment:
      Windows 10

      Description

      No sure if it is an expected behaviour or a bug.

      The Method PDStructureTreeRoot.getRoleMap returns a map which the key is a String (Map<String, Object>).

      However when we use map.containsKey("Header") it always return false because instead of a String it is waiting for A COSName instance.
      Then we have to use map.containsKey(COSName.getPDFName("Header"));

      In the other the method map.get("Header"); works

      Test.java
      //PDF Filte tested: 
      //http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf
      try (PDDocument document = PDDocument.load(new File("PDF32000_2008.pdf"));){
        PDStructureTreeRoot treeRoot = document.getDocumentCatalog().getStructureTreeRoot();
        Map<String, Object> roleMap = treeRoot.getRoleMap();
        //Returned map: COSDictionaryMap<K,V>
        System.out.println(roleMap.containsKey("Header"));//No work
        System.out.println(  roleMap.containsKey(COSName.getPDFName("Header")));//Works
      } catch (IOException ex) {  
        ex.printStackTrace();
      }
      

        Attachments

          Activity

            People

            • Assignee:
              lehmi Andreas Lehmkühler
              Reporter:
              carlos_forever@msn.com Carlos Cabral
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 24h
                24h
                Remaining:
                Remaining Estimate - 24h
                24h
                Logged:
                Time Spent - Not Specified
                Not Specified