List of usage examples for com.lowagie.text.pdf PdfAnnotation createText
public static PdfAnnotation createText(PdfWriter writer, Rectangle rect, String title, String contents, boolean open, String icon)
From source file:classroom.newspaper_b.Newspaper08.java
public static void main(String[] args) { try {/* w w w.j a va 2 s. c o m*/ PdfReader reader = new PdfReader(NEWSPAPER); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PdfAnnotation annotation1 = PdfAnnotation.createText(stamper.getWriter(), new Rectangle(LLX1, LLY1, URX1, URY1), "Advertisement 1", MESSAGE, false, "Insert"); PdfAppearance ap = stamper.getOverContent(1).createAppearance(W1, H1); ap.setRGBColorStroke(0xFF, 0x00, 0x00); ap.setLineWidth(3); ap.moveTo(0, 0); ap.lineTo(W1, H1); ap.moveTo(W1, 0); ap.lineTo(0, H1); ap.stroke(); annotation1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, ap); stamper.addAnnotation(annotation1, 1); PdfAnnotation annotation2 = PdfAnnotation.createText(stamper.getWriter(), new Rectangle(LLX2, LLY2, URX2, URY2), "Advertisement 2", MESSAGE, true, "Insert"); annotation2.put(PdfName.C, new PdfArray(new float[] { 0, 0, 1 })); stamper.addAnnotation(annotation2, 1); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:classroom.newspaper_b.Newspaper09.java
public static void main(String[] args) { try {/*ww w. j a v a2s .c o m*/ PdfReader reader = new PdfReader(NEWSPAPER); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PdfAnnotation annotation1 = PdfAnnotation.createSquareCircle(stamper.getWriter(), new Rectangle(LLX1, LLY1, URX1, URY1), MESSAGE, true); annotation1.put(PdfName.T, new PdfString("Advertisement 1")); annotation1.put(PdfName.C, new PdfArray(new float[] { 1, 0, 0 })); stamper.addAnnotation(annotation1, 1); PdfAnnotation annotation2 = PdfAnnotation.createText(stamper.getWriter(), new Rectangle(LLX2, LLY2, URX2, URY2), "Advertisement 2", MESSAGE, false, null); annotation2.put(PdfName.NM, new PdfString("ad2")); // the text must be read only, and the annotation set to NOVIEW annotation2.put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_READONLY | PdfAnnotation.FLAGS_NOVIEW)); // we create a popup annotation that will define where the rectangle will appear PdfAnnotation popup = PdfAnnotation.createPopup(stamper.getWriter(), new Rectangle(LLX2 + 50, LLY2 + 120, URX2 - 80, URY2 - 120), null, false); // we add a reference to the text annotation to the popup annotation popup.put(PdfName.PARENT, annotation2.getIndirectReference()); // we add a reference to the popup annotation to the text annotation annotation2.put(PdfName.POPUP, popup.getIndirectReference()); // we add both annotations to the writer stamper.addAnnotation(annotation2, 1); stamper.addAnnotation(popup, 1); // the text annotation can't be viewed (it's invisible) // we create a widget annotation named mywidget (it's a button field) PushbuttonField field = new PushbuttonField(stamper.getWriter(), new Rectangle(LLX2, LLY2, URX2, URY2), "button"); PdfAnnotation widget = field.getField(); PdfDictionary dict = new PdfDictionary(); // we write some javascript that makes the popup of the text annotation visible/invisible on mouse enter/exit String js1 = "var t = this.getAnnot(this.pageNum, 'ad2'); t.popupOpen = true; var w = this.getField('button'); w.setFocus();"; PdfAction enter = PdfAction.javaScript(js1, stamper.getWriter()); dict.put(PdfName.E, enter); String js2 = "var t = this.getAnnot(this.pageNum, 'ad2'); t.popupOpen = false;"; PdfAction exit = PdfAction.javaScript(js2, stamper.getWriter()); dict.put(PdfName.X, exit); // we add the javascript as additional action widget.put(PdfName.AA, dict); // we add the button field stamper.addAnnotation(widget, 1); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:org.mapfish.print.PDFCustomBlocks.java
License:Open Source License
private void addErrors(PdfWriter writer) { if (errors.size() > 0) { StringBuilder errorTxt = new StringBuilder(); for (int i = 0; i < errors.size(); i++) { Exception exception = errors.get(i); errorTxt.append(exception).append("\n"); }/*from w w w. j a v a 2 s .c om*/ errors.clear(); final Rectangle rect = new Rectangle(20f, 40f, 40f, 60f); final PdfAnnotation annotation = PdfAnnotation.createText(writer, rect, "Error", errorTxt.toString(), false, "Note"); writer.addAnnotation(annotation); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Added an annotation for errors"); } } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfLogicalPageDrawable.java
License:Open Source License
protected void drawHyperlink(final RenderNode box, final String target, final String window, final String title) { if (box.isNodeVisible(getDrawArea()) == false) { return;/* www .j av a2 s .co m*/ } final PdfAction action = createActionForLink(target); final AffineTransform affineTransform = getGraphics().getTransform(); final float translateX = (float) affineTransform.getTranslateX(); final float leftX = translateX + (float) (StrictGeomUtility.toExternalValue(box.getX())); final float rightX = translateX + (float) (StrictGeomUtility.toExternalValue(box.getX() + box.getWidth())); final float lowerY = (float) (globalHeight - StrictGeomUtility.toExternalValue(box.getY() + box.getHeight())); final float upperY = (float) (globalHeight - StrictGeomUtility.toExternalValue(box.getY())); if (action != null) { final PdfAnnotation annotation = new PdfAnnotation(writer, leftX, lowerY, rightX, upperY, action); writer.addAnnotation(annotation); } else if (StringUtils.isEmpty(title) == false) { final Rectangle rect = new Rectangle(leftX, lowerY, rightX, upperY); final PdfAnnotation commentAnnotation = PdfAnnotation.createText(writer, rect, "Tooltip", title, false, null); commentAnnotation.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, writer.getDirectContent().createAppearance(rect.getWidth(), rect.getHeight())); writer.addAnnotation(commentAnnotation); } }
From source file:questions.stamppages.RemoveAttachmentAnnotations.java
public static void createPdfWithAttachments() throws IOException, DocumentException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESOURCE)); document.open();// w ww . jav a 2 s.c om document.add(new Paragraph("page 1")); writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 780f, 120f, 800f), "This is some text", "some text".getBytes(), null, "some.txt")); writer.addAnnotation(PdfAnnotation.createText(writer, new Rectangle(100f, 750f, 120f, 770f), "Help", "This Help annotation was made with 'createText'", false, "Help")); document.newPage(); document.add(new Paragraph("page 2")); document.newPage(); document.add(new Paragraph("page 3")); PdfFileSpecification fs1 = PdfFileSpecification.fileEmbedded(writer, TXT, "caesar.txt", null); writer.addAnnotation( PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 780f, 120f, 800f), "Caesar", fs1)); PdfFileSpecification fs2 = PdfFileSpecification.fileEmbedded(writer, IMG, "1t3xt.gif", null); writer.addAnnotation( PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 750f, 120f, 770f), "1t3xt", fs2)); document.close(); }