The static constructor Image.getInstance(PdfTemplate) looks pretty obvious to me. An example:
PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate( width, height ); Graphics2D g2 = tp.createGraphics( width, height, new DefaultFontMapper() ); Rectangle2D r2D = new Rectangle2D.Double(0, 0, width, height ); chart.draw(g2, r2D); g2.dispose(); Image img = Image.getInstance(tp); Paulo ----- Original Message ----- From: "Stanton Fisque" <[EMAIL PROTECTED]> To: "Post all your questions about iText here" <[email protected]> Sent: Wednesday, September 06, 2006 11:08 PM Subject: Re: [iText-questions] real world image injection >I found no way to use a template that did not require direct writing to X,Y > coordinates in the document. If there is a way, it is not clear how one > would perform this. My example was meant to provide a more concrete way > to > use JFreeChart and iText together that allows the chart images to be > injected into a given flow (such as a report or marketing literature) > where > one does not know the exact layout until runtime. I would argue that > using > explicit page layout is not optimal for most real world problems, like > real > time report generation with dynamic data and user controlled layout > options. > > If there is a way to use templates that doesn't require the use of > explicit > placement, this functionality should be made more obvious then. If you > have > a good example, submit it so the rest of us can possibly use it in cases > where it would be helpful. > > == stanton > > > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Paulo > Soares > Sent: Wednesday, September 06, 2006 2:53 PM > To: Post all your questions about iText here > Subject: Re: [iText-questions] real world image injection > > You can draw the chart to a template and use that template as an image, > there's a constructor in Image for that. > > Paulo > > ----- Original Message ----- > From: "Stanton Fisque" <[EMAIL PROTECTED]> > To: "Post all your questions about iText here" > <[email protected]> > Sent: Wednesday, September 06, 2006 9:39 PM > Subject: Re: [iText-questions] real world image injection > > >> My apologies, I copied the wrong method when posting this. The Image >> construction should be as follows: >> >> >> >> com.lowagie.text.Image itextImg = com.lowagie.text.Image.getInstance( >> img, >> transColor ); >> >> >> >> _____ >> >> From: [EMAIL PROTECTED] >> [mailto:[EMAIL PROTECTED] On Behalf Of >> Stanton >> Fisque >> Sent: Wednesday, September 06, 2006 1:33 PM >> To: [email protected] >> Subject: [iText-questions] real world image injection >> >> >> >> The tutorials using images AND jfreechart are lacking because they assume >> you can place the image on the page at a given X,Y coordinate. Most real >> world layouts will not allow for this, and the graphs should be done >> "within" the document flow. >> >> >> >> This is achievable by the following: >> >> >> >> >> >> /* inject code as you will */ >> >> >> >> ByteArrayOutputStream bos = new >> ByteArrayOutputStream(); >> >> ChartUtilities.writeChartAsJPEG( bos, chart, 400, >> 300 ); >> >> >> >> Toolkit tk = Toolkit.getDefaultToolkit(); >> >> java.awt.Image img = tk.createImage( >> bos.toByteArray() ); >> >> >> >> /* we now have a valid image object */ >> >> >> >> /* later on in your code */ >> >> >> >> Paragraph p = new Paragraph(); >> >> com.lowagie.text.Image itextImg = >> com.lowagie.text.Image.getInstance( img, offsetX, offsetY ); >> >> p.add( itextImg ); >> >> document.add( p ); >> >> >> >> /* the image should now appear amid the document flow properly without >> having to resort to X,Y hardcoding */ >> >> >> >> == Stanton >> >> >> >> > > > ---------------------------------------------------------------------------- > ---- > > >> ------------------------------------------------------------------------- >> Using Tomcat but need to do more? Need to support web services, security? >> Get stuff done quickly with pre-integrated technology to make your job >> easier >> Download IBM WebSphere Application Server v.1.0.1 based on Apache >> Geronimo >> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > > ---------------------------------------------------------------------------- > ---- > > >> _______________________________________________ >> iText-questions mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/itext-questions >> > > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > iText-questions mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/itext-questions > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > iText-questions mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/itext-questions ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions
