感谢您帮助我解决垃圾问题。昨晚和今天花了几个小时,人们对PipedIn /
OutStreams感到困惑。无法解决。但是,我得到它的工作。事实证明,这并不是很困难。
public void exportToPDF(JFreeChart chart, String filePath){ PDdocument doc = null; PDPage page = null; PDXObjectImage ximage = null; try { doc = new PDdocument(); page = new PDPage(); doc.addPage(page); PDPageContentStream content = new PDPageContentStream(doc, page); //create a new outStream ByteArrayOutputStream out = new ByteArrayOutputStream(); ChartUtilities.writeChartAsJPEG(out, chart, 300, 300);//write to outstream //create a new inputstream InputStream in = new ByteArrayInputStream(out.toByteArray()); ximage = new PDJpeg(doc, in); content.drawImage(ximage, 5, 300); content.close(); } catch (IOException ie){ //handle exception } //save and close doc.save(filePath); doc.close();}
我敢肯定,这样做可以做得更好,但是可以。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)