Community
Participate
Working Groups
Created attachment 233686 [details] JFreeChart to PNG to Birt Data Source: JFreeChart Output Format: PDF Issue: convert JFreeChart to PNG byte array makes the image blurred, convert JFreeChart to SVG byte array also makes the die data point blurred even if the text is clear after zoom in, and the output file size is big in this two ways Purpose: clear vetor image and small file size
Created attachment 233687 [details] JFreeChart to SVG to Birt
Created attachment 233688 [details] JFreeChart directly to Birt
I did my own "patch" to org.eclipse.birt.report.engine.emitter.pdf.PDFPage I modify the following method: protected void drawImage( String imageId, byte[] imageData, String extension, float imageX, float imageY, float height,float width, String helpText, Map params ) throws Exception if ( SvgFile.isSvg( null, null, extension ) ) { //start add JFreeChart if(null == imageData) return; JFreeChart[] charts = null; try { ObjectInputStream obj =new ObjectInputStream(new ByteArrayInputStream(imageData)); charts = (JFreeChart[])obj.readObject(); } catch (Exception e) { // TODO Auto-generated catch block System.out.println("not jfreechart"); } if(charts!=null){ template = contentByte.createTemplate(width*2, height*2); Image img = genJfreechartImage(template, charts, width, height); if(img!=null) drawImage( img, imageX, imageY, height, width, helpText ); return; //end add JFreeChart }else{ template = generateTemplateFromSVG( null, imageData, imageX, imageY, height, width, helpText ); } }
and add my genJfreechartImage: //add genJfreechartImage private Image genJfreechartImage(PdfTemplate tp, JFreeChart[] charts, float width, float height)throws BadElementException, DocumentException{ Graphics2D g2d = tp.createGraphics(width*2, height*2, true, 0); for(int i=0;i<charts.length;i++){ Rectangle2D r2d = new Rectangle2D.Double(i*width*2/charts.length, 0, width*2/charts.length, height*2); charts[i].draw(g2d, r2d, null); } Image img = Image.getInstance(tp); g2d.dispose(); g2d = null; return img; }
To use the "patch", need to do: 1: serialize the JFreeChart[] to byte[] 2: setMimeType("image/svg+xml") to the image in report design In this way, the vector image is always clear after zoom in and the file size will be much smaller than convert to PNG/SVG
If this patch is acceptable, could you add it to the future birt updates?