Search in sources :

Example 1 with Anchor

use of com.lowagie.text.Anchor in project javamelody by javamelody.

the class PdfCacheInformationsReport method addConfigurationReference.

private void addConfigurationReference() throws DocumentException {
    final Anchor ehcacheAnchor = new Anchor("Configuration reference", PdfFonts.BLUE.getFont());
    ehcacheAnchor.setName("Ehcache configuration reference");
    ehcacheAnchor.setReference("http://www.ehcache.org/apidocs/2.9/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);
}
Also used : Anchor(com.lowagie.text.Anchor) Paragraph(com.lowagie.text.Paragraph)

Example 2 with Anchor

use of com.lowagie.text.Anchor in project itext2 by albfernandez.

the class AHrefTest method main.

/**
 * 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();
}
Also used : Anchor(com.lowagie.text.Anchor) Color(java.awt.Color) Document(com.lowagie.text.Document) Chunk(com.lowagie.text.Chunk) Paragraph(com.lowagie.text.Paragraph) Test(org.junit.Test)

Example 3 with Anchor

use of com.lowagie.text.Anchor in project itext2 by albfernandez.

the class RtfTest method main.

/**
 * Creates 1 RTF file.
 */
@Test
public void main() throws Exception {
    Document doc = new Document();
    RtfWriter2 writer2 = RtfWriter2.getInstance(doc, PdfTestBase.getOutputStream("testNew.rtf"));
    writer2.setAutogenerateTOCEntries(true);
    Table headerTable = new Table(3);
    headerTable.addCell("Test Cell 1");
    headerTable.addCell("Test Cell 2");
    headerTable.addCell("Test Cell 3");
    HeaderFooter header = new RtfHeaderFooter(headerTable);
    RtfHeaderFooterGroup footer = new RtfHeaderFooterGroup();
    footer.setHeaderFooter(new RtfHeaderFooter(new Phrase("This is the footer on the title page")), com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_FIRST_PAGE);
    footer.setHeaderFooter(new RtfHeaderFooter(new Phrase("This is a left side page")), com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_LEFT_PAGES);
    footer.setHeaderFooter(new RtfHeaderFooter(new Phrase("This is a right side page")), com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_RIGHT_PAGES);
    doc.setHeader(header);
    doc.setFooter(footer);
    doc.open();
    Paragraph p = new Paragraph();
    p.add(new RtfTableOfContents("UPDATE ME!"));
    doc.add(p);
    p = new Paragraph("", new RtfFont("Staccato222 BT"));
    p.add(new Chunk("Hello! "));
    p.add(new Chunk("How do you do?"));
    doc.add(p);
    p.setAlignment(Element.ALIGN_RIGHT);
    doc.add(p);
    Anchor a = new Anchor("http://www.uni-klu.ac.at");
    a.setReference("http://www.uni-klu.ac.at");
    doc.add(a);
    Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR + "pngnow.png");
    doc.add(new Chunk(img, 0, 0));
    doc.add(new Annotation("Mark", "This works!"));
    Chunk c = new Chunk("");
    c.setNewPage();
    doc.add(c);
    List subList = new List(true, 40);
    subList.add(new ListItem("Sub list 1"));
    subList.add(new ListItem("Sub list 2"));
    List list = new List(true, 20);
    list.add(new ListItem("Test line 1"));
    list.add(new ListItem("Test line 2 - This is a really long test line to test that linebreaks are working the way they are supposed to work so a really really long line of drivel is required"));
    list.add(subList);
    list.add(new ListItem("Test line 3 - \t\u20ac\t 60,-"));
    doc.add(list);
    list = new List(false, 20);
    list.add(new ListItem("Bullet"));
    list.add(new ListItem("Another one"));
    doc.add(list);
    doc.newPage();
    Chapter chapter = new Chapter(new Paragraph("This is a Chapter"), 1);
    chapter.add(new Paragraph("This is some text that belongs to this chapter."));
    chapter.add(new Paragraph("A second paragraph. What a surprise."));
    Section section = chapter.addSection(new Paragraph("This is a subsection"));
    section.add(new Paragraph("Text in the subsection."));
    doc.add(chapter);
    com.lowagie.text.rtf.field.RtfTOCEntry rtfTOC = new com.lowagie.text.rtf.field.RtfTOCEntry("Table Test");
    doc.add(rtfTOC);
    Table table = new Table(3);
    table.setPadding(2);
    table.setAlignment(Element.ALIGN_LEFT);
    table.setSpacing(2);
    Cell emptyCell = new Cell("");
    Cell cellLeft = new Cell("Left Alignment");
    cellLeft.setHorizontalAlignment(Element.ALIGN_LEFT);
    Cell cellCenter = new Cell("Center Alignment");
    cellCenter.setHorizontalAlignment(Element.ALIGN_CENTER);
    Cell cellRight = new Cell("Right Alignment");
    cellRight.setHorizontalAlignment(Element.ALIGN_RIGHT);
    table.addCell(cellLeft);
    table.addCell(cellCenter);
    table.addCell(cellRight);
    Cell cellSpanHoriz = new Cell("This Cell spans two columns");
    cellSpanHoriz.setColspan(2);
    table.addCell(cellSpanHoriz);
    table.addCell(emptyCell);
    Cell cellSpanVert = new Cell("This Cell spans two rows");
    cellSpanVert.setRowspan(2);
    table.addCell(emptyCell);
    table.addCell(cellSpanVert);
    table.addCell(emptyCell);
    table.addCell(emptyCell);
    table.addCell(emptyCell);
    Cell cellSpanHorizVert = new Cell("This Cell spans both two columns and two rows");
    cellSpanHorizVert.setColspan(2);
    cellSpanHorizVert.setRowspan(2);
    table.addCell(emptyCell);
    table.addCell(cellSpanHorizVert);
    table.addCell(emptyCell);
    RtfCell cellDotted = new RtfCell("Dotted border");
    cellDotted.setBorders(new RtfBorderGroup(Rectangle.BOX, RtfBorder.BORDER_DOTTED, 1, new Color(0, 0, 0)));
    RtfCell cellEmbossed = new RtfCell("Embossed border");
    cellEmbossed.setBorders(new RtfBorderGroup(Rectangle.BOX, RtfBorder.BORDER_EMBOSS, 1, new Color(0, 0, 0)));
    RtfCell cellNoBorder = new RtfCell("No border");
    cellNoBorder.setBorders(new RtfBorderGroup());
    table.addCell(cellDotted);
    table.addCell(cellEmbossed);
    table.addCell(cellNoBorder);
    doc.add(table);
    for (int i = 0; i < 300; i++) {
        doc.add(new Paragraph("Dummy line to get multi-page document. Line " + (i + 1)));
    }
    doc.close();
}
Also used : RtfFont(com.lowagie.text.rtf.style.RtfFont) HeaderFooter(com.lowagie.text.HeaderFooter) RtfHeaderFooter(com.lowagie.text.rtf.headerfooter.RtfHeaderFooter) Document(com.lowagie.text.Document) Image(com.lowagie.text.Image) RtfHeaderFooterGroup(com.lowagie.text.rtf.headerfooter.RtfHeaderFooterGroup) List(com.lowagie.text.List) RtfCell(com.lowagie.text.rtf.table.RtfCell) Cell(com.lowagie.text.Cell) Table(com.lowagie.text.Table) RtfBorderGroup(com.lowagie.text.rtf.table.RtfBorderGroup) Color(java.awt.Color) Chapter(com.lowagie.text.Chapter) RtfCell(com.lowagie.text.rtf.table.RtfCell) Phrase(com.lowagie.text.Phrase) Chunk(com.lowagie.text.Chunk) Section(com.lowagie.text.Section) Annotation(com.lowagie.text.Annotation) Paragraph(com.lowagie.text.Paragraph) RtfHeaderFooter(com.lowagie.text.rtf.headerfooter.RtfHeaderFooter) Anchor(com.lowagie.text.Anchor) ListItem(com.lowagie.text.ListItem) RtfTableOfContents(com.lowagie.text.rtf.field.RtfTableOfContents) RtfWriter2(com.lowagie.text.rtf.RtfWriter2) Test(org.junit.Test)

