Kim A Greuling <KGreuling <at> aurorallc.com> writes:

> 
> 
> I have a JFreeChart that is successfully
> being put into a Document.  I now need to add text after the chart
> in some circumstances.  I tried adding a paragraph after writing out
> the chart but the text appears behind the chart at the top of the page.
>   How can I get the text to show up after the chart?
>          
>  PdfContentByte cb = docWriter.getDirectContent();
>          
>  PdfTemplate tp = cb.createTemplate(this.width, this.height);
>  Graphics2D g2 = tp.createGraphics(width,height, new DefaultFontMapper());
>          
>  Rectangle2D r2D = new Rectangle2D.Double(0, 0, width, height);
>          
>  chart.draw(g2, r2D, null);
>  g2.dispose();
>  cb.addTemplate(tp, 50, 150);

Here's the issue.  your this.doc has no idea that the "current location" moved
when you directly manipulate content.

Solution:  ImgTemplate.  It's a subclass of Image:

Rather than cp.addTemplate(...), your code should look something like this 
instead:

  ImgTemplate chartTemplate = new ImgTemplate( tp );
  // do something to set the location... setAbsoluteX/Y IIRC... nope:
  chartTemplate.setAbsolutePosition( 50, 150 );

  doc.add( chartTemplate );


Come to think of it, the absolute positioning thing might cause issues with the
"current location" as well.  Not really my thing.

--Mark Storer


------------------------------------------------------------------------------
Crystal Reports &#45; New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty&#45;free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to