Hi Paulo,
i've tried your last tip for multiple field-annotations on 
different page (with function setPlaceInPage()) and it works in 
general, but it seems I found a bug.

If you want to populate a PDF with fields and kids of these fields 
on different pages, you get a problem if there's a page in the PDF 
without any fields.

The code below produces an invalid PDF, though I can't tell why 
it is illegal. For me, the object-relations look quite sensible.

But if you click or tab in the field on the third page, Acrobat 
Reader 5 complains about incorrect links, Acrobat Reader 6 
doesn't seem to have a problem.

Do you have any ideas?

Best regards,
Peter

BTW: Is there a tool for checking the validity of PDF-files?
Acrobat's error messages are not very informative!


public class FieldsonPages
{
        public static void main(String[] args) 
        {
                String strOutPDF = "c:/temp/with_fields.pdf";
                
                System.out.println("Testing fields on different pages");
                Document doc = new Document();
                try 
                {
                        PdfFormField aFormField = null;
                        PdfFormField bFormField = null;
                        PdfFormField aSecondKid = null;
                        PdfFormField aFirstKid = null;
                        float fontSize = 12;
                        Color textColor = new GrayColor(0f);

                        BaseFont helv = BaseFont.createFont("Helvetica", "winansi", 
false);
                        PdfWriter aWriter = PdfWriter.getInstance(doc,
                                        new FileOutputStream(strOutPDF));
                        doc.open();
                        PdfContentByte cb = aWriter.getDirectContent();
                        doc.add(new Paragraph("Page 1"));

                        aFormField = PdfFormField.createTextField(aWriter, false, 
false, 100); 
                        aFormField.setFieldName("aTextField");

                        aFirstKid = PdfFormField.createTextField(aWriter, false, 
false, 100);
                        aFirstKid.setWidget(new Rectangle(171, 750, 342, 769),
PdfAnnotation.HIGHLIGHT_INVERT);
                        aFormField.addKid(aFirstKid);

                        aSecondKid = PdfFormField.createTextField(aWriter, false, 
false, 100);
                        aSecondKid.setWidget(new Rectangle(171, 650, 342, 669),
PdfAnnotation.HIGHLIGHT_INVERT);
                        aFormField.addKid(aSecondKid);
                        aSecondKid.setPlaceInPage(3);

                        aWriter.addAnnotation(aFormField);

                        doc.newPage();
                        doc.add(new Paragraph("Page 2"));

                        doc.newPage();
                        doc.add(new Paragraph("Page 3"));

                        doc.close();
                } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (DocumentException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }

                System.out.println("finished.");
        }


> PdfAnnotation.setPlaceInPage() 

-- 
NEU: GMX ProMail mit bestem Virenschutz http://www.gmx.net/de/go/mail
+++ Empfehlung der Redaktion +++ Internet Professionell 10/04 +++



-------------------------------------------------------
This SF.Net email is sponsored by: thawte's Crypto Challenge Vl
Crack the code and win a Sony DCRHC40 MiniDV Digital Handycam
Camcorder. More prizes in the weekly Lunch Hour Challenge.
Sign up NOW http://ad.doubleclick.net/clk;10740251;10262165;m
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to