0

问题是通过使用下面的代码可以使用 iTextPdf 动态填充 Acrobat 字段上的中文文本,但是当我打开生成 pdf 时,中文文本没有显示(当我点击该字段时,只有它出现。请参考下面的代码。

        PdfReader reader = new PdfReader(D://xyx.pdf);
        PdfStamper stamper = new PdfStamper(reader, baos);
        AcroFields form = stamper.getAcroFields();

        Map<String, AcroFields.Item> fields = form.getFields();
        Iterator<?> it = fields.entrySet().iterator();
        // the following block will get the china text from a txt file
        while (it.hasNext()) {

            for (int i = 0; i < chinaList.size(); i++) {
            Map.Entry<?, ?> pairs = (Map.Entry<?, ?>) it.next();
            System.out.println(pairs.getKey() + " = " + pairs.getValue());
                form.setFieldProperty(chinaList.get(i), "textsize",
                        new Float(10), null);

                form.setField((String) pairs.getKey(), chinaList.get(i));
                //form.setField((String) pairs.getKey(),"Jaipal");
               System.out.println(chinaList.get(i));
            }
            it.remove(); 
            }
        FileOutputStream fileOutputStream = new FileOutputStream("Output.pdf");
        fileOutputStream.write(decodedDocumentByteArray);
        stamper.close();
        reader.close(); 
4

0 回答 0