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

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

Introduction

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

Prototype

COSName PG

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

Click Source Link

Usage

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

License:Apache License

private void copyElemEntries(COSBase base, PDFStructElem elem) throws IOException {
    assert base instanceof COSObject;
    COSObject baseObj = (COSObject) base;
    COSDictionary baseDic = (COSDictionary) baseObj.getObject();
    COSName[] names = { COSName.TYPE, COSName.S, COSName.PG, COSName.ALT, COSName.LANG, COSName.A,
            COSName.ACTUAL_TEXT, COSName.T, COSName.E, COSName.C };
    for (COSName name : names) {
        if (baseDic.keySet().contains(name)) {
            if (name.equals(COSName.PG)) {
                elem.put(COSName.PG.getName(), targetPage.makeReference());
            } else {
                elem.put(name.getName(), adapter.cloneForNewDocument(baseDic.getItem(name)));
            }//w  ww . j  a  va 2s .c  om
        }
    }
    adapter.cacheClonedObject(base, elem);
}

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

License:Apache License

private boolean checkPageEntryInAncestorsRecursively(COSDictionary elem) {
    if (elem.containsKey(COSName.PG)) {
        COSDictionary pageDict = (COSDictionary) elem.getDictionaryObject(COSName.PG);
        return srcPage.getCOSObject() == pageDict;
    } else if (elem.containsKey(COSName.P)) {
        COSDictionary parent = (COSDictionary) elem.getDictionaryObject(COSName.P);
        return checkPageEntryInAncestorsRecursively(parent);
    } else {//from  w  w  w.  ja  v  a  2 s.  co m
        return true;
    }
}

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

License:Apache License

private boolean isElementFromSourcePage(COSDictionary mrcDict, COSDictionary parentDict) {
    if (mrcDict.containsKey(COSName.PG)) {
        COSDictionary page = (COSDictionary) mrcDict.getDictionaryObject(COSName.PG);
        return srcPage.getCOSObject() == page;
    } else {//from w  w  w. j av  a2  s .  co  m
        return checkPageEntryInAncestorsRecursively(parentDict);
    }
}

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

License:Apache License

private void createKidFromCOSDictionary(COSDictionary mcrDict, PDFStructElem parent, COSDictionary baseDict)
        throws IOException {
    Collection<COSName> exclude = Arrays.asList(COSName.PG);
    PDFReference referenceObj;/*from  w  w  w  . j av a 2 s  .c  om*/
    if (isElementFromSourcePage(mcrDict, baseDict)) {
        PDFDictionary contentItem = (PDFDictionary) adapter.cloneForNewDocument(mcrDict, mcrDict, exclude);
        if (mcrDict.keySet().contains(COSName.TYPE)) {
            String type = ((COSName) mcrDict.getDictionaryObject(COSName.TYPE)).getName();
            if (type.equals("OBJR")) {
                COSObject obj = (COSObject) mcrDict.getItem(COSName.OBJ);
                if (adapter.getCachedClone(obj) == null) {
                    referenceObj = null;
                } else {
                    referenceObj = ((PDFObject) adapter.getCachedClone(obj)).makeReference();
                }
                contentItem.put(COSName.OBJ.getName(), referenceObj);
                updateStructParentAndAddToPageParentTree(referenceObj, parent);
            } else if (type.equals("MCR")) {
                updateMCIDEntry(contentItem);
                markedContentMap.put(
                        (((PDFNumber) contentItem.get(COSName.MCID.getName())).getNumber()).intValue(), parent);
            }
        }
        if (mcrDict.keySet().contains(COSName.PG)) {
            contentItem.put(COSName.PG.getName(), targetPage.makeReference());
        } else {
            parent.put(COSName.PG.getName(), targetPage.makeReference());
        }
        parent.addKid(contentItem);
    } else {
        parent.addKid(null);
    }
}

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

License:Apache License

private void configureCurrentSessionElem(PDDocument srcDoc) {
    if (!(isInputPDFTagged(srcDoc) && isStructureTreeRootNull(srcDoc))) {
        merger.setCurrentSessionElemKid();
        merger.currentSessionElem.put(COSName.PG.getName(), targetPage.makeReference());
    } else {//from   ww w.j  a va2  s. c om
        merger.currentSessionElem.put("S", new PDFName("Div"));
        merger.currentSessionElem.remove("Alt");
    }
}