-
1. Re: Request for PDF p:element tag
norman.richards Apr 5, 2007 6:38 PM (in response to dustismo)That's an interesting possibility. I had intended that people would extend the PDF support by creating a subclass of ITextComponent. There's a tiny bit of XML overhead required to register the tag, but otherwise it's fairly trivial amount of code.
I've gone ahead and added p:element experimentally. To use it you'll need to move the itext jar out of the war (into the ear or as an app-server library) or move your components into the WAR. Let me know if it is useful. -
2. Re: Request for PDF p:element tag
dustismo Apr 9, 2007 8:18 PM (in response to dustismo)Norman,
Many thanks for implementing this. Unfortunately it doesn't work for my purpose. I forgot that I needed access to the DocWriter in order to draw the graph onto the pdf. The element tag may end up being useful for other purposes though.
I extended ITextComponent to create a simple tag to renderer JFreeCharts. Possibly someone will find it useful.public class PdfGraph extends ITextComponent { JFreeChart graph = null; Element element = null; float height; float width; /** * */ public PdfGraph() { } public void setValue(JFreeChart graph) { this.graph = graph; } /* (non-Javadoc) * @see org.jboss.seam.pdf.ui.ITextComponent#createITextObject(javax.faces.context.FacesContext) */ @Override public void createITextObject(FacesContext context) { graph = (JFreeChart) valueBinding(context, "value", graph); height = (Float) valueBinding(context, "height", height); width = (Float) valueBinding(context, "width", width); UIDocument doc = (UIDocument)this.findITextParent(this, UIDocument.class); DocWriter writer = doc.getWriter(); if (writer instanceof PdfWriter) { try { PdfContentByte cb = ((PdfWriter)writer).getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); Graphics2D g2d = tp.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D r2d = new Rectangle2D.Double(0, 0, width, height); this.graph.draw(g2d, r2d); g2d.dispose(); this.element = new ImgTemplate(tp); } catch (Exception x) { x.printStackTrace(); } } } /* (non-Javadoc) * @see org.jboss.seam.pdf.ui.ITextComponent#getITextObject() */ @Override public Object getITextObject() { return element; } /* (non-Javadoc) * @see org.jboss.seam.pdf.ui.ITextComponent#handleAdd(java.lang.Object) */ @Override public void handleAdd(Object arg0) { throw new RuntimeException("No children allowed"); } /* (non-Javadoc) * @see org.jboss.seam.pdf.ui.ITextComponent#removeITextObject() */ @Override public void removeITextObject() { element = null; } public float getHeight() { return this.height; } public void setHeight(float height) { this.height = height; } public float getWidth() { return this.width; } public void setWidth(float width) { this.width = width; } }
thanks,
Dustin -
3. Re: Request for PDF p:element tag
norman.richards Apr 10, 2007 5:59 PM (in response to dustismo)Yes, that is the recommended way to do it. I will probably remove p:element unless someone else find it useful.
Just so you know, Seam 1.3 will have JFreeChart integration. I'd welcome feedback on what features are most useful. -
4. Re: Request for PDF p:element tag
supernovasoftware.com Apr 10, 2007 8:20 PM (in response to dustismo)I am doing the following in order to add a vector logo to my PDF documents. I had my graphics artist make the logo in vector and then save it as a PDF. I then read this PDF fragment from the classpath and then use iText to write it to an empty region of a PDF that I created using JasperReports. I wanted t do it this way so that the logo would not be distored regardless of the size or zoom of the PDF. There is a code sample below. Is this possible using Seam PDF?
InputStream in = getClass().getClassLoader().getResourceAsStream("pipetracker/model/state/type/pipetracker_paperwork_logo.pdf"); PdfReader pdfReaderLogo = new PdfReader(in); Rectangle psizeLogo = pdfReaderLogo.getPageSize(1); // step 1: creation of a document-object Document document = new Document(psize); // // step 2: we create a writer that listens to the document PdfWriter writer = PdfWriter.getInstance(document, baos2); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfImportedPage pageReport = writer.getImportedPage(pdfReader, 1); PdfImportedPage pageLogo = writer.getImportedPage(pdfReaderLogo, 1); cb.addTemplate(pageReport, 0, 0); cb.addTemplate(pageLogo, .4f, 0f, 0f, .4f, 20, 610); document.close();