Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[birt-dev] How to get smaller BIRT pdf report file size and faster generating time?

Hello,
 
I have thousands of 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

How to get smaller BIRT pdf report file size and faster generating time?
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
Description: Binary data

Attachment: birt.png
Description: Binary data


Back to the top