List of usage examples for com.lowagie.text.pdf PdfAction PdfAction
public PdfAction(int named)
From source file:ambit2.data.qmrf.Qmrf_Xml_Pdf.java
License:Open Source License
protected PdfPTable getAttachmentsAsTable(org.w3c.dom.Document doc, String attachments) { NodeList nodes = doc.getElementsByTagName(attachments); if (nodes.getLength() > 0) { float[] widths = { 3f, 3f }; PdfPTable table = new PdfPTable(widths); table.setWidthPercentage(100);//from ww w . ja v a2s.co m for (int i = 0; i < nodes.getLength(); i++) if (nodes.item(i) instanceof org.w3c.dom.Element) { NodeList attachment = nodes.item(i).getChildNodes(); if (attachment.getLength() == 0) ;//b.append("N/A\n"); else for (int j = 0; j < attachment.getLength(); j++) if (attachment.item(j) instanceof org.w3c.dom.Element) { org.w3c.dom.Element e = ((org.w3c.dom.Element) attachment.item(j)); Paragraph p = new Paragraph(org.apache.commons.lang.StringEscapeUtils .unescapeXml(e.getAttribute("description"))); PdfPCell cell = new PdfPCell(p); cell.setBackgroundColor(Color.white); table.addCell(cell); String c = org.apache.commons.lang.StringEscapeUtils .unescapeXml(e.getAttribute("url")); PdfAction action = new PdfAction(c); p = new Paragraph(); p.add(new Chunk(c).setAction(action)); cell = new PdfPCell(p); cell.setBackgroundColor(Color.white); table.addCell(cell); } } return table; } else return null; }
From source file:classroom.newspaper_b.Newspaper10.java
public static void main(String[] args) { try {/*from w ww. j a v a2 s . co m*/ PdfReader reader = new PdfReader(NEWSPAPER); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PushbuttonField button; Rectangle rect; rect = new Rectangle(100, 980, 700, 1000); button = new PushbuttonField(stamper.getWriter(), rect, "click"); button.setBackgroundColor(Color.ORANGE); button.setText("Click here to close window"); button.setLayout(PushbuttonField.LAYOUT_LABEL_ONLY); button.setAlignment(Element.ALIGN_RIGHT); PdfFormField menubar = button.getField(); String js = "var f1 = getField('click'); f1.display = display.hidden;" + "var f2 = getField('advertisement'); f2.display = display.hidden;"; menubar.setAction(PdfAction.javaScript(js, stamper.getWriter())); stamper.addAnnotation(menubar, 1); rect = new Rectangle(100, 500, 700, 980); button = new PushbuttonField(stamper.getWriter(), rect, "advertisement"); button.setBackgroundColor(Color.WHITE); button.setBorderColor(Color.ORANGE); button.setImage(Image.getInstance(IMG)); button.setText("Buy the book iText in Action"); button.setLayout(PushbuttonField.LAYOUT_LABEL_TOP_ICON_BOTTOM); PdfFormField advertisement = button.getField(); advertisement.setAction(new PdfAction("http://www.1t3xt.com/docs/book.php")); stamper.addAnnotation(advertisement, 1); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:nl.knaw.dans.common.lang.pdf.PdfPageLayouter.java
License:Apache License
private static Phrase createPageAction(final String caption, final int action) { return new Phrase(new Chunk(caption, AFONT).setAction(new PdfAction(action))); }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.CaseStudieSummaryPDF.java
License:Open Source License
/** * This method is used for add the main information table of project summary *//*from w w w . j a va 2 s .c om*/ private void addMainInformationTable() { String startDate, endDate; if (project.getStartDate() != null) { startDate = new SimpleDateFormat("dd-MM-yyyy").format(project.getStartDate()); } else { startDate = this.messageReturn(null); } if (project.getEndDate() != null) { endDate = new SimpleDateFormat("dd-MM-yyyy").format(project.getEndDate()); } else { endDate = this.messageReturn(null); } Paragraph cellContent; // Add content try { PdfPTable table = new PdfPTable(4); // Set table widths table.setLockedWidth(true); table.setTotalWidth(480); table.setWidths(new int[] { 3, 5, 3, 5 }); // First row cellContent = new Paragraph(this.getText("summaries.project.startDate") + "\n" + " (dd-MM-yyyy)", TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0); cellContent = new Paragraph(this.messageReturn(startDate), TABLE_BODY_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0); cellContent = new Paragraph(this.getText("summaries.project.endDate") + "\n" + " (dd-MM-yyyy)", TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0); cellContent = new Paragraph(this.messageReturn(endDate), TABLE_BODY_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0); // Second row cellContent = new Paragraph(this.getText("summaries.project.managementLiaison"), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1); cellContent = new Paragraph(this.messageReturn(project.getLiaisonInstitution().getAcronym() + " - " + project.getLiaisonInstitution().getName()), TABLE_BODY_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1); cellContent = new Paragraph(this.getText("summaries.project.contactPerson"), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1); cellContent = new Paragraph(this.messageReturn(project.getOwner().getComposedName()), TABLE_BODY_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1); // Third row cellContent = new Paragraph(this.getText("summaries.project.leadOrganization"), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0); if (project.getLeader() == null || project.getLeader().getInstitution() == null) { cellContent = new Paragraph(this.getText("summaries.project.empty"), TABLE_BODY_FONT); } else { cellContent = new Paragraph( this.messageReturn( this.messageReturn(project.getLeader().getInstitution().getComposedName())), TABLE_BODY_FONT); } this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0); cellContent = new Paragraph(this.getText("summaries.project.projectLeader"), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0); if (project.getLeaderPerson() == null || project.getLeaderPerson().getUser() == null) { cellContent = new Paragraph(this.getText("summaries.project.empty"), TABLE_BODY_FONT); } else { cellContent = new Paragraph( this.messageReturn(project.getLeaderPerson().getUser().getComposedName()), TABLE_BODY_FONT); } this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0); // Fourth row cellContent = (new Paragraph(this.getText("summaries.project.projectType"), TABLE_BODY_BOLD_FONT)); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1); cellContent = new Paragraph(this.messageReturn(project.getType().replaceAll("_", " ")), TABLE_BODY_FONT); this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1); // Fiveth row Chunk imdb = null; Font hyperLink = new Font(FontFactory.getFont("openSans", 10, Color.BLUE)); hyperLink.setStyle(Font.UNDERLINE); // -- Not Bilateral if (!project.isBilateralProject()) { cellContent = (new Paragraph(this.getText("summaries.project.detailed"), TABLE_BODY_BOLD_FONT)); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1); if (project.getWorkplanName() != null && !project.getWorkplanName().equals("")) { imdb = new Chunk(project.getWorkplanName(), hyperLink); try { imdb.setAction(new PdfAction(new URL(this.messageReturn(project.getWorkplanURL())))); } catch (MalformedURLException exp) { imdb = new Chunk(project.getWorkplanName(), TABLE_BODY_FONT); LOG.error("There is an Malformed exception in " + project.getWorkplanName()); } } else { imdb = new Chunk(this.getText("summaries.project.empty"), TABLE_BODY_FONT); } } // -- Bilateral else { cellContent = (new Paragraph(this.getText("summaries.project.ipContributions.proposal.space"), TABLE_BODY_BOLD_FONT)); this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1); if (project.getBilateralContractProposalName() != null && !project.getBilateralContractProposalName().equals("")) { imdb = new Chunk(project.getBilateralContractProposalName(), hyperLink); try { imdb.setAction(new PdfAction(new URL(this.messageReturn(project.getWorkplanURL())))); } catch (MalformedURLException exp) { imdb = new Chunk(project.getBilateralContractProposalName(), TABLE_BODY_FONT); LOG.error("There is an Malformed exception in bilateral contract: " + project.getBilateralContractProposalName()); } } else { imdb = new Chunk(this.getText("summaries.project.empty"), TABLE_BODY_FONT); } } cellContent = new Paragraph(); cellContent.add(imdb); this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1); document.add(table); document.add(Chunk.NEWLINE); } catch (DocumentException e) { LOG.error( "-- generatePdf() > There was an error adding the table with content for case study summary. ", e); } }