Example usage for org.apache.pdfbox.cos COSName ROLE_MAP

List of usage examples for org.apache.pdfbox.cos COSName ROLE_MAP

Introduction

In this page you can find the example usage for org.apache.pdfbox.cos COSName ROLE_MAP.

Prototype

COSName ROLE_MAP

To view the source code for org.apache.pdfbox.cos COSName ROLE_MAP.

Click Source Link

Usage

From source file:org.apache.fop.render.pdf.DocumentRootModifierTestCase.java

License:Apache License

@Test
public void testStructTreeRootEntriesToCopy() throws IOException {
    Rectangle2D r = new Rectangle2D.Double();
    PDFDocument pdfDoc = new PDFDocument("");
    PDFPage page = new PDFPage(new PDFResources(pdfDoc), 0, r, r, r, r);
    page.setObjectNumber(1);/* w  w w  . j a va 2  s  .com*/
    page.setDocument(pdfDoc);
    pdfDoc.makeStructTreeRoot(null);
    PDFStructTreeRoot structTreeRoot = pdfDoc.getRoot().getStructTreeRoot();
    PDFDictionary rootBaseRoleMap = new PDFDictionary();
    PDFBoxAdapter adapter = new PDFBoxAdapter(page, new HashMap(), new HashMap<Integer, PDFArray>());
    DocumentRootModifier modifier = new DocumentRootModifier(adapter, pdfDoc);
    COSDictionary root = new COSDictionary();
    COSDictionary mapRole = new COSDictionary();
    mapRole.setName("Icon", "Figure");
    root.setItem(COSName.ROLE_MAP, mapRole);
    modifier.structTreeRootEntriesToCopy(root);
    structTreeRoot = pdfDoc.getRoot().getStructTreeRoot();
    PDFDictionary baseRoot = (PDFDictionary) structTreeRoot.get("RoleMap");
    String test = baseRoot.get("Icon").toString();
    String expected = "/Figure";
    Assert.assertEquals(test, expected);

    PDFName para = new PDFName("P");
    rootBaseRoleMap.put("MyPara", para);
    structTreeRoot.put("RoleMap", rootBaseRoleMap);
    modifier.structTreeRootEntriesToCopy(root);
    structTreeRoot = pdfDoc.getRoot().getStructTreeRoot();
    PDFDictionary baseRoot2 = (PDFDictionary) structTreeRoot.get("RoleMap");
    PDFName nameIcon = (PDFName) baseRoot2.get("Icon");
    PDFName myPara = (PDFName) baseRoot2.get("MyPara");
    test = nameIcon.getName();
    expected = "Figure";
    Assert.assertEquals(test, expected);
    test = myPara.getName();
    expected = "P";
    Assert.assertEquals(test, expected);

    PDDocument doc = PDDocument.load(new File(getClass().getResource(CLASSMAP).getFile()));
    COSDictionary temp = (COSDictionary) doc.getDocumentCatalog().getStructureTreeRoot().getCOSObject();
    PDFDictionary classMap = new PDFDictionary();
    PDFDictionary inner = new PDFDictionary();
    inner.put("StartIndent", 0);
    classMap.put("Normal2", inner);
    structTreeRoot.put("ClassMap", classMap);
    modifier.structTreeRootEntriesToCopy(temp);
    structTreeRoot = pdfDoc.getRoot().getStructTreeRoot();
    PDFDictionary testDict = (PDFDictionary) structTreeRoot.get("ClassMap");
    Assert.assertNotNull(testDict.get("Normal2"));
}

From source file:org.apache.fop.render.pdf.pdfbox.DocumentRootModifier.java

License:Apache License

public void structTreeRootEntriesToCopy(COSDictionary structRootDict) throws IOException {
    checkForMap(structRootDict, COSName.ROLE_MAP.getName());
    checkForMap(structRootDict, "ClassMap");
}

From source file:org.apache.fop.render.pdf.pdfbox.DocumentRootModifier.java

License:Apache License

private void addMapToStructTreeRoot(PDFDictionary rootMap, PDFDictionary map, String mapName) {
    if (mapName.equals(COSName.ROLE_MAP.getName())) {
        mergeRoleMaps(rootMap, map);//from w  w  w  . jav  a2s. co m
    } else {
        mergeMapClass(rootMap, map);
    }
}

From source file:org.apache.fop.render.pdf.pdfbox.TaggedPDFConductor.java

License:Apache License

public void handleLogicalStructure(PDDocument srcDoc) throws IOException {
    if (isInputPDFTagged(srcDoc) && isStructureTreeRootNull(srcDoc)) {
        merger.setCurrentSessionElem();/*from w w w. j  a v  a2s  . co m*/
        COSDictionary strucRootDict = srcDoc.getDocumentCatalog().getStructureTreeRoot().getCOSObject();
        rootMod.structTreeRootEntriesToCopy(strucRootDict);
        if (!isParentTreeIsPresent(strucRootDict)) {
            merger.createDirectDescendants(strucRootDict, merger.currentSessionElem);
        } else {
            PageParentTreeFinder markedContentsParentFinder = new PageParentTreeFinder(srcPage);
            COSArray markedContentsParents = markedContentsParentFinder.getPageParentTreeArray(srcDoc);
            COSDictionary roleMap = (COSDictionary) strucRootDict.getDictionaryObject(COSName.ROLE_MAP);
            if (roleMap != null) {
                merger.setRoleMap(roleMap);
            }
            merger.copyStructure(markedContentsParents);
        }
    }
    configureCurrentSessionElem(srcDoc);
}