我正在开发一个Java Webdynpro,我尝试打印一个交互式PDF表单。 我一直在关注以下教程:http://itextpdf.com/
现在,当我打印我的新PDF“temp.pdf”时,它会显示具有正确文本的模板,但该字段仍为空。 我在代码中遗漏了什么吗?
public byte[] GetPDFFromFolder( java.lang.String folderPath )
{
//@@begin GetPDFFromFolder()
byte[] byteLink = new byte[4096];
IResource folder = null;
Content content = null;
try {
IResourceContext rctx = ResourceFactory.getInstance().getServiceContext("cmadmin_service");
RID sisFolderRID = RID.getRID(folderPath);
folder = ResourceFactory.getInstance().getResource(sisFolderRID, rctx);
} catch (ResourceException e) {
e.printStackTrace();
}
StringBuilder bf = new StringBuilder();
try {
PdfWriter writer = null;
File file = new File("temp.pdf");
try {
FileOutputStream out = new FileOutputStream(file);
if (folder.isCollection()) {
ICollection folderColl = (ICollection) folder;
IResourceListIterator it = folderColl.getChildren().listIterator();
IResource res = it.next();
try {
try {
InputStream in = res.getContent().getInputStream();
PdfReader reader = new PdfReader(in);
try {
PdfStamper stamper = new PdfStamper(reader, out);
AcroFields form = stamper.getAcroFields();
if ("Document1.pdf".equals(res.getName())){
form.setField("TextField1Vertegenwoordigd", "Van Den Berghe Tim");
form.setField("TextField2Directeur", "341 - Carrefour Evere");
form.setField("TextField3Nr", "5588");
form.setField("TextField4RPR", "RPR waarde");
form.setField("TextField5BTW", "9999-999-999");
form.setField("TextField6Euro", "100");
form.setField("TextField7Periode", "8 maanden");
form.setField("TextField8Totaal", "133");
form.setField("TextField9Producten", "Cd - Eminem");
form.setField("TextField9Producten", "Bruin banket brood");
form.setField("TextField10Vanaf", "06/08/2013");
form.setField("TextField11Op", "06/09/2013");
form.setField("TextField12Te", "06/08/2013");
form.setField("TextField13Op", "06/09/2013");
}
else {// doesn't matter}
stamper.close();
reader.close();
out.close();
FileInputStream inn = new FileInputStream(file);
byteLink = IOUtils.toByteArray(inn);
} catch (DocumentException e) {
e.printStackTrace();
}
} catch (ContentException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} catch (ResourceException e) {
e.printStackTrace();
}
return byteLink;
//@@end
}