欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

有用springmvc的IText开发过PDf的吗求教 博客分类: springmvc springmvcitext 

程序员文章站 2024-03-25 15:49:40
...
    @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
现在再重写的方法里都不知道写什么了
求大神?
相关标签: springmvc itext