0

I'm working on a Java Webdynpro where I try to print out a Interactive PDF form. I've been following the tutorial on: http://itextpdf.com/

Now when I print my new PDF 'temp.pdf', it shows the template with the correct text but the field are still empty. Did I miss something in my code?

Code

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
}
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
user2206834
  • 379
  • 1
  • 5
  • 13
  • 1) There is no need to add the major tag in the title. 2) Use a consistent and logical indent for code blocks. The indentation of the code is intended to help people understand the program flow. – Andrew Thompson Dec 13 '13 at 17:44
  • Define "Print". Do you see the fields when you open the form using a PDF viewer? Maybe you're experiencing this problem: http://stackoverflow.com/questions/20526634/acroform-values-missing-after-flattening – Bruno Lowagie Dec 13 '13 at 17:54
  • When I print the PDF he shows the right PDF but the inputfields stays empty...I think I missed something because he shows the perfect PDF but without the values that I've setted to the correct fields...I made a new Java Class and this code works perfect with the values in the fields, so there is something different between a normal java class and when I use it in my WebDynPro – user2206834 Dec 15 '13 at 21:18
  • So you're saying that the problem can only be reproduced in a WebDynPro environment? In that case, very few people on SO will be able to help you. I'd start by double-checking if you're using the same iText version both on WebDynPro as well as in your standalone test. – Bruno Lowagie Dec 16 '13 at 08:39
  • My mistake excuse me, already fix that problem. @Lowagie, zou je ook eens naar mijn volgend probleem kunnen kijken? (http://stackoverflow.com/questions/20608016/itext-filling-existing-table-pdf)...ik heb in adobe livecycle een pdf gemaakt met tabel, en nu zou ik deze willen opvullen? Het grote probleem is dat je in elk voorbeeld een nieuwe pdf aanmaakt, maar bij mij is het een bestaand document dus ik kan geen gebruik maken van Document. – user2206834 Dec 16 '13 at 12:58

0 Answers0