A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Products
»
Other Open Source Projects
Author
Need to Charts on same PDF Output
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1261
posted
Sep 21, 2012 10:53:45
0
I am using the following code in my
servlet
but I only get the first chart and it is as big as page.
MOR8dChart dashboardChart8d = new MOR8dChart(); dashboardChart8d.setIssued8ds(gConn.getAs400Conn(), edSource, dArray.getDateArray(), rOwnerGroupString, rLocationString, userid, rStatusString); request.getSession().setAttribute("chart1",dashboardChart8d.getChart()); JFreeChart chart = (JFreeChart) request.getSession().getAttribute( "chart1" ); MOR8dChartb dashboardChart8db = new MOR8dChartb(); dashboardChart8db.setIssued8ds(gConn.getAs400Conn(), edSource, rOwnerGroupString, rLocationString, userid, rStatusString); request.getSession().setAttribute("chart1b",dashboardChart8db.getChart()); JFreeChart chartb = (JFreeChart) request.getSession().getAttribute( "chart1b" ); if(new Boolean(new Boolean(request.getSession().getAttribute("localServer").toString()).booleanValue()).booleanValue()){ pdffilePath = "//qgvas400/home/FAIManagement/ReportsAndCharts/MOR8dChart"+edSource+userid+".pdf"; } else{ pdffilePath = "/home/FAIManagement/ReportsAndCharts/MOR8dChart"+edSource+userid+".pdf"; } FileIndexerConnection fiConn = new FileIndexerConnection(); fiConn.setSaveUserFile(gConn.getAs400Conn(), userid, "/home/FAIManagement/ReportsAndCharts/RejectionsByDispositionChart" + edSource+userid+".pdf"); response.setContentType( "application/pdf" ); int width = 320; int height = 240; Rectangle pagesize = new Rectangle( width, height ); try{ Document document = new Document( pagesize, 50, 50, 50, 50 ); PdfWriter writer = PdfWriter.getInstance( document, new FileOutputStream(pdffilePath) ); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate( width, height ); Graphics2D g2 = tp.createGraphics( width, height, new DefaultFontMapper() ); Rectangle2D r2D = new Rectangle2D.Double(0, 0, width, height ); chart.draw(g2, r2D); g2.dispose(); cb.addTemplate(tp, 0, 0); PdfContentByte cbb = writer.getDirectContent(); PdfTemplate tpb = cbb.createTemplate( width, height ); Graphics2D g2b = tpb.createGraphics( width, height, new DefaultFontMapper() ); Rectangle2D r2Db = new Rectangle2D.Double(320, 240, width, height ); chartb.draw(g2b, r2Db); g2b.dispose(); cbb.addTemplate(tpb, 0, 0); document.close();
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: Need to Charts on same PDF Output
Similar Threads
Images in PDF files problem for ServletOutputStream
2D inconsistencies
Display a Chart from a Servlet to JSP
What to Replace Deprecated Method With
iText PDF export
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter