`
吳培基一个人奋斗中
  • 浏览: 601 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

有用springmvc的IText开发过PDf的吗求教

阅读更多
    @Override
    protected void buildPdfDocument(Map<String, Object> model, Document document,
                                    PdfWriter writer, HttpServletRequest request,
                                    HttpServletResponse response)
            throws Exception {
        PdfReader reader = new PdfReader(request.getSession().getServletContext().getRealPath("/")+"temp.pdf");
        ByteArrayOutputStream ba=new ByteArrayOutputStream();
        PdfStamper stamper=new PdfStamper(reader,new FileOutputStream("/1.pdf"));
        AcroFields fields = stamper.getAcroFields();
        for (Iterator it = fields.getFields().keySet().iterator(); it
                .hasNext();) {
            System.out.println("---PDF----"+it.next());
        }
        Map<String, String> map=(Map<String, String>) model.get(DATA);
        for (String key : map.keySet()) {
            System.out.println("key:"+key);
            String value = map.get(key);
            System.out.println("value:"+value);
            fields.setField(key, value);
            fields.setField("userName","zhangsan");
        }
      //  fillData(fields, (Map<String, String>) model.get(DATA));
        stamper.setFormFlattening(true);
        System.out.println("stamper=" + stamper);

        stamper.close();
//        response.setContentType("application/pdf");
      //     response.setContentLength(ba.size());
        //ServletOutputStream outstream = response.getOutputStream();

    //  ba.writeTo(outstream);
        reader.close();
      //   ba.flush();
        // ba.close();
    }
这是springmvc里间接继承AbstractView因为springmvc支持IText1.3写了个中间类让他支持5.4的pdf。
是不行有 问题。报过ExceptionConverter: java.io.IOException: The document has no pages. 这是现在下面代码报错的

顺便问下:Itext怎么搞了两套啊,一个IText和ItextPdf一个1.3和一个5.5
现在再重写的方法里都不知道写什么了
求大神?
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics