Example #1
0
        public static PdfAcroForm AddAcroForm(Document doc)
        {
            Paragraph title = new Paragraph("Application for employment").SetTextAlignment(TextAlignment.CENTER).SetFontSize
                                  (16);

            doc.Add(title);
            doc.Add(new Paragraph("Full name:").SetFontSize(12));
            doc.Add(new Paragraph("Native language:      English         French       German        Russian        Spanish"
                                  ).SetFontSize(12));
            doc.Add(new Paragraph("Experience in:       cooking        driving           software development").SetFontSize
                        (12));
            doc.Add(new Paragraph("Preferred working shift:").SetFontSize(12));
            doc.Add(new Paragraph("Additional information:").SetFontSize(12));
            //Add acroform
            PdfAcroForm form = PdfAcroForm.GetAcroForm(doc.GetPdfDocument(), true);
            //Create text field
            PdfTextFormField nameField = PdfTextFormField.CreateText(doc.GetPdfDocument(), new Rectangle(99, 753, 425,
                                                                                                         15), "name", "");

            form.AddField(nameField);
            //Create radio buttons
            PdfButtonFormField group = PdfFormField.CreateRadioGroup(doc.GetPdfDocument(), "language", "");

            PdfFormField.CreateRadioButton(doc.GetPdfDocument(), new Rectangle(130, 728, 15, 15), group, "English");
            PdfFormField.CreateRadioButton(doc.GetPdfDocument(), new Rectangle(200, 728, 15, 15), group, "French");
            PdfFormField.CreateRadioButton(doc.GetPdfDocument(), new Rectangle(260, 728, 15, 15), group, "German");
            PdfFormField.CreateRadioButton(doc.GetPdfDocument(), new Rectangle(330, 728, 15, 15), group, "Russian");
            PdfFormField.CreateRadioButton(doc.GetPdfDocument(), new Rectangle(400, 728, 15, 15), group, "Spanish");
            form.AddField(group);
            //Create checkboxes
            for (int i = 0; i < 3; i++)
            {
                PdfButtonFormField checkField = PdfFormField.CreateCheckBox(doc.GetPdfDocument(), new Rectangle(119 + i *
                                                                                                                69, 701, 15, 15), String.Concat("experience", (i + 1).ToString()), "Off", PdfFormField.TYPE_CHECK);
                form.AddField(checkField);
            }
            //Create combobox
            String[]           options     = new String[] { "Any", "6.30 am - 2.30 pm", "1.30 pm - 9.30 pm" };
            PdfChoiceFormField choiceField = PdfFormField.CreateComboBox(doc.GetPdfDocument(), new Rectangle(163, 676,
                                                                                                             115, 15), "shift", "Any", options);

            form.AddField(choiceField);
            //Create multiline text field
            PdfTextFormField infoField = PdfTextFormField.CreateMultilineText(doc.GetPdfDocument(), new Rectangle(158,
                                                                                                                  625, 366, 40), "info", "");

            form.AddField(infoField);
            //Create push button field
            PdfButtonFormField button = PdfFormField.CreatePushButton(doc.GetPdfDocument(), new Rectangle(479, 594, 45
                                                                                                          , 15), "reset", "RESET");

            button.SetAction(PdfAction.CreateResetForm(new String[] { "name", "language", "experience1", "experience2"
                                                                      , "experience3", "shift", "info" }, 0));
            form.AddField(button);
            return(form);
        }
Example #2
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);

            PdfButtonFormField button = PdfFormField.CreatePushButton(pdfDoc,
                                                                      new Rectangle(36, 700, 36, 30), "post", "POST");

            button.SetBackgroundColor(ColorConstants.GRAY);
            button.SetValue("POST");

            // The second parameter is optional, it declares which fields to include in the submission or which to exclude,
            // depending on the setting of the Include/Exclude flag.
            button.SetAction(PdfAction.CreateSubmitForm("http://itextpdf.com:8180/book/request", null,
                                                        PdfAction.SUBMIT_HTML_FORMAT | PdfAction.SUBMIT_COORDINATES));
            button.SetVisibility(PdfFormField.VISIBLE_BUT_DOES_NOT_PRINT);
            form.AddField(button);

            pdfDoc.Close();
        }
        // ********************************************************************
        // Fct:     CreateAnnot
        //
        // Descr:   -
        //
        // Owner:   erst
        // ********************************************************************
        public static void CreateAnnot(String src, String dest)
        {
            try
            {
                // Initialize PDF document
                PdfDocument ScrPdf  = new PdfDocument(new PdfReader(src));
                PdfPage     SrcPage = null;


                PdfDocument destPdf = new PdfDocument(new PdfWriter(dest));
                PageSize    ps      = PageSize.A4;
                destPdf.SetDefaultPageSize(ps);

                string idx = String.Empty;


                for (int i = 1; i <= 3; i++)
                {
                    idx = i.ToString();
                    // Add a page from Source PDF
                    SrcPage = ScrPdf.GetPage(i);
                    destPdf.AddPage(SrcPage.CopyTo(destPdf));
                    // Add empty page
                    //destPdf.AddNewPage(PageSize.A4);

                    PdfPage page = destPdf.GetPage(i);

                    // add title
                    PdfFont   fontHelvetica = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);
                    PdfCanvas canvas        = new PdfCanvas(page);
                    canvas.BeginText().SetFontAndSize(fontHelvetica, 8).MoveText(420, 770).ShowText("My Title " + idx).EndText();

                    //Add acroform
                    PdfAcroForm form = PdfAcroForm.GetAcroForm(destPdf, true);
                    //Create text field
                    PdfTextFormField title = PdfTextFormField.CreateText(destPdf, new Rectangle(420, 750, 60, 10), idx + "_Title", idx + ".Page", fontHelvetica, 6);
                    PdfTextFormField user1 = PdfTextFormField.CreateText(destPdf, new Rectangle(420, 740, 60, 10), idx + "_User", "enter User", fontHelvetica, 6);
                    PdfTextFormField date1 = PdfTextFormField.CreateText(destPdf, new Rectangle(420, 730, 60, 10), idx + "_Date", "enter date" + idx, fontHelvetica, 6);
                    form.AddField(title);
                    form.AddField(user1);
                    form.AddField(date1);

                    //// Create Button Check

                    PdfButtonFormField button = PdfFormField.CreatePushButton(destPdf, new Rectangle(420, 720, 19, 10), idx + "_BtnOK", "OK");
                    //button.SetAction(PdfAction.CreateResetForm(new String[] { "name", "language", "experience1", "experience2", "experience3", "shift", "info" }, 0));
                    PdfAction action = new PdfAction();
                    PdfAction date   = PdfAction.CreateJavaScript("AFDate_FormatEx(\"yyyy-mm-dd\");");

                    //PdfAction date = PdfAction.CreateNamed
                    //action.Put(button.GetFormType(), PdfName.F);

                    button.SetAction(date);
                    form.AddField(button);
                }


                ScrPdf.Close();
                destPdf.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
        }