急求!java导出pdf的源码,希望各位兄弟姐妹过来帮助一下,我弄的那个pdf导出只有在ie9的情况下是以文件形式导出,其它的浏览器都是在线看的,求解!

解决方案 »

  1.   

    设置response.setContentType()了吗?
    response.setContentType()的String参数及对应类型<option   value="image/bmp">BMP</option>   
    <option   value="image/gif">GIF</option>   
    <option   value="image/jpeg">JPEG</option>   
    <option   value="image/tiff">TIFF</option>   
    <option   value="image/x-dcx">DCX</option>   
    <option   value="image/x-pcx">PCX</option>   
    <option   value="text/html">HTML</option>   
    <option   value="text/plain">TXT</option>   
    <option   value="text/xml">XML</option>   
    <option   value="application/afp">AFP</option>   
    <option   value="application/pdf">PDF</option>   
    <option   value="application/rtf">RTF</option>   
    <option   value="application/msword">MSWORD</option>   
    <option   value="application/vnd.ms-excel">MSEXCEL</option>   
    <option   value="application/vnd.ms-powerpoint">MSPOWERPOINT</option>   
    <option   value="application/wordperfect5.1">WORDPERFECT</option>   
    <option   value="application/vnd.lotus-wordpro">WORDPRO</option>   
    <option   value="application/vnd.visio">VISIO</option>   
    <option   value="application/vnd.framemaker">FRAMEMAKER</option>   
    <option   value="application/vnd.lotus-1-2-3">LOTUS123</option>
      

  2.   

    你用什么来生成PDF的,iTEXT吗?在java代码里面,response里面设置一下就可以了【application/pdf】类似这样的
      

  3.   

    用Itext 插件吧, 很容易的
      

  4.   

    能使用现有工具最好哇,像iText
      

  5.   

    先向大家说句不好意思,由于昨天有点事没及时回复大家,谢谢大家支持先。代码如下
                                      
                                Document document = new Document(PageSize.A4, 10, 10, 10, 10); HttpServletResponse response = ServletActionContext.getResponse();
    response.setContentType("application/pdf");    
    table = new Table(12);//设置列数为3列
         table.setBorderWidth(1); //将边框宽度设为1
         table.setBorderColor(new Color(0, 0, 255)); 
         table.setPadding(1);
         table.setSpacing(1);
         //上面两个代码是设置单元格的间距    
         Cell cell = new Cell(new PDFParagraph("案例信息"));   //设置表头的名称
         cell.setHeader(true);//是将该单元格作为表头信息显示
         cell.setColspan(12);//指定了该单元格占4列,为表格添加表头信息时
         table.addCell(cell);
         table.endHeaders();
         table.addCell(new PDFParagraph("案例代号"));
         table.addCell(new PDFParagraph("案例名称"));
         table.addCell(new PDFParagraph("案例状态"));
         table.addCell(new PDFParagraph("开启日期"));
         table.addCell(new PDFParagraph("产品线名称"));
         table.addCell(new PDFParagraph("通路名称"));
         table.addCell(new PDFParagraph("销售区域名称"));
         table.addCell(new PDFParagraph("联系人"));
         table.addCell(new PDFParagraph("公司"));
         table.addCell(new PDFParagraph("案例型态"));
         table.addCell(new PDFParagraph("附件数量"));
         table.addCell(new PDFParagraph("备注"));
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
         PdfWriter.getInstance(document, buffer);   
         document.open();
         document.add(table);
         document.close();
         response.setContentLength(buffer.size());//测试
         ServletOutputStream out = response.getOutputStream();
         buffer.writeTo(out);
             out.flush();  
      

  6.   

    搞定了!明白了原因,谢谢各位捧场,真的不好意思!原来是个小问题,还真给大家添麻烦了!由于我用的struts2,可是我没对pdf文件进行重命名,加上一句
    ServletActionContext.getResponse().setHeader(
         "Content-disposition",
         "attachment; filename="
         + URLEncoder.encode("报价单展示表.pdf", "UTF-8"));就解决了。