Beispiel #1
0
        public virtual void ManipulatePdf(String src, String dest)
        {
            //Initialize PDF document
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
            //Add text annotation
            PdfAnnotation ann = new PdfTextAnnotation(new Rectangle(400, 795, 0, 0))
                                .SetOpen(true)
                                .SetTitle(new PdfString("iText"))
                                .SetContents("Please, fill out the form.");

            pdfDoc.GetFirstPage().AddAnnotation(ann);
            PdfCanvas canvas = new PdfCanvas(pdfDoc.GetFirstPage());

            canvas.BeginText().SetFontAndSize(PdfFontFactory.CreateFont(StandardFonts.HELVETICA), 12).MoveText(265, 597
                                                                                                               ).ShowText("I agree to the terms and conditions.").EndText();
            //Add form field
            PdfAcroForm        form       = PdfAcroForm.GetAcroForm(pdfDoc, true);
            PdfButtonFormField checkField = PdfFormField.CreateCheckBox(pdfDoc, new Rectangle(245, 594, 15, 15), "agreement"
                                                                        , "Off", PdfFormField.TYPE_CHECK);

            checkField.SetRequired(true);
            form.AddField(checkField);
            //Update reset button
            form.GetField("reset").SetAction(PdfAction.CreateResetForm(new String[] { "name", "language", "experience1"
                                                                                      , "experience2", "experience3", "shift", "info", "agreement" }, 0));
            pdfDoc.Close();
        }