/** * Gets an array of strings. * * @param name the attribute name * @return the array of strings */ protected String[] getArrayOfString(String name) { COSBase v = this.getCOSObject().getDictionaryObject(name); if (v instanceof COSArray) { COSArray array = (COSArray) v; String[] strings = new String[array.size()]; for (int i = 0; i < array.size(); i++) { strings[i] = ((COSName) array.getObject(i)).getName(); } return strings; } return null; }
/** * Set the RGB text color for this node. * * @param textColor The text color for this node. */ public void setTextColor( Color textColor ) { COSArray array = new COSArray(); array.add( new COSFloat( textColor.getRed()/255f)); array.add( new COSFloat( textColor.getGreen()/255f)); array.add( new COSFloat( textColor.getBlue()/255f)); getCOSObject().setItem( COSName.C, array ); }
/** * returns the COSString contained in the Recipients field at position i. * * @param i the position in the Recipients field array. * * @return a COSString object containing information about the recipient number i. */ public COSString getRecipientStringAt(int i) { COSArray array = (COSArray) dictionary.getItem(COSName.RECIPIENTS); return (COSString)array.get(i); }
/** * This will set the line ending style for the end point, see the LE_ constants for the possible values. * * @param style The new style. */ public void setEndPointEndingStyle(String style) { String actualStyle = style == null ? PDAnnotationLine.LE_NONE : style; COSArray array = (COSArray) annot.getDictionaryObject(COSName.LE); if (array == null) { array = new COSArray(); array.add(COSName.getPDFName(PDAnnotationLine.LE_NONE)); array.add(COSName.getPDFName(actualStyle)); annot.setItem(COSName.LE, array); } else { array.setName(1, actualStyle); } }
/** * This will set interior color of the drawn area. * * @param color The interior color of the circle. */ public final void setInteriorColor(Color color) { COSArray array = null; if (color != null) { float[] colors = color.getRGBColorComponents(null); array = new COSArray(); array.setFloatArray(colors); } annot.setItem(COSName.IC, array); }
/** * This will return the BlackPoint tristimulus. This is an optional field * but has defaults so this will never return null. A default of 0,0,0 will * be returned if the pdf does not have any values yet. * * @return the blackpoint tristimulus */ public final PDTristimulus getBlackPoint() { COSArray bp = (COSArray) dictionary.getDictionaryObject(COSName.BLACK_POINT); if (bp == null) { bp = new COSArray(); bp.add(new COSFloat(0.0f)); bp.add(new COSFloat(0.0f)); bp.add(new COSFloat(0.0f)); } return new PDTristimulus(bp); }
/** * (Optional) A list of array of bytes containing DER-encoded X.509v3 certificates of acceptable * issuers. If the signer’s certificate chains up to any of the specified issuers (either * directly or indirectly), the certificate is considered acceptable for signing. * * @param issuers A list of byte array containing DER-encoded X.509v3 certificates */ public void setIssuer(List<byte[]> issuers) { COSArray array = new COSArray(); for (byte[] issuer : issuers) { array.add(new COSString(issuer)); } this.dictionary.setItem(COSName.ISSUER, array); }
if (sourcePage.getResources() == null) sourcePage.setResources(resources); if (!appendContent.isOverwrite() && sourcePage.hasContents()) COSBase contents = sourcePage.getCOSObject().getDictionaryObject(COSName.CONTENTS); COSArray array; if (contents instanceof COSArray) array = new COSArray(); array.add(contents); array.add(0, stream.getCOSObject()); array.add(stream); array.add(0, prefixStream.getCOSObject()); sourcePage.getCOSObject().setItem(COSName.CONTENTS, array);
COSDictionary nextPageDict = nextPage.getCOSObject(); COSDictionary parentDict = (COSDictionary) nextPageDict.getDictionaryObject(COSName.PARENT); COSArray kids = (COSArray) parentDict.getDictionaryObject(COSName.KIDS); boolean found = false; for (int i = 0; i < kids.size(); ++i) COSDictionary pageDict = (COSDictionary) kids.getObject(i); if (pageDict.equals(nextPage.getCOSObject())) kids.add(i, newPage.getCOSObject()); newPage.getCOSObject().setItem(COSName.PARENT, parentDict); found = true; break;
COSDictionary pageDictionary = page.getCOSObject(); COSBase contents = pageDictionary.getDictionaryObject(COSName.CONTENTS); if (contents instanceof COSStream) COSArray array = new COSArray(); array.add(saveGraphicsStateStream); array.add(contentsStream); array.add(restoreGraphicsStateStream); pageDictionary.setItem(COSName.CONTENTS, array); contentsArray.add(0, saveGraphicsStateStream); contentsArray.add(restoreGraphicsStateStream);
/** * Adds the given page to this page tree. * * @param page The page to add. */ public void add(PDPage page) { // set parent COSDictionary node = page.getCOSObject(); node.setItem(COSName.PARENT, root); // todo: re-balance tree? (or at least group new pages into tree nodes of e.g. 20) // add to parent's kids COSArray kids = (COSArray)root.getDictionaryObject(COSName.KIDS); kids.add(node); // update ancestor counts do { node = (COSDictionary) node.getDictionaryObject(COSName.PARENT, COSName.P); if (node != null) { node.setInt(COSName.COUNT, node.getInt(COSName.COUNT) + 1); } } while (node != null); }
COSDictionary fdict = new COSDictionary(); fdict.setInt(COSName.FUNCTION_TYPE, 2); COSArray domain = new COSArray(); domain.add(COSInteger.get(0)); domain.add(COSInteger.get(1)); COSArray c0 = new COSArray(); c0.add(COSFloat.get("1")); c0.add(COSFloat.get("0")); c0.add(COSFloat.get("0")); COSArray c1 = new COSArray(); c1.add(COSFloat.get("0.5")); c1.add(COSFloat.get("1")); c1.add(COSFloat.get("0.5")); fdict.setItem(COSName.DOMAIN, domain); axialShading.setColorSpace(PDDeviceRGB.INSTANCE); axialShading.setShadingType(PDShading.SHADING_TYPE2); COSArray coords1 = new COSArray(); coords1.add(COSInteger.get(100)); coords1.add(COSInteger.get(400)); coords1.add(COSInteger.get(400)); coords1.add(COSInteger.get(600)); axialShading.setCoords(coords1); axialShading.setFunction(func); radialShading.setColorSpace(PDDeviceRGB.INSTANCE); radialShading.setShadingType(PDShading.SHADING_TYPE3); COSArray coords2 = new COSArray(); coords2.add(COSInteger.get(100));
/** * Returns list of maps that contains subject distinguished names like [(cn: John Doe, o: Doe), * (cn: John Smith)] both keys are typically of the form 'cn', 'o', 'email', '2.5.4.43'; and * values are text strings. */ public List<Map<String, String>> getSubjectDN() { COSBase base = this.dictionary.getDictionaryObject(COSName.SUBJECT_DN); if (base instanceof COSArray) { COSArray cosArray = (COSArray) base; List subjectDNList = cosArray.toList(); List<Map<String, String>> result = new LinkedList<>(); for (Object subjectDNItem : subjectDNList) { if (subjectDNItem instanceof COSDictionary) { COSDictionary subjectDNItemDict = (COSDictionary) subjectDNItem; Map<String, String> subjectDNMap = new HashMap<>(); for (COSName key : subjectDNItemDict.keySet()) { subjectDNMap.put(key.getName(), subjectDNItemDict.getString(key)); } result.add(subjectDNMap); } } return result; } return null; }
private PDColorSpace createColorSpace(COSBase cs) throws IOException { if (cs instanceof COSName) { return PDColorSpace.create(toLongName(cs), resources); } if (cs instanceof COSArray && ((COSArray) cs).size() > 1) { COSArray srcArray = (COSArray) cs; COSBase csType = srcArray.get(0); if (COSName.I.equals(csType) || COSName.INDEXED.equals(csType)) { COSArray dstArray = new COSArray(); dstArray.addAll(srcArray); dstArray.set(0, COSName.INDEXED); dstArray.set(1, toLongName(srcArray.get(1))); return PDColorSpace.create(dstArray, resources); } throw new IOException("Illegal type of inline image color space: " + csType); } throw new IOException("Illegal type of object for inline image color space: " + cs); }
COSBase base = getCOSObject().getDictionaryObject(COSName.BORDER); COSArray border; if (base instanceof COSArray) if (border.size() < 3) COSArray newBorder = new COSArray(); newBorder.addAll(border); border = newBorder; while (border.size() < 3) border.add(COSInteger.ZERO); border = new COSArray(); border.add(COSInteger.ZERO); border.add(COSInteger.ZERO); border.add(COSInteger.ONE);
if (array.size() > 0) COSBase page = array.getObject(0); if (page instanceof COSNumber) while (((COSDictionary) parent).getDictionaryObject(COSName.PARENT, COSName.P) != null) parent = ((COSDictionary) parent).getDictionaryObject(COSName.PARENT, COSName.P); return pages.indexOf(new PDPage((COSDictionary) page));
private int checkPagesDictionary(COSDictionary pagesDict, Set<COSObject> set) COSBase kids = pagesDict.getDictionaryObject(COSName.KIDS); int numberOfPages = 0; if (kids instanceof COSArray) List<? extends COSBase> kidsList = kidsArray.toList(); for (COSBase kid : kidsList) kidsArray.remove(kid); continue; kidsArray.remove(kid); COSName type = kidDictionary.getCOSName(COSName.TYPE); if (COSName.PAGES.equals(type)) numberOfPages += checkPagesDictionary(kidDictionary, set); else if (COSName.PAGE.equals(type)) pagesDict.setInt(COSName.COUNT, numberOfPages); return numberOfPages;