I am able to read the PDF document and all of that works fine.  I am NOW
having a problem trying to position NEW text near an existing form
field.
 
ColumnText ct = new ColumnText(canvas);
float[] f = form.getFieldPositions("Text2");
ct.setSimpleColumn(f[1], f[2], f[3], f[4]);
 
For example, with this code, the setSimpleColumn doesn't seem to be in a
position I want.
 
It could be that I am using 'ColumnText'

________________________________

From: Brown, Berlin [GCG-PFS] 
Sent: Tuesday, October 20, 2009 4:35 PM
To: 'itext-questions@lists.sourceforge.net'
Cc: 'Berlin Brown'
Subject: RE: Modifying the value of forms in a PDF document, update!


OK, I am able to open a PDF document, find the form/text fields that I
need and then set those values.  Now I want to be able to change the
font size and alignment of that text.  And additional additional text.
I used some code 'addText' that I found online.  I am able to add the
new text but the position is off.
 
I used the get field position call to get the positions but they don't
seem to lie on top of the text field.  Essentially, with the code below,
my new text is not even close to where I want it.  If you look at the
hard coded values, 
 
ct.setSimpleColumn(f[1], f[2]-300, f[3]+ 100, f[4]-300);

I don't mean to substract some arbitrary value 300 from the height.  
 
Here is the original code that I modified.
http://www.1t3xt.info/examples/browse/?page=example&id=347
--------------- Code: 
 
     @SuppressWarnings("unchecked")
    public static boolean addText(String s, PdfContentByte canvas,
float[] f, float size, boolean simulate) throws DocumentException,
IOException {
        
        // PdfContentByte is an object containing the user positioned
text and graphic contents of a page. 
        // It knows how to apply the proper font encoding.         
        StyleSheet styles = new StyleSheet();
        /*
        styles.loadTagStyle("p", "size", size + "px");
        styles.loadTagStyle("p", "align", "justify");
        styles.loadTagStyle("p", "hyphenation", "en_us");
        */
        ArrayList<Element> objects = HTMLWorker.parseToList(new
StringReader(s), styles);
        ColumnText ct = new ColumnText(canvas);
        ct.setAlignment(Element.ALIGN_CENTER);
        ct.setLeading(size * 1.2f);
        ///////////////////////////////
        /// __NOTE__:2
        /// THIS IS THE CODE I AM HAVING AN ISSUE WITH
        /// THE TEXT SHOULD! DISPLAY BY THE TEXT BOX
        ///////////////////////////////
        //ct.setSimpleColumn(f[1] + 2, f[2] + 2, f[3] - 2, f[4]);  
        //float llx, float lly, float urx, float ury, int alignment)
        ct.setSimpleColumn(f[1], f[2]-300, f[3]+ 100, f[4]-300);
        for (Element element : objects) {            
            final Chunk cz = new Chunk("abc!!!!!", F1);
            cz.setFont(F1);
            final Phrase jj = new Phrase(cz);
            ct.addElement(jj);
        }
        ct.go(simulate);
        return true;
    }
 
    
    public static final ByteArrayOutputStream generatePDFDocumentBytes()

        throws DocumentException, IOException {
                
        ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();

        final PdfReader reader  = new PdfReader(CERT_PATH);
                
        PdfStamper stamp = new PdfStamper(reader, baosPDF);       
        AcroFields form = stamp.getAcroFields();
        HashMap formFields = form.getFields();
        System.out.println(formFields.size());
        
        // PdfContentByte is an object containing the user positioned
text and graphic contents of a page. 
        // It knows how to apply the proper font encoding. 
        PdfContentByte canvas = stamp.getOverContent(1);        
        
        float[] f = form.getFieldPositions("Text2");        
        System.out.println("===>" + f.length + " // " + f[0] + ", " +
f[1] + ", " + f[2] + ", " + f[3] + ", " + f[4]);        
        addText("<p>__Test__ Again!!</p>", canvas, f, 8, false);
        
        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());
            /// __NOTE__:3 HERE THE TEXT IS CHANGED ON THE FORM (that is
OK)
            form.setField(fieldName, "simple text");
        }
                        
        stamp.setFormFlattening(true);
        stamp.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