I have a simple test program as following. The intention is to create 4 
check boxes (disabled, for displaying purpose only). However the tow 
paragraphs "this is paragraph four" and "this is paragraph five" are 
rendered at the same Y position as the first check box. I expect to see 
them rendered after the 4th check box. I tried PdfContentByte.moveTo() but 
it didn't work out. How do I do that? I read chapter 7 of the "iText in 
Action" book. Looks like I have to use  ColumnText?

Any input is appreciated. If you compile and run the program as below, you 
might know  what my trouble is. 

Thanks,
Zhaohua Meng


import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class PdfTest {
 
        public static void main(String[] args) throws Exception {
                OutputStream out = new FileOutputStream("test.pdf");
                Document document = new Document(PageSize.LETTER);
                PdfWriter writer = PdfWriter.getInstance(document,out);
                document.open();
                document.add(new Paragraph("this is paragraph one"));
                document.add(new Paragraph("this is paragraph two"));
                document.add(new Paragraph("this is paragraph three"));
                createCheckbox(writer);
                //after writing the 4 check boxes, t
                document.add(new Paragraph("this is paragraph four"));
                document.add(new Paragraph("this is paragraph five"));
                document.close();
        }

        private static void createCheckbox(PdfWriter writer) throws 
IOException, DocumentException {
                BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
                                BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
                Rectangle rect = null;
                float fontSize = 12f;
                float lineWidth = 25;
                PdfContentByte cb = writer.getDirectContent();
                float currentPosition = writer.getVerticalPosition(false);
                String[] questions = {"Q 1","Q 2","Q 3","Q 4"};
                for (int i = 0; i < questions.length; i++) {
                                rect = new Rectangle(35, currentPosition - 
i * lineWidth, 100, currentPosition -fontSize - i * lineWidth);
                        RadioCheckField checkBox = new 
RadioCheckField(writer, rect, "name"+i, "On");
                        checkBox.setCheckType(RadioCheckField.TYPE_CHECK);
                        checkBox.setChecked(true);
                        checkBox.setOptions(BaseField.READ_ONLY);
                        writer.addAnnotation(checkBox.getCheckField());
                        cb.beginText();
                        cb.setFontAndSize(bf, fontSize);
                        cb.showTextAligned(Element.ALIGN_LEFT, 
questions[i], 80,
                                currentPosition - i * lineWidth-fontSize, 
0);
                        cb.endText(); 
                                }

        }
}
This message is being sent from a law firm and may contain
confidential or privileged information.  If you are not
the intended recipient, please advise the sender
immediately by reply e-mail and delete this message and
any attachments without retaining a copy.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to