Example 4 with Anchor

use of com.lowagie.text.Anchor in project itext2 by albfernandez.

the class ElementFactory method getAnchor.

/**
 * 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;
}
Also used : Anchor(com.lowagie.text.Anchor)

Example 5 with Anchor

use of com.lowagie.text.Anchor in project itext2 by albfernandez.

the class JavaScriptActionTest method main.

/**
 * 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
    StringBuilder javaScriptSection = new StringBuilder();
    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();
}
Also used : Anchor(com.lowagie.text.Anchor) Header(com.lowagie.text.Header) Phrase(com.lowagie.text.Phrase) Document(com.lowagie.text.Document) Test(org.junit.Test)

Aggregations

Anchor (com.lowagie.text.Anchor)23 Paragraph (com.lowagie.text.Paragraph)15 Phrase (com.lowagie.text.Phrase)11 Chunk (com.lowagie.text.Chunk)8 Document (com.lowagie.text.Document)7 Section (com.lowagie.text.Section)7 Annotation (com.lowagie.text.Annotation)6 Chapter (com.lowagie.text.Chapter)4 Image (com.lowagie.text.Image)4 List (com.lowagie.text.List)4 ListItem (com.lowagie.text.ListItem)4 Table (com.lowagie.text.Table)4 Test (org.junit.Test)4 Cell (com.lowagie.text.Cell)3 DocumentException (com.lowagie.text.DocumentException)3 SimpleTable (com.lowagie.text.SimpleTable)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 BadElementException (com.lowagie.text.BadElementException)2 Element (com.lowagie.text.Element)2