Good afternoon.
I need to put a JFreeChart instance into a PDF document using PDFBox.

In iText it's possible to use the PdfTemplate class to directly put the chart 
inside the document (see code below):
PdfWriter writer = ...;
...
JFreeChart chart = ...;
float width  = ...;
float height = ...;
float posX = ...,
float posY = ...;
...
PdfTemplate template = writer.getDirectContent().createTemplate(width, height);
PdfGraphics2D graphics = new PdfGraphics2D(template, width, height);
Rectangle2D rectangle = new Rectangle2D.Double(0, 0, width, height);
chart.draw(graphics, rectangle);
graphics.dispose();
writer.getDirectContent().addTemplate(template, posX, posY);

All I was able to do in PDFBox is converting the chart into an image, but this 
causes a big quality loss (see code below):
PDDocument document = ..;
PDPageContentStream currentContentStream = ...;
...
JFreeChart chart = ...;
int width  = ...;
int height = ...;
float posX = ...,
float posY = ...;
...
BufferedImage bi = chart.createBufferedImage(width, height);
PDImageXObject image = LosslessFactory.createFromImage(document, bi);
currentContentStream.drawImage(image, posX, posY);

Is there a way to put the chart into the document in the same way as using 
iText?

Thank you in advance,
Fabio Vassallo


Fabio Vassallo
Product Development (CIS)

[cid:[email protected]]
Würth Phoenix S.r.l.
via Kravogl 4, 39100 Bolzano
T: +39 0471 564 116
F: +39 0471 564 122
Website<http://www.wuerth-phoenix.com/> | 
e-Mail<mailto:[email protected]> | 
Map<https://www.google.de/maps/place/Wuerth+Phoenix+S.R.L./@46.474192,11.33141,15z/data=!4m2!3m1!1s0x0:0x98a5db69edb2a02?hl=en>

[twitter-2]<https://twitter.com/WuerthPhoenix>  [wordpress-2] 
<http://www.neteye-blog.com/>   [linkedin] 
<https://www.linkedin.com/company/wuerth-phoenix>   [youtube] 
<https://www.youtube.com/user/WuerthPhoenix>   
[http://feng-shui-web.net/blog2/wp-content/uploads/2016/02/xing-icon.png] 
<https://www.xing.com/companies/w%C3%BCrthphoenixsrl>   [facebook] 
<https://www.facebook.com/wuerthphoenix>

Reply via email to