Hi all,

I've been asked to dive into the iText source in order to allow for the 
flattening of rich text fields on our PDF forms (currently, iText simply 
stamps the XML code into the field).

Now one solution I thought of would be to simply use 
partialFormFlattening(fieldName) on fields not containing the rich text 
formatting, and then setting the rich text fields to "read-only" (via 
AcroFields.setFieldProperty(...)); however, this doesn't work - it still 
stamps the actual XML code onto the field and the Reader will not render 
it as rich text in the stamped PDF.

Please visit the code I've written below and feel free to point out any 
errors/omissions I have made when trying to accomplish this, or if I'm 
failing to understand the usage of the methods outlined in the 
Documentation.  (Please note, as suggested in some current iText archive 
articles, I've also attempted this with a call to setField(name,value) 
after the setFieldProperty() statement with the same results).  I'm 
using the most recent SVN version of the iText source compiled via 
Eclipse 3.2.2.

           // Prepare FDF/PDF reader objects
            FdfReader inFDF = new FdfReader(inFDFFilename);
            PdfReader inPDF = new PdfReader(inPDFFilename);
           
            // create our stamper instance
            PdfStamper stp = new PdfStamper(inPDF, new 
FileOutputStream(outPDFFilename));
           
            // set form flattening flag
            stp.setFormFlattening(true);
           
            // Merge the FDF data into the PDF
            AcroFields af = stp.getAcroFields();
            af.setFields(inFDF);
           
            // Iterate through the list of fields
            HashMap hm = af.getFields();
            Iterator i = hm.keySet().iterator();
            while (i.hasNext()) {
                String fieldName = (String)i.next();
                String fieldData = af.getField(fieldName);
               
                if (fieldData.indexOf("<?xml") >= 0) {
                    // System.out.println("xml data found in "+fieldName);
                    // simply mark this field as "read-only" but keep 
everything intact
                    // so that the client's Reader can render the 
XML/rich text formatting itself
                    af.setFieldProperty(fieldName, "setfflags", 
PdfFormField.FF_READ_ONLY, null);
//                    af.setField(fieldName, fieldData);
                } else {
                    // this field can be flattened
                    stp.partialFormFlattening(fieldName);
                }
            }
           
            // close the stamper
            stp.close();


Thanks!

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to