public static void validateNotRemoteDestination(PdfDestination destination) { if (destination instanceof PdfExplicitRemoteGoToDestination) { LoggerFactory.getLogger(PdfAction.class).warn(LogMessageConstant.INVALID_DESTINATION_TYPE); } else if (destination instanceof PdfExplicitDestination) { // No page number can be specified for a destination associated with a not remote go-to action because the // destination page is in a current PDF document. See section 12.3.2.2 of ISO 32000-1. PdfObject firstObj = ((PdfArray)destination.getPdfObject()).get(0); if (firstObj.isNumber()) { LoggerFactory.getLogger(PdfAction.class).warn(LogMessageConstant.INVALID_DESTINATION_TYPE); } } } }
/** * This methods adds new name in the Dests NameTree. It throws an exception, if the name already exists. * * @param key Name of the destination. * @param value An object destination refers to. Must be an array or a dictionary with key /D and array. * See ISO 32000-1 12.3.2.3 for more info. */ public void addNamedDestination(String key, PdfObject value) { checkClosingStatus(); if (value.isArray() && ((PdfArray)value).get(0).isNumber()) LoggerFactory.getLogger(PdfDocument.class).warn(LogMessageConstant.INVALID_DESTINATION_TYPE); catalog.addNamedDestination(key, value); }
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); }
@Override public void add(PdfObject pdfObject) { if (pdfObject.isNumber()) { add(((PdfNumber)pdfObject).floatValue()); } else if (pdfObject instanceof PdfString) { add(((PdfString)pdfObject).getValueBytes()); } }
/** * PDF 2.0. Gets halftone origin * * @return an array of two values specifying X and Y values of the halftone origin in the current coordinate system, * respectively, or <code>null</code> if halftone origin is not specified */ public float[] getHalftoneOrigin() { PdfArray hto = getPdfObject().getAsArray(PdfName.HTO); if (hto != null && hto.size() == 2 && hto.get(0).isNumber() && hto.get(1).isNumber()) { return new float[]{hto.getAsNumber(0).floatValue(), hto.getAsNumber(1).floatValue()}; } else { return null; } }
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(); } } }
for (int k = 0; k < diffs.size(); ++k) { PdfObject obj = diffs.get(k); if (obj.isNumber()) { currentNumber = ((PdfNumber) obj).intValue(); } else if (currentNumber > 255) {
if (!compareNamesExtended((PdfName) outDirectObj, (PdfName) cmpDirectObj, currentPath, compareResult)) return false; } else if (cmpDirectObj.isNumber()) { if (!compareNumbersExtended((PdfNumber) outDirectObj, (PdfNumber) cmpDirectObj, currentPath, compareResult)) return false;
int flags = 0; if (obj != null && obj.isNumber()) { flags = ((PdfNumber) obj).intValue();
/** * Concatenates the 2x3 affine transformation matrix to the current matrix * in the content stream managed by this Canvas. * If an array not containing the 6 values of the matrix is passed, * The current canvas is returned unchanged. * * @param array affine transformation stored as a PdfArray with 6 values * @return current canvas */ public PdfCanvas concatMatrix(PdfArray array) { if (array.size() != 6) { //Throw exception or warning here return this; } for (int i = 0; i < array.size(); i++) { if (!array.get(i).isNumber()) { return this; } } return concatMatrix(array.getAsNumber(0).doubleValue(), array.getAsNumber(1).doubleValue(), array.getAsNumber(2).doubleValue(), array.getAsNumber(3).doubleValue(), array.getAsNumber(4).doubleValue(), array.getAsNumber(5).doubleValue()); }
int flags = 0; if (obj != null && obj.isNumber()) { flags = ((PdfNumber) obj).intValue();
/** * Shows text (operator TJ) * * @param textArray the text array. Each element of array can be a string or a number. * If the element is a string, this operator shows the string. * If it is a number, the operator adjusts the text position by that amount. * The number is expressed in thousandths of a unit of text space. * This amount is subtracted from the current horizontal or vertical coordinate, depending on the writing mode. * @return current canvas. */ public PdfCanvas showText(PdfArray textArray) { if (currentGs.getFont() == null) throw new PdfException(PdfException.FontAndSizeMustBeSetBeforeWritingAnyText, currentGs); contentStream.getOutputStream().writeBytes(ByteUtils.getIsoBytes("[")); for (PdfObject obj : textArray) { if (obj.isString()) { StreamUtil.writeEscapedString(contentStream.getOutputStream(), ((PdfString) obj).getValueBytes()); } else if (obj.isNumber()) { contentStream.getOutputStream().writeFloat(((PdfNumber) obj).floatValue()); } } contentStream.getOutputStream().writeBytes(ByteUtils.getIsoBytes("]")); contentStream.getOutputStream().writeBytes(TJ); return this; }
private PdfMcr prepareMcrForMovingToNewParent(PdfMcr mcrKid, PdfStructElem newParent) { PdfObject mcrObject = mcrKid.getPdfObject(); PdfDictionary mcrPage = mcrKid.getPageObject(); PdfDictionary mcrDict = null; if (!mcrObject.isNumber()) { mcrDict = (PdfDictionary) mcrObject; } if (mcrDict == null || !mcrDict.containsKey(PdfName.Pg)) { if (!ensureElementPageEqualsKidPage(newParent, mcrPage)) { if (mcrDict == null) { mcrDict = new PdfDictionary(); mcrDict.put(PdfName.Type, PdfName.MCR); mcrDict.put(PdfName.MCID, mcrKid.getPdfObject()); } mcrDict.put(PdfName.Pg, mcrPage); } } if (mcrDict != null) { if (PdfName.MCR.equals(mcrDict.get(PdfName.Type))) { mcrKid = new PdfMcrDictionary(mcrDict, newParent); } else if (PdfName.OBJR.equals(mcrDict.get(PdfName.Type))) { mcrKid = new PdfObjRef(mcrDict, newParent); } } else { mcrKid = new PdfMcrNumber((PdfNumber) mcrObject, newParent); } return mcrKid; }
if (indices != null && indices.size() > 0) { for (PdfObject ind : indices) { if (!ind.isNumber()) continue; if (((PdfNumber) ind).getValue() == index) {
if (indices != null && indices.size() > 0) { for (PdfObject ind : indices) { if (!ind.isNumber()) continue; if (((PdfNumber) ind).getValue() == index) {
private static PdfObject copyObjectKid(PdfObject kid, PdfDictionary copiedParent, PdfDictionary destPage, boolean parentChangePg, StructElemCopyingParams copyingParams) { if (kid.isNumber()) { if (!parentChangePg) { copyingParams.getToDocument().getStructTreeRoot().getParentTreeHandler()