jfreechart - Reduce size of iText generated PDF including time series bar chart -


adding time series bar chart large time span in pdf results in large file size 50 mb or more depending on data points. here code samples:

adding chart pdf

document document = new document(); pdfwriter writer = pdfwriter.getinstance(document, new fileoutputstream(result)); document.open(); pdfcontentbyte cb = writer.getdirectcontent(); float width = pagesize.a4.getwidth(); float height = pagesize.a4.getheight() / 2;  pdftemplate bar = cb.createtemplate(width, height); graphics2d g2d2 = new pdfgraphics2d(bar, width, height); rectangle2d r2d2 = new rectangle2d.double(0, 0, width, height); getbarchart().draw(g2d2, r2d2); g2d2.dispose(); cb.addtemplate(bar, 0, 0); document.close(); 

creating chart

jfreechart getbarchart() {     timeseries series = new timeseries("data");      gregoriancalendar cal = new gregoriancalendar();     (int i=0; i<365*24; i++) {         cal.add(calendar.hour, 1);         series.addorupdate(new millisecond(cal.gettime()), math.random());     }      xyplot plot = new xyplot();     plot.setdataset(new xybardataset(new timeseriescollection(series), 10));     plot.setrenderer(new xybarrenderer());     plot.setrangeaxis(new numberaxis());     plot.setdomainaxis(new dateaxis());      return new jfreechart(plot); } 

how can reduce file size?

using itextpdf-5.4.4 , jfreechart-1.0.15.

while inspecting pdf provided op, becomes apparent full of pattern definitions , used drawing pretty bars. reduce pdf size, therefore, simplifying bar design way go.

in case @ hand can done setting different default bar painter (using xybarrenderer.setdefaultbarpainter()). initial value of attribute gradientxybarpainter, using gradients small bars makes number of required drawing operations , operators explode while making difference @ gigantic zoom level, if @ all.

as worked out in comments question, using standardxybarpainter instead solves size issues.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -