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 03:43  |
Eclipse User |
|
|
|
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 297 times)
Attachment: birt.png
(Size: 47.66KB, Downloaded 328 times)
|
|
| |
Goto Forum:
Current Time: Fri Mar 21 17:34:22 EDT 2025
Powered by FUDForum. Page generated in 0.03428 seconds
|