/** * Creates a link. * * @return A PdfAnnotation */ protected static PdfAnnotation createLink(PdfWriter writer, Rectangle rect, PdfName highlight) { PdfAnnotation annot = new PdfAnnotation(writer, rect); annot.put(PdfName.SUBTYPE, PdfName.LINK); if (!highlight.equals(HIGHLIGHT_INVERT)) { annot.put(PdfName.H, highlight); } return annot; }
/** * Creates an Annotation with an local destination. * * @return A PdfAnnotation */ public static PdfAnnotation createLink(PdfWriter writer, Rectangle rect, PdfName highlight, String namedDestination) { PdfAnnotation annot = createLink(writer, rect, highlight); annot.put(PdfName.DEST, new PdfString(namedDestination)); return annot; }
/** Creates a file attachment annotation. * @param writer the <CODE>PdfWriter</CODE> * @param rect the dimensions in the page of the annotation * @param contents the file description * @param fileStore an array with the file. If it's <CODE>null</CODE> * the file will be read from the disk * @param file the path to the file. It will only be used if * <CODE>fileStore</CODE> is not <CODE>null</CODE> * @param fileDisplay the actual file name stored in the pdf * @throws IOException on error * @return the annotation */ public static PdfAnnotation createFileAttachment(PdfWriter writer, Rectangle rect, String contents, byte fileStore[], String file, String fileDisplay) throws IOException { return createFileAttachment(writer, rect, contents, PdfFileSpecification.fileEmbedded(writer, file, fileDisplay, fileStore)); }
/** * Creates an Annotation with an Action. * * @return A PdfAnnotation */ public static PdfAnnotation createLink(PdfWriter writer, Rectangle rect, PdfName highlight, PdfAction action) { PdfAnnotation annot = createLink(writer, rect, highlight); annot.putEx(PdfName.A, action); return annot; }
public void setPopup(PdfAnnotation popup) { put(PdfName.POPUP, popup.getIndirectReference()); popup.put(PdfName.PARENT, getIndirectReference()); }
/** * Add some free text to the document. * * @return A PdfAnnotation */ public static PdfAnnotation createFreeText(PdfWriter writer, Rectangle rect, String contents, PdfContentByte defaultAppearance) { PdfAnnotation annot = new PdfAnnotation(writer, rect); annot.put(PdfName.SUBTYPE, PdfName.FREETEXT); annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE)); annot.setDefaultAppearanceString(defaultAppearance); return annot; }
for (int k = 0; k < annotations.size(); ++k) { PdfAnnotation dic = (PdfAnnotation)annotations.get(k); int page = dic.getPlaceInPage(); if (page > currentPage) { delayedAnnotations.add(dic); continue; if (dic.isForm()) { if (!dic.isUsed()) { HashMap templates = dic.getTemplates(); if (templates != null) acroForm.addFieldTemplates(templates); if (dic.isAnnotation()) { array.add(dic.getIndirectReference()); if (!dic.isUsed()) { PdfRectangle rect = (PdfRectangle)dic.get(PdfName.RECT); if (rect != null) { switch (rotation) { case 90: dic.put(PdfName.RECT, new PdfRectangle( pageSize.getTop() - rect.bottom(), rect.left(), break; case 180: dic.put(PdfName.RECT, new PdfRectangle( pageSize.getRight() - rect.left(), pageSize.getTop() - rect.bottom(),
/** * Creates a screen PdfAnnotation * * @return a screen PdfAnnotation */ public static PdfAnnotation createScreen(PdfWriter writer, Rectangle rect, String clipTitle, PdfFileSpecification fs, String mimeType, boolean playOnDisplay) throws IOException { PdfAnnotation ann = new PdfAnnotation(writer, rect); ann.put(PdfName.SUBTYPE, PdfName.SCREEN); ann.put(PdfName.F, new PdfNumber(FLAGS_PRINT)); ann.put(PdfName.TYPE, PdfName.ANNOT); ann.setPage(); PdfIndirectReference ref = ann.getIndirectReference(); PdfAction action = PdfAction.rendition(clipTitle, fs, mimeType, ref); PdfIndirectReference actionRef = writer.addToBody(action).getIndirectReference(); // for play on display add trigger event if (playOnDisplay) { PdfDictionary aa = new PdfDictionary(); aa.put(new PdfName("PV"), actionRef); ann.put(PdfName.AA, aa); } ann.put(PdfName.A, actionRef); return ann; }
targetArea.setBorderWidth(0); PdfAnnotation annot = new PdfAnnotation(_writer, targetArea.getLeft(), targetArea.getBottom(), targetArea.getRight(), targetArea.getTop(), action); annot.put(PdfName.SUBTYPE, PdfName.LINK); annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0)); annot.setBorder(new PdfBorderArray(0.0f, 0.0f, 0)); _writer.addAnnotation(annot); return; PdfAnnotation annot = new PdfAnnotation(_writer, targetArea.getLeft(), targetArea.getBottom(), targetArea.getRight(), targetArea.getTop(), action); annot.put(PdfName.SUBTYPE, PdfName.LINK); annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0)); annot.setBorder(new PdfBorderArray(0.0f, 0.0f, 0)); _writer.addAnnotation(annot);
/** Implements an action in an area. * @param action the <CODE>PdfAction</CODE> * @param llx the lower left x corner of the activation area * @param lly the lower left y corner of the activation area * @param urx the upper right x corner of the activation area * @param ury the upper right y corner of the activation area */ void setAction(PdfAction action, float llx, float lly, float urx, float ury) { addAnnotation(new PdfAnnotation(writer, llx, lly, urx, ury, action)); }
return; PdfAnnotation annot = PdfAnnotation.createLink( _writer, targetArea, PdfAnnotation.HIGHLIGHT_INVERT, action); annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0)); annot.setBorder(new PdfBorderArray(0.0f,0.0f,0)); _writer.addAnnotation(annot); return; PdfAnnotation annot = PdfAnnotation.createLink( _writer, targetArea, PdfAnnotation.HIGHLIGHT_INVERT, action); annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0)); annot.setBorder(new PdfBorderArray(0.0f,0.0f,0)); _writer.addAnnotation(annot);
public static PdfAnnotation convertAnnotation(PdfWriter writer, Annotation annot, Rectangle defaultRect) throws IOException { switch(annot.annotationType()) { case Annotation.URL_NET: return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction((URL) annot.attributes().get(Annotation.URL))); case Annotation.URL_AS_STRING: return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction((String) annot.attributes().get(Annotation.FILE))); case Annotation.FILE_DEST: return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction((String) annot.attributes().get(Annotation.FILE), (String) annot.attributes().get(Annotation.DESTINATION))); case Annotation.SCREEN: boolean sparams[] = (boolean[])annot.attributes().get(Annotation.PARAMETERS); else fs = PdfFileSpecification.fileExtern(writer, fname); PdfAnnotation ann = PdfAnnotation.createScreen(writer, new Rectangle(annot.llx(), annot.lly(), annot.urx(), annot.ury()), fname, fs, mimetype, sparams[1]); return ann; case Annotation.FILE_PAGE: return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction((String) annot.attributes().get(Annotation.FILE), ((Integer) annot.attributes().get(Annotation.PAGE)).intValue())); case Annotation.NAMED_DEST: return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction(((Integer) annot.attributes().get(Annotation.NAMED)).intValue())); case Annotation.LAUNCH: return new PdfAnnotation(writer, annot.llx(), annot.lly(), annot.urx(), annot.ury(), new PdfAction((String) annot.attributes().get(Annotation.APPLICATION),(String) annot.attributes().get(Annotation.PARAMETERS),(String) annot.attributes().get(Annotation.OPERATION),(String) annot.attributes().get(Annotation.DEFAULTDIR))); default: return new PdfAnnotation(writer, defaultRect.getLeft(), defaultRect.getBottom(), defaultRect.getRight(), defaultRect.getTop(), new PdfString(annot.title(), PdfObject.TEXT_UNICODE), new PdfString(annot.content(), PdfObject.TEXT_UNICODE));
public void setMKBorderColor(Color color) { if (color == null) getMK().remove(PdfName.BC); else getMK().put(PdfName.BC, getMKColor(color)); }
public PdfAnnotation(PdfWriter writer, Rectangle rect) { this.writer = writer; if (rect != null) put(PdfName.RECT, new PdfRectangle(rect)); }
public void setMKNormalCaption(String caption) { getMK().put(PdfName.CA, new PdfString(caption, PdfObject.TEXT_UNICODE)); }
return; PdfAnnotation annot = PdfAnnotation.createLink( _writer, targetArea, PdfAnnotation.HIGHLIGHT_INVERT, action); annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0)); return; PdfAnnotation annot = PdfAnnotation.createLink( _writer, targetArea, PdfAnnotation.HIGHLIGHT_INVERT, action); annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0));
/** * A Hide action hides or shows an annotation. * @param annot * @param hide * @return A Hide Action */ public static PdfAction createHide(PdfAnnotation annot, boolean hide) { return createHide(annot.getIndirectReference(), hide); }
public void manipulatePdf(String src, String dest) throws IOException, DocumentException { PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); // Here we define the location: Rectangle linkLocation = new Rectangle(320, 695, 560, 741); // here we add the actual content at this location: ColumnText ct = new ColumnText(stamper.getOverContent(1)); ct.setSimpleColumn(linkLocation); ct.addElement(new Paragraph("This is a link. Click it and you'll be forwarded to another page in this document.")); ct.go(); // now we create the link that will jump to a specific destination: PdfDestination destination = new PdfDestination(PdfDestination.FIT); PdfAnnotation link = PdfAnnotation.createLink(stamper.getWriter(), linkLocation, PdfAnnotation.HIGHLIGHT_INVERT, 3, destination); // If you don't want a border, here's where you remove it: link.setBorder(new PdfBorderArray(0, 0, 0)); // We add the link (that is the clickable area, not the text!) stamper.addAnnotation(link, 1); stamper.close(); reader.close(); }