Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » how to use com.itextpdf.text.image to generate pdf report(vector image will not be distorted )
how to use com.itextpdf.text.image to generate pdf report [message #1046658] Mon, 22 April 2013 07:43 Go to next message
janine chang is currently offline janine changFriend
Messages: 2
Registered: April 2013
Junior Member
I have some dynamic JFreeChart charts which need to be inserted into pdf report
I used iText before. the code like the following:

private Image genJfreechartImage(PdfTemplate tp, JFreeChart chart, float width, float height)throws BadElementException, DocumentException{
Graphics2D g2d = tp.createGraphics(width / 40, height / 40, true, 0);
Rectangle2D r2d = new Rectangle2D.Double(0, 0, width, height);
AffineTransform affineTransform2 = AffineTransform.getTranslateInstance(0, 0);
affineTransform2.scale(0.025, 0.025);
g2d.transform(affineTransform2);
g2d.transform(AffineTransform.getTranslateInstance(0, 0));
chart.draw(g2d, r2d, null);
com.itextpdf.text.image img = Image.getInstance(tp);
g2d.dispose();
g2d = null;
float pageWidth = (float) (PageSize.A4.getWidth() * 0.9);
float percentage = (pageWidth / img.getWidth()) * 100;
img.scalePercent(percentage, percentage);
return img;
}


in this method, I got the vector image in pdf which will not be distorted after zoom in, the pdf file size is small and the generating report time is quick

Now I use birt-4.2, I use dynamic image which takes byte array as source, so my code is:

public byte[] getByteArray(List<ChartData> chartDataList, int width, int height, boolean isDualAxis) {
byte[] png=null;
BufferedImage objBufferedImage = new BufferedImage(480, 320, BufferedImage.TYPE_USHORT_555_RGB);
Graphics2D g2d = (Graphics2D) objBufferedImage.getGraphics();
Rectangle2D r2d = new Rectangle2D.Double(0, 0, 600, 400);
AffineTransform affineTransform2 = AffineTransform.getTranslateInstance(0, 0);
affineTransform2.scale(0.8, 0.8);
g2d.transform(affineTransform2);
g2d.transform(AffineTransform.getTranslateInstance(0, 0));
jfreechart.draw(g2d, r2d, null);
g2d.dispose();
g2d = null;
ByteArrayOutputStream bas = new ByteArrayOutputStream();
try {
ImageIO.write(objBufferedImage, "png", bas);
png=bas.toByteArray();
bas.close();
} catch (IOException e) {
e.printStackTrace();
}
return png;
}


in this method, the image in pdf is distorted after zoom in, the file size is bigger and the generating time is long

Is there a way to take com.itextpdf.text.image as the source for dynamic image in birt? or is there any other solution? If I want to edit the birt source code, can you give me some guide?

thanks very much.

the attached files are 2 pictures from itext report and my new birt report, the itext picture is not distorted after zoom in
  • Attachment: itext.png
    (Size: 19.57KB, Downloaded 287 times)
  • Attachment: birt.png
    (Size: 47.66KB, Downloaded 316 times)
Re: how to use com.itextpdf.text.image to generate pdf report [message #1073194 is a reply to message #1046658] Wed, 24 July 2013 09:47 Go to previous message
janine chang is currently offline janine changFriend
Messages: 2
Registered: April 2013
Junior Member
Hi,

I did my own "patch" to org.eclipse.birt.report.engine.emitter.pdf.PDFPage

and now I can generate an image from JFreeChart to iText, which gets the fast speed and small file size.

I have added my steps to bugzilla:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=413489
Previous Topic:Issues with Report in Maximo 7.5
Next Topic:Birt view internalizational
Goto Forum:
  


Current Time: Sat Sep 21 09:41:35 GMT 2024

Powered by FUDForum. Page generated in 0.04160 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top