/** * 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); }
/** * Returns a unique key for a new resource. */ private COSName createKey(COSName kind, String prefix) { COSDictionary dict = (COSDictionary)resources.getDictionaryObject(kind); if (dict == null) { return COSName.getPDFName(prefix + 1); } // find a unique key String key; int n = dict.keySet().size(); do { ++n; key = prefix + n; } while (dict.containsKey(key)); return COSName.getPDFName(key); }
/** * Constructor for embedding. */ public PDPageTree() { root = new COSDictionary(); root.setItem(COSName.TYPE, COSName.PAGES); root.setItem(COSName.KIDS, new COSArray()); root.setItem(COSName.COUNT, COSInteger.ZERO); document = null; }
private void increaseParents(COSDictionary parentDict) { do { int cnt = parentDict.getInt(COSName.COUNT); parentDict.setInt(COSName.COUNT, cnt + 1); parentDict = (COSDictionary) parentDict.getDictionaryObject(COSName.PARENT); } while (parentDict != null); } }
/** * Constructor. */ public PDAnnotation() { dictionary = new COSDictionary(); dictionary.setItem(COSName.TYPE, COSName.ANNOT); }
/** * 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 ); }
/** * This will retrieve the interior color of the drawn area. * * @return object representing the color. */ public Color getInteriorColor() { Color retval = null; COSArray array = (COSArray) annot.getDictionaryObject(COSName.IC); if (array != null) { float[] rgb = array.toFloatArray(); if (rgb.length >= 3) { retval = new Color(rgb[0], rgb[1], rgb[2]); } } return retval; }
/** * 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); }
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;
key = entry.getKey().getName(); object = toTreeObject(entry.getValue()); value = entry.getValue(); result = "" + ((COSFloat) nodeValue).floatValue(); String text = ((COSString) nodeValue).getString(); text = "<" + ((COSString) nodeValue).toHexString() + ">"; break; result = ((COSName) nodeValue).getName(); if (COSName.XREF.equals(dict.getCOSName(COSName.TYPE))) result = "(" + dict.size() + ")"; result = "(" + array.size() + ")";
/** * Returns a map of colorants and their associated Separation color space. * @return map of colorants to color spaces, never null. * @throws IOException If there is an error reading a color space */ public Map<String, PDSeparation> getColorants() throws IOException { Map<String,PDSeparation> actuals = new HashMap<>(); COSDictionary colorants = (COSDictionary)dictionary.getDictionaryObject(COSName.COLORANTS); if(colorants == null) { colorants = new COSDictionary(); dictionary.setItem(COSName.COLORANTS, colorants); } for(COSName name : colorants.keySet()) { COSBase value = colorants.getDictionaryObject(name); actuals.put(name.getName(), (PDSeparation)PDColorSpace.create(value)); } return new COSDictionaryMap<>(actuals, colorants); }
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);
/** * (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); }
/** * 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; }
angleCollector.getText(document); int rotation = page.getRotation(); page.setRotation(0); COSArray contents = (COSArray) page.getCOSObject().getItem(COSName.CONTENTS); contents.remove(0);
/** * This will set the horizontal offset of the caption. * * @param offset the horizontal offset of the caption */ public void setCaptionHorizontalOffset(float offset) { COSArray array = (COSArray) this.getCOSObject().getDictionaryObject(COSName.CO); if (array == null) { array = new COSArray(); array.setFloatArray(new float[] { offset, 0.f }); this.getCOSObject().setItem(COSName.CO, array); } else { array.set(0, new COSFloat(offset)); } }
/** * 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; }
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));