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 } } } }
@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); } } }
/** * @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); } } }
PdfReader reader = new PdfReader(resourceStream); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("target/test-outputs/test-annotated-edited.pdf")); PdfDictionary page1 = reader.getPageNRelease(1); PdfArray annots = page1.getAsArray(PdfName.ANNOTS); for (int i = 0; i < annots.size(); i++) { PdfDictionary annot = annots.getAsDict(i); PdfString contents = annot.getAsString(PdfName.CONTENTS); if (contents != null) { String value = contents.toString(); StringBuilder builder = new StringBuilder(value); value = builder.reverse().toString(); annot.put(PdfName.CONTENTS, new PdfString(value)); annot.remove(PdfName.AP); } stamper.markUsed(annot); } stamper.close();
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; }
public void manipulatePdf(String src, String dest) throws IOException, DocumentException { PdfReader reader = new PdfReader(src); PdfDictionary page = reader.getPageN(1); PdfArray annots = page.getAsArray(PdfName.ANNOTS); PdfDictionary sticky = annots.getAsDict(0); PdfArray stickyRect = sticky.getAsArray(PdfName.RECT); PdfRectangle stickyRectangle = new PdfRectangle( stickyRect.getAsNumber(0).floatValue() - 120, stickyRect.getAsNumber(1).floatValue() -70, stickyRect.getAsNumber(2).floatValue(), stickyRect.getAsNumber(3).floatValue() - 30 ); sticky.put(PdfName.RECT, stickyRectangle); PdfDictionary popup = annots.getAsDict(1); PdfArray popupRect = popup.getAsArray(PdfName.RECT); PdfRectangle popupRectangle = new PdfRectangle( popupRect.getAsNumber(0).floatValue() - 250, popupRect.getAsNumber(1).floatValue(), popupRect.getAsNumber(2).floatValue(), popupRect.getAsNumber(3).floatValue() - 250 ); popup.put(PdfName.RECT, popupRectangle); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); stamper.close(); }
protected void kidNode(PdfDictionary merged, String name) { PdfArray kids = merged.getAsArray(PdfName.KIDS); if (kids == null || kids.isEmpty()) { if (name.length() > 0) name = name.substring(1); fields.put(name, merged); } else { merged.remove(PdfName.KIDS); for (int k = 0; k < kids.size(); ++k) { PdfDictionary dic = new PdfDictionary(); dic.merge(merged); PdfDictionary newDic = kids.getAsDict(k); PdfString t = newDic.getAsString(PdfName.T); String newName = name; if (t != null) newName += "." + t.toUnicodeString(); dic.merge(newDic); dic.remove(PdfName.T); kidNode(dic, newName); } } }
protected void kidNode(PdfDictionary merged, String name) { PdfArray kids = merged.getAsArray(PdfName.KIDS); if (kids == null || kids.isEmpty()) { if (name.length() > 0) name = name.substring(1); fields.put(name, merged); } else { merged.remove(PdfName.KIDS); for (int k = 0; k < kids.size(); ++k) { PdfDictionary dic = new PdfDictionary(); dic.merge(merged); PdfDictionary newDic = kids.getAsDict(k); PdfString t = newDic.getAsString(PdfName.T); String newName = name; if (t != null) newName += "." + t.toUnicodeString(); dic.merge(newDic); dic.remove(PdfName.T); kidNode(dic, newName); } } }
PdfReader reader = new PdfReader(resourceStream); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("target/test-outputs/test-annotated-moved.pdf")); PdfDictionary page1 = reader.getPageNRelease(1); PdfArray annots = page1.getAsArray(PdfName.ANNOTS); for (int i = 0; i < annots.size(); i++) { PdfDictionary annot = annots.getAsDict(i); PdfArray rect = annot.getAsArray(PdfName.RECT); PdfArray movedRect = new PdfArray(new float[] { rect.getAsNumber(0).floatValue() + 100f, rect.getAsNumber(1).floatValue() + 100f, rect.getAsNumber(2).floatValue() + 100f, rect.getAsNumber(3).floatValue() + 100f } ); annot.put(PdfName.RECT, movedRect); stamper.markUsed(annot); } stamper.close();
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); } } } } } }
static PdfDictionary getKDict(PdfDictionary obj) { PdfDictionary k = obj.getAsDict(PdfName.K); if (k != null) { if (PdfName.OBJR.equals(k.getAsName(PdfName.TYPE))) { return k; } } else { PdfArray k1 = obj.getAsArray(PdfName.K); if (k1 == null) return null; for (int i = 0; i < k1.size(); i++) { k = k1.getAsDict(i); if (k != null) { if (PdfName.OBJR.equals(k.getAsName(PdfName.TYPE))) { return k; } } } } return null; }
static PdfDictionary getKDict(PdfDictionary obj) { PdfDictionary k = obj.getAsDict(PdfName.K); if (k != null) { if (PdfName.OBJR.equals(k.getAsName(PdfName.TYPE))) { return k; } } else { PdfArray k1 = obj.getAsArray(PdfName.K); if (k1 == null) return null; for (int i = 0; i < k1.size(); i++) { k = k1.getAsDict(i); if (k != null) { if (PdfName.OBJR.equals(k.getAsName(PdfName.TYPE))) { return k; } } } } return null; }
if (arr == null || arr.size() == 0) return PdfSignatureAppearance.NOT_CERTIFIED; dic = arr.getAsDict(0); if (dic == null) return PdfSignatureAppearance.NOT_CERTIFIED;
if (ref != null) { for (int i = 0; i < ref.size(); i++) { PdfDictionary dict = ref.getAsDict(i); PdfDictionary params = dict.getAsDict(PdfName.TRANSFORMPARAMS); if (PdfName.DOCMDP.equals(dict.getAsName(PdfName.TRANSFORMMETHOD))) {
protected void readColorProfile() { PdfObject outputIntents = reader.getCatalog().getAsArray(PdfName.OUTPUTINTENTS); if (outputIntents != null && ((PdfArray) outputIntents).size() > 0) { PdfStream iccProfileStream = null; for (int i = 0; i < ((PdfArray) outputIntents).size(); i++) { PdfDictionary outputIntentDictionary = ((PdfArray) outputIntents).getAsDict(i); if (outputIntentDictionary != null) { iccProfileStream = outputIntentDictionary.getAsStream(PdfName.DESTOUTPUTPROFILE); if (iccProfileStream != null) break; } } if (iccProfileStream instanceof PRStream) { try { colorProfile = ICC_Profile.getInstance(PdfReader.getStreamBytes((PRStream) iccProfileStream)); } catch (IOException exc) { throw new ExceptionConverter(exc); } } } }
protected void readColorProfile() { PdfObject outputIntents = reader.getCatalog().getAsArray(PdfName.OUTPUTINTENTS); if (outputIntents != null && ((PdfArray) outputIntents).size() > 0) { PdfStream iccProfileStream = null; for (int i = 0; i < ((PdfArray) outputIntents).size(); i++) { PdfDictionary outputIntentDictionary = ((PdfArray) outputIntents).getAsDict(i); if (outputIntentDictionary != null) { iccProfileStream = outputIntentDictionary.getAsStream(PdfName.DESTOUTPUTPROFILE); if (iccProfileStream != null) break; } } if (iccProfileStream instanceof PRStream) { try { colorProfile = ICC_Profile.getInstance(PdfReader.getStreamBytes((PRStream) iccProfileStream)); } catch (IOException exc) { throw new ExceptionConverter(exc); } } } }
protected void readColorProfile() { PdfObject outputIntents = reader.getCatalog().getAsArray(PdfName.OUTPUTINTENTS); if (outputIntents != null && ((PdfArray) outputIntents).size() > 0) { PdfStream iccProfileStream = null; for (int i = 0; i < ((PdfArray) outputIntents).size(); i++) { PdfDictionary outputIntentDictionary = ((PdfArray) outputIntents).getAsDict(i); if (outputIntentDictionary != null) { PdfName gts = outputIntentDictionary.getAsName(PdfName.S); if (iccProfileStream == null || PdfName.GTS_PDFA1.equals(gts)) { iccProfileStream = outputIntentDictionary.getAsStream(PdfName.DESTOUTPUTPROFILE); if (iccProfileStream != null && PdfName.GTS_PDFA1.equals(gts)) break; } } } if (iccProfileStream instanceof PRStream) { try { colorProfile = ICC_Profile.getInstance(PdfReader.getStreamBytes((PRStream)iccProfileStream)); } catch(IOException exc) { throw new ExceptionConverter(exc); } } } }
if (outs.size() == 0) return false; PdfDictionary outa = outs.getAsDict(0); PdfObject obj = PdfReader.getPdfObject(outa.get(PdfName.S)); if (obj == null || !PdfName.GTS_PDFA1.equals(obj))