com.lowagie.text.Anchor Java Examples
The following examples show how to use
com.lowagie.text.Anchor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SAXiTextHandler.java From gcs with Mozilla Public License 2.0 | 5 votes |
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; } }
Example #2
Source File: PdfCell.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * 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; } }
Example #3
Source File: ElementFactory.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * 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; }
Example #4
Source File: SAXiTextHandler.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
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; } }
Example #5
Source File: PdfCell.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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; } }
Example #6
Source File: ElementFactory.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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; }
Example #7
Source File: HelloWorldMultipleTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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(); }
Example #8
Source File: AHrefTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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(); }
Example #9
Source File: PdfProcessInformationsReport.java From javamelody with Apache License 2.0 | 5 votes |
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); }
Example #10
Source File: PdfJavaInformationsReport.java From javamelody with Apache License 2.0 | 5 votes |
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/proper/commons-dbcp/configuration.html"); currentTable.addCell(anchor); } }
Example #11
Source File: PdfCacheInformationsReport.java From javamelody with Apache License 2.0 | 5 votes |
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); }
Example #12
Source File: PdfJobInformationsReport.java From javamelody with Apache License 2.0 | 5 votes |
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/documentation/"); quartzAnchor.setFont(PdfFonts.BLUE.getFont()); final Paragraph quartzParagraph = new Paragraph(); quartzParagraph.add(quartzAnchor); quartzParagraph.setAlignment(Element.ALIGN_RIGHT); addToDocument(quartzParagraph); }
Example #13
Source File: JavaScriptActionTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * 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(); }
Example #14
Source File: PatchRtfDocument.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
public RtfBasicElement[] mapElement( Element element ) throws DocumentException { ArrayList<RtfBasicElement> rtfElements = new ArrayList<RtfBasicElement>(); if ( element instanceof RtfBasicElement ) { RtfBasicElement rtfElement = (RtfBasicElement) element; rtfElement.setRtfDocument( rtfDoc ); return new RtfBasicElement[] { rtfElement }; } switch ( element.type() ) { case Element.CHUNK: Chunk chunk = (Chunk) element; if ( chunk.hasAttributes() ) { if ( chunk.getAttributes().containsKey( Chunk.IMAGE ) ) { rtfElements.add( new RtfImage( rtfDoc, chunk.getImage() ) ); } else if ( chunk.getAttributes().containsKey( Chunk.NEWPAGE ) ) { rtfElements.add( new RtfNewPage( rtfDoc ) ); } else if ( chunk.getAttributes().containsKey( Chunk.TAB ) ) { Float tabPos = (Float) ( (Object[]) chunk.getAttributes().get( Chunk.TAB ) )[1]; RtfTab tab = new RtfTab( tabPos.floatValue(), RtfTab.TAB_LEFT_ALIGN ); tab.setRtfDocument( rtfDoc ); rtfElements.add( tab ); rtfElements.add( new RtfChunk( rtfDoc, new Chunk( "\t" ) ) ); } else { rtfElements.add( new RtfChunk( rtfDoc, (Chunk) element ) ); } } else { rtfElements.add( new RtfChunk( rtfDoc, (Chunk) element ) ); } break; case Element.PHRASE: rtfElements.add( new RtfPhrase( rtfDoc, (Phrase) element ) ); break; case Element.PARAGRAPH: rtfElements.add( new RtfParagraph( rtfDoc, (Paragraph) element ) ); break; case Element.ANCHOR: rtfElements.add( new RtfAnchor( rtfDoc, (Anchor) element ) ); break; case Element.ANNOTATION: rtfElements.add( new RtfAnnotation( rtfDoc, (Annotation) element ) ); break; case Element.IMGRAW: case Element.IMGTEMPLATE: case Element.JPEG: rtfElements.add( new RtfImage( rtfDoc, (Image) element ) ); break; case Element.AUTHOR: case Element.SUBJECT: case Element.KEYWORDS: case Element.TITLE: case Element.PRODUCER: case Element.CREATIONDATE: rtfElements.add( new RtfInfoElement( rtfDoc, (Meta) element ) ); break; case Element.LIST: rtfElements.add( new RtfList( rtfDoc, (List) element ) ); // TODO: Testing break; case Element.LISTITEM: rtfElements.add( new RtfListItem( rtfDoc, (ListItem) element ) ); // TODO: Testing break; case Element.SECTION: rtfElements.add( new RtfSection( rtfDoc, (Section) element ) ); break; case Element.CHAPTER: rtfElements.add( new RtfChapter( rtfDoc, (Chapter) element ) ); break; case Element.TABLE: if ( element instanceof Table ) { rtfElements.add( new PatchRtfTable( rtfDoc, (Table) element ) ); } else { rtfElements.add( new PatchRtfTable( rtfDoc, ( (SimpleTable) element ).createTable() ) ); } break; case Element.PTABLE: if ( element instanceof PdfPTable ) { rtfElements.add( new PatchRtfTable( rtfDoc, (PdfPTable) element ) ); } else { rtfElements.add( new PatchRtfTable( rtfDoc, ( (SimpleTable) element ).createTable() ) ); } break; } return rtfElements.toArray( new RtfBasicElement[rtfElements.size()] ); }
Example #15
Source File: RtfAnchor.java From itext2 with GNU Lesser General Public License v3.0 | 2 votes |
/** * 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); }