List of usage examples for org.apache.pdfbox.cos COSName OBJ
COSName OBJ
To view the source code for org.apache.pdfbox.cos COSName OBJ.
Click Source Link
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 ww . j av a 2 s . c o m 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.StructureTreeMergerTestCase.java
License:Apache License
@Test public void testCheckNullCOSObject() throws IOException { setUp();/*from www .j a v a 2 s. com*/ PDDocument doc = PDDocument.load(new File(getClass().getResource(BrokenLink).getFile())); PDPage srcPage = doc.getPage(0); PageParentTreeFinder finder = new PageParentTreeFinder(srcPage); COSArray markedContentParents = finder.getPageParentTreeArray(doc); COSObject nullObj = new COSObject(null); nullObj.setObjectNumber(100); nullObj.setGenerationNumber(0); PDFStructElem elem = new PDFStructElem(); elem.setObjectNumber(2); COSObject parent = (COSObject) markedContentParents.get(1); COSArray kids = (COSArray) parent.getDictionaryObject(COSName.K); COSDictionary kid = (COSDictionary) kids.get(1); kid.setItem(COSName.OBJ, nullObj); adapter = new PDFBoxAdapter(pdfPage, new HashMap(), new HashMap<Integer, PDFArray>()); PDFLogicalStructureHandler handler = setUpPDFLogicalStructureHandler(); StructureTreeMerger merger = new StructureTreeMerger(elem, handler, adapter, srcPage); merger.copyStructure(markedContentParents); PDFArray array = handler.getPageParentTree(); PDFStructElem parentElem = (PDFStructElem) array.get(1); PDFDictionary objrDict = (PDFDictionary) parentElem.getKids().get(1); Assert.assertNull(objrDict.get("Obj")); }