JFreechart and iText used in combination with the problem

For the need of the project, I used to generate reports JfreeChart pictures in the project, use the following code
/**
	 * Get the pie JFreeChart
	 * @return
	 */
	public static JFreeChart getPieJFreeChart(){
		
		// Create a theme style
		StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
		// Set the title font
		standardChartTheme.setExtraLargeFont(new Font("Official script", Font.BOLD, 20));
		// The font setting legend
		standardChartTheme.setRegularFont(new Font("Song Book", Font.PLAIN, 15));
		// Axial font settings
		standardChartTheme.setLargeFont(new Font("Song Book", Font.PLAIN, 15));
		// Applying a theme style
		ChartFactory.setChartTheme(standardChartTheme);
		
		return ChartFactory.createPieChart3D("The figure 1.1 test",piedataset, true, false, true);
		
	}


/**
	 * Generate a pie chart
	 * 
	 * @return
	 * @throws IOException
	 */
	public static String getView() throws IOException {	

		// The generation of JFreeChart objects through the factory class
		JFreeChart chart = getPieJFreeChart();

		PiePlot pieplot = (PiePlot) chart.getPlot();
		pieplot.setLabelFont(new Font("Times New Roman", 0, 14));
		// When no data display content
		pieplot.setNoDataMessage("No data show");
		// Set the background color
		pieplot.setBackgroundPaint(null);
		// In each block percentage pie
		pieplot.setCircular(true);
		pieplot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {2},{1}An example", NumberFormat.getNumberInstance(),NumberFormat.getPercentInstance()));
		pieplot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})"));
		StandardEntityCollection sec = new StandardEntityCollection();
		ChartRenderingInfo info = new ChartRenderingInfo(sec);
		HttpServletResponse response = ServletActionContext.getResponse();
		ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 550,400, info);
		response.getOutputStream().flush();
		response.getOutputStream().close();
		return null;
	}




The above is to generate a pie chart reports code, then I use iText to generate word documents, I think in the word document, the above statements picture into a word document. How to do?? I wrote the following code, but I can't.,
public String exportOffice() throws Exception {
		
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
     
	Image histogramImage = Image.getInstance(getView());
		
        createWord(outputStream,histogramImage,null);
        
        HttpServletResponse response = ServletActionContext.getResponse();

        response.addHeader("Content-Disposition", "attachment; filename=testReport.doc");
        response.setContentType("application/octet-stream");
        response.setContentLength(outputStream.size());

        ServletOutputStream out = response.getOutputStream();
        outputStream.writeTo(out);
        out.flush();
        out.close();
		return null;

	}



How can I get Jfreechart to generate word statements to create pictures? Ask God to save.!

Started by Amy at November 14, 2016 - 12:07 PM

IText combined with JfreeChart, I've used, but I output is PDF, should be the same.
I was the first JfreeChart image output to disk, then the iText is loaded from disk.

Posted by Colbert at November 27, 2016 - 12:16 PM

Hey. There are ways to use wood. Only the first picture is written on the disk, word to delete.. But such frequent operation of the disk is not always good. .

Posted by Amy at December 05, 2016 - 12:56 PM

JFreeChart chart=...;
BufferedImage bufferedImage = chart.createBufferedImage(550, 400);
ByteArrayOutputStream out = new ByteArrayOutputStream();
boolean flag = ImageIO.write(bufferedImage, "jpeg", out);
byte[] bytes = out.toByteArray();
Image img = Image.getInstance(bytes);
img.setAbsolutePosition(0, 0);
img.setAlignment(Image.LEFT);// Set the image display position
document.add(img);

This method is feasible?

Posted by Andy at December 13, 2016 - 1:21 PM