I am trying to do some kind of "fill in" a predefined form but
apparently this doesn't exist with iText.
 
So, it seems like a pretty popular approach is to add form fields/text
boxes with in the PDF document read in the document and set those
values.  I have two questions.  First question, what is the best way to
do this.  Also, can I change the visual aspects of the text box.  Can I
increase the font, possibly disable the border around the edit box.
 
Here is the code I have.  I am able to read the document and write it
back out.  But I get an error when I resave the document.
 
    public static final ByteArrayOutputStream generatePDFDocumentBytes()

        throws DocumentException, IOException {         
        
        Document document = null;
        PdfWriter writer = null;
                
        ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
        
        final PdfReader reader  = new PdfReader(PATH);
        Rectangle psize = reader.getPageSizeWithRotation(1);
        float height = psize.height();
        int rotation = reader.getPageRotation(1);
        
        document = new Document(psize, 0,0, 0,0);
        writer = PdfWriter.getInstance(document, baosPDF);
        document.open();
        
        document.newPage();
        PdfImportedPage page = writer.getImportedPage(reader,1);
        PdfContentByte cb = writer.getDirectContent();
        cb.addTemplate(page, 0, -1f, 1f, 0, 0, height);
       
        PdfStamper stamp = new PdfStamper(reader, baosPDF);
       
        AcroFields form = stamp.getAcroFields();
        HashMap formFields = form.getFields();
        System.out.println(formFields.size());
        
        for (Iterator it = formFields.entrySet().iterator();
it.hasNext(); ) {
            
            Map.Entry e = (Map.Entry) it.next();
            final String fieldName = (String) e.getKey();
            System.out.println("==>" + fieldName);
            System.out.println("==>" + e.getKey() + " // " +
e.getValue());
                        
            //form.setField(fieldName, "New");
        }
        
        stamp.setFormFlattening(true);
        stamp.close();
        
        document.close();
        return baosPDF;
    }
        
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to