PdfDictionary pageDict = myReader.getPageN(1); PdfArray annots = pageDict.getAsArray(PdfName.ANNOTS); ArrayList<String> dests = new ArrayList<String>(); if (annots != null) { for (int i = 0; i < annots.size(); ++i) { PdfDictionary annotDict = annots.getAsDict(i); PdfName subType = annotDict.getAsName(PdfName.SUBTYPE); if (subType != null && PdfName.LINK.equals(subType)) { PdfDictionary action = annotDict.getAsDict(PdfName.A); if (action != null && PdfName.URI.equals(action.getAsName(PdfName.S)) { dests.add(action.getAsString(PdfName.URI).toString()); } // else { its an internal link, meh } } } }
PdfDictionary action = annotation.get(PdfName.A); if (action != null) { PdfArray d = action.getAsArray(PdfName.D); // now examine and change D }
... PdfDictionary embedded = names.getAsDict(PdfName.EMBEDDEDFILES); PdfArray filespecs = embedded.getAsArray(PdfName.NAMES); ...
@Override public double[] getFontMatrix() { if (font.getAsArray(PdfName.FONTMATRIX) != null) return font.getAsArray(PdfName.FONTMATRIX).asDoubleArray(); else return DEFAULT_FONT_MATRIX; }
@Override public double[] getFontMatrix() { if (font.getAsArray(PdfName.FONTMATRIX) != null) return font.getAsArray(PdfName.FONTMATRIX).asDoubleArray(); else return DEFAULT_FONT_MATRIX; }
/** * Gets the page from a page dictionary * @param page the page dictionary * @return the page */ public Rectangle getPageSize(final PdfDictionary page) { PdfArray mediaBox = page.getAsArray(PdfName.MEDIABOX); return getNormalizedRectangle(mediaBox); }
/** * Gets the page from a page dictionary * @param page the page dictionary * @return the page */ public Rectangle getPageSize(final PdfDictionary page) { PdfArray mediaBox = page.getAsArray(PdfName.MEDIABOX); return getNormalizedRectangle(mediaBox); }
private PdfArray getLastChildInNameTree(PdfDictionary dic) { PdfArray names; PdfArray childNode = dic.getAsArray(PdfName.KIDS); if (childNode != null) { PdfDictionary lastKid = childNode.getAsDict(childNode.size() - 1); names = getLastChildInNameTree(lastKid); } else { names = dic.getAsArray(PdfName.NAMES); } return names; }
private PdfArray getLastChildInNameTree(PdfDictionary dic) { PdfArray names; PdfArray childNode = dic.getAsArray(PdfName.KIDS); if (childNode != null) { PdfDictionary lastKid = childNode.getAsDict(childNode.size() - 1); names = getLastChildInNameTree(lastKid); } else { names = dic.getAsArray(PdfName.NAMES); } return names; }
private void addPagesFromDict(PdfObject dictRef, List<PdfDictionary> pages, List<RefKey> pagesRef) { PdfDictionary dict = (PdfDictionary)PdfReader.getPdfObject(dictRef); if (dict.isPages()) { PdfArray kids = dict.getAsArray(PdfName.KIDS); if (kids == null) return; for (PdfObject kid : kids) { addPagesFromDict(kid, pages, pagesRef); } } else if(dict.isPage()) { pages.add(dict); pagesRef.add(new RefKey((PRIndirectReference)dictRef)); } }
private void addPagesFromDict(PdfObject dictRef, List<PdfDictionary> pages, List<RefKey> pagesRef) { PdfDictionary dict = (PdfDictionary)PdfReader.getPdfObject(dictRef); if (dict.isPages()) { PdfArray kids = dict.getAsArray(PdfName.KIDS); if (kids == null) return; for (PdfObject kid : kids) { addPagesFromDict(kid, pages, pagesRef); } } else if(dict.isPage()) { pages.add(dict); pagesRef.add(new RefKey((PRIndirectReference)dictRef)); } }
@Override public void setOutputIntents(final String outputConditionIdentifier, final String outputCondition, final String registryName, final String info, final ICC_Profile colorProfile) throws IOException { super.setOutputIntents(outputConditionIdentifier, outputCondition, registryName, info, colorProfile); PdfArray a = extraCatalog.getAsArray(PdfName.OUTPUTINTENTS); if (a != null) { PdfDictionary d = a.getAsDict(0); if (d != null) { d.put(PdfName.S, PdfName.GTS_PDFA1); } } }
PdfReader reader = new PdfReader("in.pdf"); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("out.pdf")); PdfDictionary pagedict = reader.getPageN(1); PdfArray mediabox = pagedict.getAsArray(PdfName.MEDIABOX); mediabox.set(1, new PdfNumber(mediabox.getAsNumber(1).intValue()+50)); mediabox.set(3, new PdfNumber(mediabox.getAsNumber(3).intValue()+50)); stamper.close();
/** * @see PdfWriter#setOutputIntents(String, String, String, String, ICC_Profile) */ public void setOutputIntents(final String outputConditionIdentifier, final String outputCondition, final String registryName, final String info, final ICC_Profile colorProfile) throws IOException { super.setOutputIntents(outputConditionIdentifier, outputCondition, registryName, info, colorProfile); PdfArray a = extraCatalog.getAsArray(PdfName.OUTPUTINTENTS); if (a != null) { PdfDictionary d = a.getAsDict(0); if (d != null) { d.put(PdfName.S, PdfName.GTS_PDFA1); } } }
/** * @see PdfStamperImp#setOutputIntents(String, String, String, String, ICC_Profile) */ public void setOutputIntents(final String outputConditionIdentifier, final String outputCondition, final String registryName, final String info, final ICC_Profile colorProfile) throws IOException { super.setOutputIntents(outputConditionIdentifier, outputCondition, registryName, info, colorProfile); PdfArray a = extraCatalog.getAsArray(PdfName.OUTPUTINTENTS); if (a != null) { PdfDictionary d = a.getAsDict(0); if (d != null) { d.put(PdfName.S, PdfName.GTS_PDFA1); } } }
public void manipulatePdf(String src, String dest) throws IOException, DocumentException { PdfReader reader = new PdfReader(src); PdfDictionary root = reader.getCatalog(); PdfDictionary names = root.getAsDict(PdfName.NAMES); PdfDictionary embeddedFiles = names.getAsDict(PdfName.EMBEDDEDFILES); PdfArray namesArray = embeddedFiles.getAsArray(PdfName.NAMES); namesArray.remove(0); namesArray.remove(0); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); stamper.close(); }
private void fillWidths() { PdfArray newWidths = font.getAsArray(PdfName.WIDTHS); PdfNumber first = font.getAsNumber(PdfName.FIRSTCHAR); PdfNumber last = font.getAsNumber(PdfName.LASTCHAR); if (first != null && last != null && newWidths != null) { int f = first.intValue(); int nSize = f + newWidths.size(); if (widths.length < nSize) { int[] tmp = new int[nSize]; System.arraycopy(widths, 0, tmp, 0, f); widths = tmp; } for (int k = 0; k < newWidths.size(); ++k) { widths[f + k] = newWidths.getAsNumber(k).intValue(); } } }
// given the above stamper AcroFields fields = stamper.getAcroFields(); PdfDictionary replaceAnnot = fields.getFieldItem("ReplaceMe").getMerged(0); //we can remove the field from the PDF without breaking the info in replaceAnnot. fields.removeField("ReplaceMe"); // rects are laid out [llx, lly, urx, ury] PdfArray rect = replaceAnnot.getAsArray(PdfName.RECT); float x = rect.getAsNumber(0).floatValue(); float y = rect.getAsNumber(1).floatValue(); float width = rect.getAsNumber(2).floatValue() - x; float height = rect.getAsNumber(3).floatValue() - y;
protected void checkOutputIntentsInStamperMode(PdfWriter writer) { if (writer instanceof PdfAStamperImp && !isCheckOutputIntent) { PdfReader pdfReader = ((PdfAStamperImp) writer).getPdfReader(); PdfArray outPutIntentsDic = pdfReader.getCatalog().getAsArray(PdfName.OUTPUTINTENTS); if (outPutIntentsDic != null) { if (outPutIntentsDic.size() > 1) { throw new PdfAConformanceException(outPutIntentsDic, MessageLocalization.getComposedMessage("a.pdfa.file.may.have.only.one.pdfa.outputintent")); } else { PdfDictionary outPutIntentDic = outPutIntentsDic.getAsDict(0); if (outPutIntentDic != null) { checkPdfObject(writer, PdfIsoKeys.PDFISOKEY_OBJECT, outPutIntentDic); } } } } } }
protected void readFields() { catalog = trailer.getAsDict(PdfName.ROOT); PdfDictionary fdf = catalog.getAsDict(PdfName.FDF); if (fdf == null) return; PdfString fs = fdf.getAsString(PdfName.F); if (fs != null) fileSpec = fs.toUnicodeString(); PdfArray fld = fdf.getAsArray(PdfName.FIELDS); if (fld == null) return; encoding = fdf.getAsName(PdfName.ENCODING); PdfDictionary merged = new PdfDictionary(); merged.put(PdfName.KIDS, fld); kidNode(merged, ""); }