我的代码如下try {
/* 打开已经定义好字段以后的pdf模板 */
PdfReader reader = new PdfReader("D:\\感谢函.pdf"); 
/* 将要生成的目标PDF文件名称 */
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(
"D:\\感谢函全含.pdf"));
/* 取出报表模板中的所有字段 */
AcroFields form = stamper.getAcroFields();
/* 为字段赋值,注意字段名称是区分大小写的 */
form.setField("customerName", "远东宏信");
form.setField("year", "2011");
form.setField("month", "11");
form.setField("day", "14");
form.setField("yearO", "2010");
form.setField("monthO", "12");
form.setField("dayO", "15");
stamper.setFormFlattening(true);
/* 必须要调用这个,否则文档不会生成的 */
stamper.close();
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
在我D盘有个感谢函.pdf并用Adobe Acrobat 8 Professional做好了文本域。但感谢函全含.pdf没有。
可断点调试刚走完第一行代码就报错。说
Exception: PDF header signature not found.
java.io.IOException: PDF header signature not found.
  at com.lowagie.text.pdf.PRTokeniser.checkPdfHeader(Unknown Source)
  at com.lowagie.text.pdf.PdfReader.readPdf(Unknown Source)
  at com.lowagie.text.pdf.PdfReader.<init>(Unknown Source)
  at com.lowagie.text.pdf.PdfReader.<init>(Unknown Source我用的JAR包是iText-2.1.7.jar
请问有哪里写错了吗?

解决方案 »

  1.   

    补充我的帖子:
    上面的错误解决了。但往form.setField("name", "远东宏信");设置值的时候报
    Exception in thread "main" ExceptionConverter: com.lowagie.text.DocumentException: Font 'STSongStd-Light' with 'UniGB-UCS2-H' is not recognized.
    at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source)
    at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source)
    at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source)
    at com.lowagie.text.pdf.DocumentFont.<init>(Unknown Source)
    at com.lowagie.text.pdf.AcroFields.decodeGenericDictionary(Unknown Source)
    at com.lowagie.text.pdf.AcroFields.getAppearance(Unknown Source)
    at com.lowagie.text.pdf.AcroFields.setField(Unknown Source)
    at com.lowagie.text.pdf.AcroFields.setField(Unknown Source)
    at org.PdfCreator.main(PdfCreator.java:25)
    错误我晕了。
      

  2.   

    BaseFont qzfont = BaseFont.createFont(font, encoding, BaseFont.NOT_EMBEDDED);
    pdfStamp.setFontAndSize(qzfont, fontsize);加上这个字体设置
      

  3.   

    需要用到一个iTextAsian.jar 亚洲语言包。
    具体怎么用,google下吧。
      

  4.   

    亲,你这个PDF header signature not found.异常怎么解决的啊,我也出了这个异常,一天下来还没解决。跪求解决方法啊。