/** * Gets the (direct) PdfObject at the specified index. * * @param index index of the PdfObject in the PdfArray * @return the PdfObject at the position in the PdfArray */ public PdfObject get(int index) { return get(index, true); }
private boolean isAltCSIsTheSame(PdfObject cs1, PdfObject cs2) { boolean altCSIsTheSame = false; if (cs1 instanceof PdfName) { altCSIsTheSame = cs1.equals(cs2); } else if (cs1 instanceof PdfArray && cs2 instanceof PdfArray) { // 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. altCSIsTheSame = ((PdfArray) cs1).get(0).equals(((PdfArray) cs1).get(0)); } return altCSIsTheSame; }
/** * Returns the element at the specified index as a PdfNumber. If the element isn't a PdfNumber, null is returned. * * @param index position of the element to be returned * @return the element at the index as a PdfNumber */ public PdfNumber getAsNumber(int index) { PdfObject direct = get(index, true); if (direct != null && direct.getType() == PdfObject.NUMBER) return (PdfNumber) direct; return null; }
@Override public PdfObject getDestinationPage(Map<String, PdfObject> names) { return ((PdfArray)getPdfObject()).get(0); } public static PdfExplicitRemoteGoToDestination createXYZ(int pageNum, float left, float top, float zoom) {
private void checkSeparationInsideDeviceN(PdfArray separation, PdfObject deviceNColorSpace, PdfObject deviceNTintTransform) { if (!isAltCSIsTheSame(separation.get(2), deviceNColorSpace) || !deviceNTintTransform.equals(separation.get(3))) { Logger logger = LoggerFactory.getLogger(PdfAChecker.class); logger.warn(PdfAConformanceLogMessageConstant.TINT_TRANSFORM_AND_ALTERNATE_SPACE_OF_SEPARATION_ARRAYS_IN_THE_COLORANTS_OF_DEVICE_N_SHOULD_BE_CONSISTENT_WITH_SAME_ATTRIBUTES_OF_DEVICE_N); } checkSeparationCS(separation); }
/** * Returns the element at the specified index as a PdfDictionary. If the element isn't a PdfDictionary, null is returned. * * @param index position of the element to be returned * @return the element at the index as a PdfDictionary */ public PdfDictionary getAsDictionary(int index) { PdfObject direct = get(index, true); if (direct != null && direct.getType() == PdfObject.DICTIONARY) return (PdfDictionary) direct; return null; }
/** * Returns the element at the specified index as a PdfString. If the element isn't a PdfString, null is returned. * * @param index position of the element to be returned * @return the element at the index as a PdfString */ public PdfString getAsString(int index) { PdfObject direct = get(index, true); if (direct != null && direct.getType() == PdfObject.STRING) return (PdfString) direct; return null; }
/** * Returns the element at the specified index as a PdfArray. If the element isn't a PdfArray, null is returned. * * @param index position of the element to be returned * @return the element at the index as a PdfArray */ public PdfArray getAsArray(int index) { PdfObject direct = get(index, true); if (direct != null && direct.getType() == PdfObject.ARRAY) return (PdfArray) direct; return null; }
/** * Returns the element at the specified index as a PdfStream. If the element isn't a PdfStream, null is returned. * * @param index position of the element to be returned * @return the element at the index as a PdfStream */ public PdfStream getAsStream(int index) { PdfObject direct = get(index, true); if (direct != null && direct.getType() == PdfObject.STREAM) return (PdfStream) direct; return null; }
/** * Returns the element at the specified index as a PdfName. If the element isn't a PdfName, null is returned. * * @param index position of the element to be returned * @return the element at the index as a PdfName */ public PdfName getAsName(int index) { PdfObject direct = get(index, true); if (direct != null && direct.getType() == PdfObject.NAME) return (PdfName) direct; return null; }
/** * Returns the element at the specified index as a PdfBoolean. If the element isn't a PdfBoolean, null is returned. * * @param index position of the element to be returned * @return the element at the index as a PdfBoolean */ public PdfBoolean getAsBoolean(int index) { PdfObject direct = get(index, true); if (direct != null && direct.getType() == PdfObject.BOOLEAN) return (PdfBoolean) direct; return null; }
@Override public PdfObject getDestinationPage(Map<String, PdfObject> names) { PdfArray array = (PdfArray) names.get(((PdfName)getPdfObject()).getValue()); return array != null ? array.get(0) : null; }
@Override public PdfObject getDestinationPage(Map<String, PdfObject> names) { PdfArray array = (PdfArray) names.get(((PdfString)getPdfObject()).toUnicodeString()); return array != null ? array.get(0) : null; }
private void markArrayContentToFlush(PdfArray array) { for (int i = 0; i < array.size(); i++) { markObjectToFlush(array.get(i, false)); } }
private static int removeObjectFromArray(PdfArray array, PdfObject toRemove) { int i; for (i = 0; i < array.size(); ++i) { PdfObject obj = array.get(i); if (obj == toRemove || obj == toRemove.getIndirectReference()) { array.remove(i); break; } } return i; } }
public PdfLinkAnnotation setDestination(PdfObject destination) { if (getPdfObject().containsKey(PdfName.A)) { getPdfObject().remove(PdfName.A); logger.warn(LogMessageConstant.DESTINATION_NOT_PERMITTED_WHEN_ACTION_IS_SET); } if (destination.isArray() && ((PdfArray)destination).get(0).isNumber()) LoggerFactory.getLogger(PdfLinkAnnotation.class).warn(LogMessageConstant.INVALID_DESTINATION_TYPE); return (PdfLinkAnnotation) put(PdfName.Dest, destination); }
private void serArray(PdfArray array, ByteBuffer bb, int level, Map<PdfIndirectReference, byte[]> serializedCache) throws SelfReferenceException { bb.append("$A"); if (level <= 0) return; for (int k = 0; k < array.size(); ++k) { serObject(array.get(k, false), bb, level, serializedCache); } bb.append("$\\A"); }
private int getExplicitDestinationPageNum(PdfArray explicitDest) { PdfIndirectReference pageReference = (PdfIndirectReference) explicitDest.get(0, false); PdfDocument doc = pageReference.getDocument(); for (int i = 1; i <= doc.getNumberOfPages(); ++i) { if (doc.getPage(i).getPdfObject().getIndirectReference().equals(pageReference)) return i; } throw new IllegalArgumentException("PdfLinkAnnotation comparison: Page not found."); }
protected Rectangle getRect(PdfDictionary field) { PdfArray rect = field.getAsArray(PdfName.Rect); if (rect == null) { PdfArray kids = field.getAsArray(PdfName.Kids); if (kids == null) { throw new PdfException(PdfException.WrongFormFieldAddAnnotationToTheField); } rect = ((PdfDictionary) kids.get(0)).getAsArray(PdfName.Rect); } return rect != null ? rect.toRectangle() : null; }
protected Rectangle getRect(PdfDictionary field) { PdfArray rect = field.getAsArray(PdfName.Rect); if (rect == null) { PdfArray kids = field.getAsArray(PdfName.Kids); if (kids == null) { throw new PdfException(PdfException.WrongFormFieldAddAnnotationToTheField); } rect = ((PdfDictionary) kids.get(0)).getAsArray(PdfName.Rect); } return rect != null ? rect.toRectangle() : null; }