> Post a small PDF so that the problem can be reproduced.

File is attached. I have a virtual data structure that basically contains the 
name and the value I want to write. The
code basically looks like this:

class PdfFormField {
  String name;
  String value;
}

the data I write is this:

Writing: Checkbox 2 with value: Wert4 (Off,Wert4,)
Writing: Checkbox with value: Wert2 (Wert3,Off,Wert1,Wert2,Wert4,)
Writing: Text Normal with value: Just some fucking text yup ()
Writing: ComboBox with value: Gurken ()
Writing: Text RTF with value: Just some fucking text RTF yippieh ()
Writing: ListBox single Selection with value: Wert4 ()
Writing: ListBox Multi Selection with value: Wert1 ()

(the output is Name, Value (AppearanceStates))

and the code I use to write the fields is:

  public static final void saveReport(String serverFileName, File outputFile, 
Map<String, PdfFormField> fieldValues, boolean flattenFile) throws IOException, 
DocumentException {
    PdfReader reader = new PdfReader(serverFileName);
    try {
      FileOutputStream fos = new FileOutputStream(outputFile);
      try {
        AcroFields acroFields = reader.getAcroFields();
        boolean hasSignature = (acroFields.getSignatureNames().size() + 
acroFields.getBlankSignatureNames().size()) > 0;
        PdfStamper stamp = new PdfStamper(reader, fos, '\0', hasSignature);
        stamp.setFormFlattening(flattenFile);
        try {
          AcroFields form = stamp.getAcroFields();
          for (PdfFormField field : fieldValues.values()) {
            AcroFields.Item item = form.getFieldItem(field.getName());
            String[] allowed = form.getAppearanceStates(field.getName());
            String appearance = "";
            if (allowed != null)
              for (String s: allowed)
                appearance += s + ",";
            System.out.println("Writing: " + field.getName() + " with value: " 
+ field.getValue() + " (" + appearance + ")");
            if (item == null) {
              System.out.println("Field: " + field.getName() + " cannot be 
found!");
              continue;
            }
            switch (field.getComponentType()) {
              case None:
                break;
              case CheckBox:
              case RadioButton:
                form.setField(field.getName(), field.getValue());
                break;
              case ComboBox:
              case List: // How can we treat multiple selections?
                form.setField(field.getName(), field.getValue());
                break;
              case PushButton:
              case Signature:
                break;
              case Text:
                form.setField(field.getName(), field.getValue());
                ArrayList objArrayList = item.widgets;
                PdfDictionary dic = (PdfDictionary) objArrayList.get(0);
                PdfDictionary action = (PdfDictionary) 
PdfReader.getPdfObject(dic.get(PdfName.MK));

                Color color = field.getColor();
                if (action == null && color != null) {
                  PdfDictionary d = new PdfDictionary(PdfName.MK);
                  dic.put(PdfName.MK, d);

                  PdfArray f = new PdfArray(new int[] { color.getRed(), 
color.getGreen(), color.getBlue() });
                  d.put(PdfName.BG, f);
                }
            }
          }
        }
        finally {
          stamp.close();
        }
      }
      finally {
        fos.close();
      }
    }
    finally {
      reader.close();
    }
  }
  
Best regards and thanks
Rog
  


/*
 * Roger Misteli - ABACUS Research AG
 * Just because the system gives you a cliff doesn't mean you have to jump off 
it!
 */

Attachment: FelderTest2.pdf
Description: Binary data

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to