private void writeDatabaseVersionAndDataSourceDetails(JavaInformations javaInformations) { if (!noDatabase && javaInformations.getDataBaseVersion() != null) { addCell(getString("Base_de_donnees") + ':'); addCell(javaInformations.getDataBaseVersion()); } if (javaInformations.getDataSourceDetails() != null) { addCell(getString("DataSource_jdbc") + ':'); addCell(javaInformations.getDataSourceDetails()); addCell(""); final Anchor anchor = new Anchor("DataSource reference", PdfFonts.BLUE.getFont()); anchor.setName("DataSource reference"); anchor.setReference( "http://commons.apache.org/dbcp/apidocs/org/apache/commons/dbcp/BasicDataSource.html"); currentTable.addCell(anchor); } }
protected void addImage(Image img) throws EmptyStackException { // if there is an element on the stack... Object current = stack.pop(); // ...and it's a Chapter or a Section, the Image can be // added directly if (current instanceof Chapter || current instanceof Section || current instanceof Cell) { ((TextElementArray) current).add(img); stack.push(current); return; } // ...if not, we need to to a lot of stuff else { Stack newStack = new Stack(); while (!(current instanceof Chapter || current instanceof Section || current instanceof Cell)) { newStack.push(current); if (current instanceof Anchor) { img.setAnnotation(new Annotation(0, 0, 0, 0, ((Anchor) current).getReference())); } current = stack.pop(); } ((TextElementArray) current).add(img); stack.push(current); while (!newStack.empty()) { stack.push(newStack.pop()); } return; } }
/** * Processes all actions contained in the cell. * @param element an element in the cell * @param action an action that should be coupled to the cell * @param allActions */ protected void processActions(Element element, PdfAction action, ArrayList allActions) { if (element.type() == Element.ANCHOR) { String url = ((Anchor) element).getReference(); if (url != null) { action = new PdfAction(url); } } Iterator i; switch (element.type()) { case Element.PHRASE: case Element.SECTION: case Element.ANCHOR: case Element.CHAPTER: case Element.LISTITEM: case Element.PARAGRAPH: for (i = ((ArrayList) element).iterator(); i.hasNext();) { processActions((Element) i.next(), action, allActions); } break; case Element.CHUNK: allActions.add(action); break; case Element.LIST: for (i = ((List) element).getItems().iterator(); i.hasNext();) { processActions((Element) i.next(), action, allActions); } break; default: int n = element.getChunks().size(); while (n-- > 0) allActions.add(action); break; } }
/** * Creates an Anchor object based on a list of properties. * @param attributes * @return an Anchor */ public static Anchor getAnchor(Properties attributes) { Anchor anchor = new Anchor(getPhrase(attributes)); String value; value = attributes.getProperty(ElementTags.NAME); if (value != null) { anchor.setName(value); } value = (String) attributes.remove(ElementTags.REFERENCE); if (value != null) { anchor.setReference(value); } return anchor; }
/** * Generates simple PDF, RTF and HTML files using only one Document object. */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: // we create 3 different writers that listen to the document PdfWriter pdf = PdfWriter.getInstance(document,PdfTestBase.getOutputStream("HelloWorldPdf.pdf")); RtfWriter2 rtf = RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("HelloWorldRtf.rtf")); HtmlWriter.getInstance(document, PdfTestBase.getOutputStream("HelloWorldHtml.html")); // step 3: we open the document document.open(); // step 4: we add a paragraph to the document document.add(new Paragraph("Hello World")); // we make references Anchor pdfRef = new Anchor("see Hello World in PDF."); pdfRef.setReference("./HelloWorldPdf.pdf"); Anchor rtfRef = new Anchor("see Hello World in RTF."); rtfRef.setReference("./HelloWorldRtf.rtf"); // we add the references, but only to the HTML page: pdf.pause(); rtf.pause(); document.add(pdfRef); document.add(Chunk.NEWLINE); document.add(rtfRef); pdf.resume(); rtf.resume(); // step 5: we close the document document.close(); }
/** * Demonstrates some Anchor functionality. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: PdfWriter.getInstance(document, PdfTestBase.getOutputStream("AHref.pdf")); HtmlWriter.getInstance(document, PdfTestBase.getOutputStream("AHref.html")); // step 3: we open the document document.open(); // step 4: Paragraph paragraph = new Paragraph("Please visit my "); Anchor anchor1 = new Anchor("website (external reference)", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, new Color(0, 0, 255))); anchor1.setReference("http://www.lowagie.com/iText/"); anchor1.setName("top"); paragraph.add(anchor1); paragraph.add(new Chunk(".\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")); document.add(paragraph); Anchor anchor2 = new Anchor("please jump to a local destination", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255))); anchor2.setReference("#top"); document.add(anchor2); // step 5: we close the document document.close(); }
private void addPsCommandReference() throws DocumentException { final Anchor psAnchor = new Anchor("ps command reference", PdfFonts.BLUE.getFont()); psAnchor.setName("ps command reference"); psAnchor.setReference("http://en.wikipedia.org/wiki/Ps_(Unix)"); psAnchor.setFont(PdfFonts.BLUE.getFont()); final Paragraph psParagraph = new Paragraph(); psParagraph.add(psAnchor); psParagraph.setAlignment(Element.ALIGN_RIGHT); addToDocument(psParagraph); }
private void addConfigurationReference() throws DocumentException { final Anchor ehcacheAnchor = new Anchor("Configuration reference", PdfFonts.BLUE.getFont()); ehcacheAnchor.setName("Ehcache configuration reference"); ehcacheAnchor.setReference( "http://ehcache.sourceforge.net/apidocs/net/sf/ehcache/config/CacheConfiguration.html#field_summary"); ehcacheAnchor.setFont(PdfFonts.BLUE.getFont()); final Paragraph ehcacheParagraph = new Paragraph(); ehcacheParagraph.add(ehcacheAnchor); ehcacheParagraph.setAlignment(Element.ALIGN_RIGHT); addToDocument(ehcacheParagraph); }
private void addConfigurationReference() throws DocumentException { final Anchor quartzAnchor = new Anchor("Configuration reference", PdfFonts.BLUE.getFont()); quartzAnchor.setName("Quartz configuration reference"); quartzAnchor.setReference("http://www.quartz-scheduler.org/docs/index.html"); quartzAnchor.setFont(PdfFonts.BLUE.getFont()); final Paragraph quartzParagraph = new Paragraph(); quartzParagraph.add(quartzAnchor); quartzParagraph.setAlignment(Element.ALIGN_RIGHT); addToDocument(quartzParagraph); }
/** * Generates simple PDF, RTF and HTML files using only one Document object. * * @param args * no arguments needed here */ public static void main(String[] args) { System.out.println("Hello World in PDF, RTF and HTML"); // step 1: creation of a document-object Document document = new Document(); try { // step 2: // we create 3 different writers that listen to the document PdfWriter pdf = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "HelloWorldPdf.pdf")); HtmlWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "HelloWorldHtml.html")); // step 3: we open the document document.open(); // step 4: we add a paragraph to the document document.add(new Paragraph("Hello World")); // we make references Anchor pdfRef = new Anchor("see Hello World in PDF."); pdfRef.setReference("./HelloWorldPdf.pdf"); Anchor rtfRef = new Anchor("see Hello World in RTF."); rtfRef.setReference("./HelloWorldRtf.rtf"); // we add the references, but only to the HTML page: pdf.pause(); document.add(pdfRef); document.add(Chunk.NEWLINE); document.add(rtfRef); pdf.resume(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5: we close the document document.close(); }
/** * Demonstrates some Anchor functionality. * * @param args * no arguments needed here */ public static void main(String[] args) { System.out.println("the Anchor object"); // step 1: creation of a document-object Document document = new Document(); try { // step 2: PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "AHref.pdf")); HtmlWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "AHref.html")); // step 3: we open the document document.open(); // step 4: Paragraph paragraph = new Paragraph("Please visit my "); Anchor anchor1 = new Anchor("website (external reference)", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, new Color(0, 0, 255))); anchor1.setReference("http://www.lowagie.com/iText/"); anchor1.setName("top"); paragraph.add(anchor1); paragraph.add(new Chunk(".\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")); document.add(paragraph); Anchor anchor2 = new Anchor("please jump to a local destination", FontFactory.getFont( FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255))); anchor2.setReference("#top"); document.add(anchor2); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5: we close the document document.close(); }
/** * Creates a document with Named Actions. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: HtmlWriter.getInstance(document, PdfTestBase.getOutputStream("JavaScriptAction.html")); // step 3: we add Javascript as Metadata and we open the document StringBuffer javaScriptSection = new StringBuffer(); javaScriptSection.append("\t\tfunction load() {\n"); javaScriptSection.append("\t\t alert('Page has been loaded.');\n"); javaScriptSection.append("\t\t}\n"); javaScriptSection.append("\t\tfunction unload(){\n"); javaScriptSection.append("\t\t alert('Page has been unloaded.');\n"); javaScriptSection.append("\t\t}\n"); javaScriptSection.append("\t\tfunction sayHi(){\n"); javaScriptSection.append("\t\t alert('Hi !!!');\n"); javaScriptSection.append("\t\t}"); document.add(new Header(HtmlTags.JAVASCRIPT, javaScriptSection.toString())); document.setJavaScript_onLoad("load()"); document.setJavaScript_onUnLoad("unload()"); document.open(); // step 4: we add some content Phrase phrase1 = new Phrase( "There are 3 JavaScript functions in the HTML page, load(), unload() and sayHi().\n\n" + "The first one will be called when the HTML page has been loaded by your browser.\n" + "The second one will be called when the HTML page is being unloaded,\n" + "for example when you go to another page.\n"); document.add(phrase1); // add a HTML link <A HREF="..."> Anchor anchor = new Anchor("Click here to execute the third JavaScript function."); anchor.setReference("JavaScript:sayHi()"); document.add(anchor); // step 5: we close the document document.close(); }
/** * Add all registered players to the document * * @throws DocumentException * When the data can not be added to the document */ public void addRegisteredPlayers() throws DocumentException { /* Add a section for the players */ Anchor playerAnchor = new Anchor(PreferencesManager.getInstance() .localizeString("pdfoutput.players.title"), PDFExporter.BIG_HEADER_FONT); playerAnchor.setName(PreferencesManager.getInstance().localizeString( "pdfoutput.players.title")); Chapter playerChapter = new Chapter(new Paragraph(playerAnchor), this.chapterNumber); playerChapter.add(Chunk.NEWLINE); for (Player player : this.event.getRegisteredPlayers()) { String[][] playerAttributes = { { "Name", player.getFirstName() + " " + player.getLastName() }, { "Nickname", player.getNickName() }, { "Mail", player.getMailAddress() }, { "Starting number", player.getStartingNumber() } }; for (String[] attribute : playerAttributes) { if (attribute[1].equals("")) { if (attribute[0].equals("Starting number")) { playerChapter.add(new Paragraph(PreferencesManager .getInstance().localizeString( "pdfoutput.players.nostartingnumber"), PDFExporter.TEXT_FONT)); } else if (attribute[0].equals("Name")) { playerChapter.add(new Paragraph(PreferencesManager .getInstance().localizeString( "pdfoutput.players.noname"), PDFExporter.SMALL_BOLD)); } } else { if (attribute[0].equals("Name")) { playerChapter.add(new Paragraph(attribute[1], PDFExporter.SMALL_BOLD)); } else if (attribute[0].equals("Starting number")) { playerChapter.add(new Paragraph(PreferencesManager .getInstance().localizeString( "pdfoutput.players.startingnumber") + " " + attribute[1], PDFExporter.TEXT_FONT)); } else { playerChapter.add(new Paragraph(attribute[1], PDFExporter.TEXT_FONT)); } } } if (player.hasPayed()) { playerChapter.add(new Paragraph(PreferencesManager .getInstance().localizeString( "pdfoutput.players.payed.true"), PDFExporter.TEXT_FONT)); } else { playerChapter.add(new Paragraph(PreferencesManager .getInstance().localizeString( "pdfoutput.players.payed.false"), PDFExporter.TEXT_FONT)); } if (player.isDisqualified()) { playerChapter.add(new Paragraph(PreferencesManager .getInstance().localizeString( "pdfoutput.players.disqualified.true"), PDFExporter.TEXT_FONT)); } playerChapter.add(Chunk.NEWLINE); } this.chapterNumber++; this.document.add(playerChapter); }
/** * Constructs a RtfAnchor based on a RtfField * * @param doc The RtfDocument this RtfAnchor belongs to * @param anchor The Anchor this RtfAnchor is based on */ public RtfAnchor(RtfDocument doc, Anchor anchor) { super(doc); this.url = anchor.getReference(); this.content = new RtfPhrase(doc, anchor); }