pdf打標模板與xml資料自動填充
阿新 • • 發佈:2018-12-12
PdfReader.unethicalreading = true; PdfReader reader = new PdfReader("/templates/demo.pdf");//pdf模板 OutputStream os = new FileOutputStream("D://demo.pdf");//生成pdf路徑 PdfStamper stamper = new PdfStamper(reader,os,'\0',true); InputStream is = new ByteArrayInputStream(document.asXML().getBytes("gbk"));//document是org.dom4j.Document xml stamper.getAcroFields().getXfa().fillXfaForm(is); is.close(); stamper.close(); os.close(); reader.close();
pdf用的是itext:com.itextpdf.text.pdf.PdfReader,com.itextpdf.text.pdf.PdfStamper