/** * Tells you if the node contains a dictionary. * * @return true if the object is a PdfDictionary */ public boolean isDictionary() { return object.isDictionary(); }
private void checkOpenAction(PdfObject openAction) { if (openAction != null && openAction.isDictionary()) { checkAction((PdfDictionary) openAction); } }
private void checkOpenAction(PdfObject openAction) { if (openAction != null && openAction.isDictionary()) { checkAction((PdfDictionary) openAction); } }
private void ifKidIsStructElementAddToList(PdfObject kid, List<IStructureNode> kids) { if (kid.isFlushed()) { kids.add(null); } else if (kid.isDictionary() && PdfStructElem.isStructElem((PdfDictionary) kid)) { kids.add(new PdfStructElem((PdfDictionary) kid)); } } }
private PdfArray getDestArray(PdfObject obj) { if (obj == null) return null; if (obj.isArray()) return (PdfArray) obj; else if (obj.isDictionary()) { PdfArray arr = ((PdfDictionary) obj).getAsArray(PdfName.D); return arr; } return null; } }
private static boolean checkTypeOfPdfDictionary(PdfObject dictionary, PdfName expectedType) { return dictionary.isDictionary() && expectedType.equals(((PdfDictionary) dictionary).getAsName(PdfName.Type)); }
@Override public List<PdfStructureAttributes> getAttributesList() { ArrayList<PdfStructureAttributes> attributesList = new ArrayList<>(); PdfObject elemAttributesObj = getBackingElem().getAttributes(false); if (elemAttributesObj != null) { if (elemAttributesObj.isDictionary()) { attributesList.add(new PdfStructureAttributes((PdfDictionary) elemAttributesObj)); } else if (elemAttributesObj.isArray()) { PdfArray attributesArray = (PdfArray) elemAttributesObj; for (PdfObject attributeObj : attributesArray) { if (attributeObj.isDictionary()) { attributesList.add(new PdfStructureAttributes((PdfDictionary) attributeObj)); } } } } return attributesList; }
PdfDictionary getPropertiesDictionary(PdfObject operand1, PdfResources resources) { if (operand1.isDictionary()) return (PdfDictionary) operand1; PdfName dictionaryName = ((PdfName) operand1); PdfDictionary properties = resources.getResource(PdfName.Properties); if (null == properties) { Logger logger = LoggerFactory.getLogger(PdfCanvasProcessor.class); logger.warn(MessageFormatUtil.format(LogMessageConstant.PDF_REFERS_TO_NOT_EXISTING_PROPERTY_DICTIONARY, PdfName.Properties)); return null; } PdfDictionary propertiesDictionary = properties.getAsDictionary(dictionaryName); if (null == propertiesDictionary) { Logger logger = LoggerFactory.getLogger(PdfCanvasProcessor.class); logger.warn(MessageFormatUtil.format(LogMessageConstant.PDF_REFERS_TO_NOT_EXISTING_PROPERTY_DICTIONARY, dictionaryName)); return null; } return properties.getAsDictionary(dictionaryName); } }
public static PdfFileSpec wrapFileSpecObject(PdfObject fileSpecObject) { if (fileSpecObject != null) { if (fileSpecObject.isString()) { return new PdfStringFS((PdfString) fileSpecObject); } else if (fileSpecObject.isDictionary()) { return new PdfDictionaryFS((PdfDictionary) fileSpecObject); } } return null; }
public static PdfEncryptedPayload extractFrom(PdfFileSpec fileSpec) { if (fileSpec != null && fileSpec.getPdfObject().isDictionary()) { return PdfEncryptedPayload.wrap(((PdfDictionary) fileSpec.getPdfObject()).getAsDictionary(PdfName.EP)); } return null; }
@Override public PdfObject getDestinationPage(Map<String, PdfObject> names) { PdfObject firstObj = ((PdfArray)getPdfObject()).get(0); if (firstObj.isDictionary()) { PdfStructElem structElem = new PdfStructElem((PdfDictionary)firstObj); while (true) { List<IStructureNode> kids = structElem.getKids(); IStructureNode firstKid = kids.size() > 0 ? kids.get(0) : null; if (firstKid instanceof PdfMcr) { return ((PdfMcr) firstKid).getPageObject(); } else if (firstKid instanceof PdfStructElem) { structElem = (PdfStructElem) firstKid; } else { break; } } } return null; }
private boolean isKeyRefersBack(PdfDictionary dic, PdfName key) { // TODO review this method? // ignore recursive call return key.equals(PdfName.P) && (dic.get(key).isIndirectReference() || dic.get(key).isDictionary()) || key.equals(PdfName.Parent); } }
public SerializedObjectContent serializeObject(PdfObject obj) { if (!obj.isStream() && !obj.isDictionary()) { return null; } PdfIndirectReference indRef = obj.getIndirectReference(); assert indRef != null; Map<PdfIndirectReference, byte[]> serializedCache = indRef.getDocument().serializedObjectsCache; byte[] content = serializedCache.get(indRef); if (content == null) { ByteBuffer bb = new ByteBuffer(); int level = 100; try { serObject(obj, bb, level, serializedCache); } catch (SelfReferenceException e) { return null; } content = bb.toByteArray(); } return new SerializedObjectContent(content); }
private void checkSeparationCS(PdfArray separation) { if (separationColorSpaces.containsKey(separation.getAsName(0))) { boolean altCSIsTheSame; boolean tintTransformIsTheSame; PdfArray sameNameSeparation = separationColorSpaces.get(separation.getAsName(0)); PdfObject cs1 = separation.get(2); PdfObject cs2 = sameNameSeparation.get(2); altCSIsTheSame = isAltCSIsTheSame(cs1, cs2); // TODO(DEVSIX-1672) in fact need to check if objects content is equal. ISO 19005-2, 6.2.4.4 "Separation and DeviceN colour spaces": // In evaluating equivalence, the PDF objects shall be compared, rather than the computational // result of the use of those PDF objects. Compression and whether or not an object is direct or indirect shall be ignored. PdfObject f1Obj = separation.get(3); PdfObject f2Obj = sameNameSeparation.get(3); //Can be a stream or dict boolean bothAllowedType = (f1Obj.getType() == f2Obj.getType()) && (f1Obj.isDictionary() || f1Obj.isStream()); //Check if the indirect references are equal tintTransformIsTheSame = bothAllowedType && f1Obj.equals(f2Obj); if (!altCSIsTheSame || !tintTransformIsTheSame) { throw new PdfAConformanceException(PdfAConformanceException.TINT_TRANSFORM_AND_ALTERNATE_SPACE_SHALL_BE_THE_SAME_FOR_THE_ALL_SEPARATION_CS_WITH_THE_SAME_NAME); } } else { separationColorSpaces.put(separation.getAsName(0), separation); } }
private void checkSeparationCS(PdfArray separation) { if (separationColorSpaces.containsKey(separation.getAsName(0))) { boolean altCSIsTheSame; boolean tintTransformIsTheSame; PdfArray sameNameSeparation = separationColorSpaces.get(separation.getAsName(0)); PdfObject cs1 = separation.get(2); PdfObject cs2 = sameNameSeparation.get(2); altCSIsTheSame = isAltCSIsTheSame(cs1, cs2); // TODO(DEVSIX-1672) in fact need to check if objects content is equal. ISO 19005-2, 6.2.4.4 "Separation and DeviceN colour spaces": // In evaluating equivalence, the PDF objects shall be compared, rather than the computational // result of the use of those PDF objects. Compression and whether or not an object is direct or indirect shall be ignored. PdfObject f1Obj = separation.get(3); PdfObject f2Obj = sameNameSeparation.get(3); //Can be a stream or dict boolean bothAllowedType = (f1Obj.getType() == f2Obj.getType()) && (f1Obj.isDictionary() || f1Obj.isStream()); //Check if the indirect references are equal tintTransformIsTheSame = bothAllowedType && f1Obj.equals(f2Obj); if (!altCSIsTheSame || !tintTransformIsTheSame) { throw new PdfAConformanceException(PdfAConformanceException.TINT_TRANSFORM_AND_ALTERNATE_SPACE_SHALL_BE_THE_SAME_FOR_THE_ALL_SEPARATION_CS_WITH_THE_SAME_NAME); } } else { separationColorSpaces.put(separation.getAsName(0), separation); } }
/** * Creates an instance of a tree node for a PDF object. * * @param object the PDF object represented by this tree node. * @return a PdfObjectTreeNode */ public static PdfObjectTreeNode getInstance(PdfObject object) { if (object.isDictionary()) { if (PdfName.Page.equals(((PdfDictionary) object).get(PdfName.Type, false))) { return new PdfPageTreeNode((PdfDictionary) object); } else if (PdfName.Pages.equals(((PdfDictionary) object).get(PdfName.Type, false))) { return new PdfPagesTreeNode((PdfDictionary) object); } } return new PdfObjectTreeNode(object); }
public static PdfDestination makeDestination(PdfObject pdfObject) { if (pdfObject.getType() == PdfObject.STRING) { return new PdfStringDestination((PdfString) pdfObject); } else if (pdfObject.getType() == PdfObject.NAME) { return new PdfNamedDestination((PdfName) pdfObject); } else if (pdfObject.getType() == PdfObject.ARRAY) { PdfArray destArray = (PdfArray) pdfObject; if (destArray.size() == 0) { throw new IllegalArgumentException(); } else { PdfObject firstObj = destArray.get(0); // In case of explicit destination for remote go-to action this is a page number if (firstObj.isNumber()) { return new PdfExplicitRemoteGoToDestination(destArray); } // In case of explicit destination for not remote go-to action this is a page dictionary if (firstObj.isDictionary() && PdfName.Page.equals(((PdfDictionary) firstObj).getAsName(PdfName.Type))) { return new PdfExplicitDestination(destArray); } // In case of structure destination this is a struct element dictionary or a string ID. Type is not required for structure elements return new PdfStructureDestination(destArray); } } else { throw new UnsupportedOperationException(); } } }
/** * Adds an additional action to the provided {@link PdfObjectWrapper}<{@link PdfDictionary}> wrapper. * * @param wrapper the wrapper to add an additional action to * @param key a {@link PdfName} specifying the name of an additional action * @param action the {@link PdfAction} to add as an additional action */ public static void setAdditionalAction(PdfObjectWrapper<PdfDictionary> wrapper, PdfName key, PdfAction action) { PdfDictionary dic; PdfObject obj = wrapper.getPdfObject().get(PdfName.AA); if (obj != null && obj.isDictionary()) { dic = (PdfDictionary) obj; } else { dic = new PdfDictionary(); } dic.put(key, action.getPdfObject()); wrapper.getPdfObject().put(PdfName.AA, dic); wrapper.getPdfObject().setModified(); }
/** * Adds a chained action. * * @param nextAction the next action or sequence of actions that shall be performed after the current action */ public void next(PdfAction nextAction) { PdfObject currentNextAction = getPdfObject().get(PdfName.Next); if (currentNextAction == null) { put(PdfName.Next, nextAction.getPdfObject()); } else if (currentNextAction.isDictionary()) { PdfArray array = new PdfArray(currentNextAction); array.add(nextAction.getPdfObject()); put(PdfName.Next, array); } else { ((PdfArray) currentNextAction).add(nextAction.getPdfObject()); } }
public static FontEncoding createDocFontEncoding(PdfObject encoding, CMapToUnicode toUnicode) { if (encoding != null) { if (encoding.isName()) { return FontEncoding.createFontEncoding(((PdfName) encoding).getValue()); } else if (encoding.isDictionary()) { DocFontEncoding fontEncoding = new DocFontEncoding(); fontEncoding.differences = new String[256]; fillBaseEncoding(fontEncoding, ((PdfDictionary) encoding).getAsName(PdfName.BaseEncoding)); fillDifferences(fontEncoding, ((PdfDictionary) encoding).getAsArray(PdfName.Differences), toUnicode); return fontEncoding; } } if (toUnicode != null) { DocFontEncoding fontEncoding = new DocFontEncoding(); fontEncoding.differences = new String[256]; fillDifferences(fontEncoding, toUnicode); return fontEncoding; } else { return FontEncoding.createFontSpecificEncoding(); } }