我得到这个例外当我生成图像到PDF

时间:2012-12-18 07:42:53

标签: java jsp

我的例外

ClientAbortException:  java.net.SocketException: Broken pipe
at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:319)
at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:288)
at org.apache.catalina.connector.CoyoteOutputStream.flush(CoyoteOutputStream.java:98)
at javax.imageio.stream.MemoryCacheImageOutputStream.flushBefore(MemoryCacheImageOutputStream.java:177)
at javax.imageio.stream.MemoryCacheImageOutputStream.close(MemoryCacheImageOutputStream.java:163)
at javax.imageio.ImageIO.write(ImageIO.java:1567)
at org.jfree.chart.encoders.SunPNGEncoderAdapter.encode(SunPNGEncoderAdapter.java:127)
at org.jfree.chart.encoders.EncoderUtil.writeBufferedImage(EncoderUtil.java:134)
at org.jfree.chart.ChartUtilities.writeBufferedImageAsPNG(ChartUtilities.java:610)
at org.apache.jsp.SRAnalysisGraphReportPDF_jsp._jspService(SRAnalysisGraphReportPDF_jsp.java:173)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
 **Caused by: java.net.SocketException: Broken pipe**
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:760)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:432)
at org.apache.coyote.http11.InternalOutputBuffer.flush(InternalOutputBuffer.java:318)
at org.apache.coyote.http11.Http11Processor.action(Http11Processor.java:985)
at org.apache.coyote.Response.action(Response.java:183)
at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:314)
... 27 more

1 个答案:

答案 0 :(得分:1)

Please go through bellow code :-

package com.test;


import com.lowagie.text.Rectangle;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import java.io.File;
import java.io.FileOutputStream;
/**
*
* @author Jamsheer T
* +91 9846716175
*/
public class PDFConversion
{
/**
* This method is used to convert the given file to a PDF format
* @param inputFile - Name and the path of the file
* @param outputFile - Name and the path where the PDF file to be saved
* @param isPictureFile
*/
private void createPdf(String inputFile, String outputFile, boolean isPictureFile)
 {
  /**
  * Set the page size for the image
  */
 Rectangle pageSize = new Rectangle(2780, 2525);
 Document pdfDocument = new Document(pageSize);
 String pdfFilePath = outputFile;
 try
 {
     FileOutputStream fileOutputStream = new FileOutputStream(pdfFilePath);
     PdfWriter writer = null;
     writer = PdfWriter.getInstance(pdfDocument, fileOutputStream);
     writer.open();
     pdfDocument.open();
     /**
     * Proceed if the file given is a picture file
     */
      if (isPictureFile)
     {
      pdfDocument.add(com.lowagie.text.Image.getInstance(inputFile));
     }
     /**
     * Proceed if the file given is (.txt,.html,.doc etc)
     */
     else
     {
     File file = new File(inputFile);

     }

     pdfDocument.close();
     writer.close();
   }
   catch (Exception exception)
   {
     System.out.println("Document Exception!" + exception);
    }
  }

  public static void main(String args[])
  {
   PDFConversion pdfConversion = new PDFConversion();
   pdfConversion.createPdf("C:\\Users\\Jamsheer T\\Desktop\\test\\Lily flower   
  wallpaper.jpg", "C:\\Users\\Jamsheer T\\Desktop\\test\\myfile.pdf", true);

  }
  }