public virtual void CreatePDF(String dest)
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest));

            PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDocument, true);

            PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "KhmerOS.ttf",
                                                     PdfEncodings.IDENTITY_H);

            // Embed entire font without any subsetting. Please note that without subset it's impossible to edit a form field
            // with the predefined font
            font.SetSubset(false);

            // រុញ​ខ្ញុំ
            String text = "\u179A\u17BB\u1789\u200B\u1781\u17D2\u1789\u17BB\u17C6";

            Rectangle rect = new Rectangle(50, 650, 100, 25);

            // Create a button for the form field, set its font and size
            PdfButtonFormField pushButton = PdfFormField.CreatePushButton(pdfDocument, rect, "Name", text);

            pushButton
            .SetFont(font)
            .SetFontSize(10);

            // Add the button to the form
            form.AddField(pushButton);

            pdfDocument.Close();
        }
Example #2
0
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.attach.impl.layout.form.renderer.AbstractFormFieldRenderer#applyAcroField(com.itextpdf.layout.renderer.DrawContext)
         */
        protected internal override void ApplyAcroField(DrawContext drawContext)
        {
            String    value    = GetDefaultValue();
            String    name     = GetModelId();
            UnitValue fontSize = (UnitValue)this.GetPropertyAsUnitValue(Property.FONT_SIZE);

            if (!fontSize.IsPointValue())
            {
                ILog logger = LogManager.GetLogger(typeof(iText.Html2pdf.Attach.Impl.Layout.Form.Renderer.ButtonRenderer));
                logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property
                                                      .FONT_SIZE));
            }
            PdfDocument doc  = drawContext.GetDocument();
            Rectangle   area = flatRenderer.GetOccupiedArea().GetBBox().Clone();

            ApplyPaddings(area, true);
            PdfPage            page   = doc.GetPage(occupiedArea.GetPageNumber());
            PdfButtonFormField button = PdfFormField.CreatePushButton(doc, area, name, value, font, fontSize.GetValue(
                                                                          ));
            Background background = this.GetProperty <Background>(Property.BACKGROUND);

            if (background != null && background.GetColor() != null)
            {
                button.SetBackgroundColor(background.GetColor());
            }
            ApplyDefaultFieldProperties(button);
            PdfAcroForm.GetAcroForm(doc, true).AddField(button, page);
        }
Example #3
0
        public virtual void PdfA1aRadioFieldOffAppearanceTest()
        {
            String          name         = "pdfA1a_radioFieldOffAppearance";
            String          outPath      = destinationFolder + name + ".pdf";
            String          cmpPath      = cmpFolder + "cmp_" + name + ".pdf";
            String          diff         = "diff_" + name + "_";
            PdfWriter       writer       = new PdfWriter(outPath);
            Stream          @is          = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
                                                               , @is);
            PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);

            doc.SetTagged();
            doc.GetCatalog().SetLang(new PdfString("en-US"));
            doc.AddNewPage();
            PdfAcroForm        form  = PdfAcroForm.GetAcroForm(doc, true);
            PdfButtonFormField group = PdfFormField.CreateRadioGroup(doc, "group", "1", PdfAConformanceLevel.PDF_A_1B);

            group.SetReadOnly(true);
            Rectangle rect1 = new Rectangle(36, 700, 20, 20);
            Rectangle rect2 = new Rectangle(36, 680, 20, 20);

            PdfFormField.CreateRadioButton(doc, rect1, group, "1", PdfAConformanceLevel.PDF_A_1B).SetBorderWidth(2).SetBorderColor
                (ColorConstants.RED).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetVisibility(PdfFormField.VISIBLE);
            PdfFormField.CreateRadioButton(doc, rect2, group, "2", PdfAConformanceLevel.PDF_A_1B).SetBorderWidth(2).SetBorderColor
                (ColorConstants.RED).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetVisibility(PdfFormField.VISIBLE);
            form.AddField(group);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
                                                                             ));
        }
        public virtual void CreatePDF(String dest)
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest));

            PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDocument, true);

            PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "NotoSansGurmukhi-Regular.ttf",
                                                     PdfEncodings.IDENTITY_H);

            // ਮੈਨੂੰ ਧੱਕੋ
            String line1 = "\u0A2E\u0A48\u0A28\u0A42\u0A70\u0020\u0A27\u0A71\u0A15\u0A4B";

            Rectangle rectangle = new Rectangle(50, 650, 100, 25);

            // Create a button for the form field, set its font and size
            PdfButtonFormField pushButton = PdfFormField.CreatePushButton(pdfDocument, rectangle, "Name", line1);

            pushButton
            .SetFont(font)
            .SetFontSize(10);

            // Add the button to the form
            form.AddField(pushButton);

            pdfDocument.Close();
        }
Example #5
0
        public virtual void CreatePDF(String dest)
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest));

            PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDocument, true);

            PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "NotoSansDevanagari-Regular.ttf",
                                                     PdfEncodings.IDENTITY_H);

            // पुश मे
            String text = "\u092A\u0941\u0936\u0020\u092E\u0947";

            Rectangle rect = new Rectangle(50, 650, 150, 25);

            // Create a button for the form field, set its font and size
            PdfButtonFormField pushButton = PdfFormField.CreatePushButton(pdfDocument, rect, "Name", text);

            pushButton
            .SetFont(font)
            .SetFontSize(10);

            // Add the button to the form
            form.AddField(pushButton);

            pdfDocument.Close();
        }
Example #6
0
        public virtual void CreatePDF(String dest)
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest));

            PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDocument, true);

            PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "NotoSansThai-Regular.ttf",
                                                     PdfEncodings.IDENTITY_H);

            // Embed entire font without any subsetting. Please note that without subset it's impossible to edit a form field
            // with the predefined font
            font.SetSubset(false);

            // ผลักฉัน
            String text = "\u0E1C\u0E25\u0E31\u0E01\u0E09\u0E31\u0E19";

            Rectangle rect = new Rectangle(50, 650, 80, 25);

            // Create a button for the form field, set its font and size
            PdfButtonFormField pushButton = PdfFormField.CreatePushButton(pdfDocument, rect, "Name", text);

            pushButton
            .SetFont(font)
            .SetFontSize(10);

            // Add the button to the form
            form.AddField(pushButton);

            pdfDocument.Close();
        }
 public override void Draw(DrawContext drawContext)
 {
     base.Draw(drawContext);
     if (!IsFlatten())
     {
         String    value    = GetDefaultValue();
         String    name     = GetModelId();
         UnitValue fontSize = (UnitValue)this.GetPropertyAsUnitValue(Property.FONT_SIZE);
         if (!fontSize.IsPointValue())
         {
             fontSize = UnitValue.CreatePointValue(DEFAULT_FONT_SIZE);
         }
         PdfDocument doc  = drawContext.GetDocument();
         Rectangle   area = GetOccupiedArea().GetBBox().Clone();
         ApplyMargins(area, false);
         PdfPage            page   = doc.GetPage(occupiedArea.GetPageNumber());
         PdfButtonFormField button = PdfFormField.CreatePushButton(doc, area, name, value, doc.GetDefaultFont(), fontSize
                                                                   .GetValue());
         button.GetWidgets()[0].SetHighlightMode(PdfAnnotation.HIGHLIGHT_NONE);
         button.SetBorderWidth(0);
         button.SetBackgroundColor(null);
         TransparentColor color = GetPropertyAsTransparentColor(Property.FONT_COLOR);
         if (color != null)
         {
             button.SetColor(color.GetColor());
         }
         PdfAcroForm forms = PdfAcroForm.GetAcroForm(doc, true);
         //Add fields only if it isn't already added. This can happen on split.
         if (forms.GetField(name) == null)
         {
             forms.AddField(button, page);
         }
     }
 }
Example #8
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);
            PdfFont     font   = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);
            Rectangle   rect   = new Rectangle(40, 788, 20, 18);
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);

            // Radio buttons will be added to this radio group
            PdfButtonFormField radioGroup = PdfFormField.CreateRadioGroup(pdfDoc, "Language", "");

            for (int page = 1; page <= LANGUAGES.Length; page++)
            {
                pdfDoc.AddNewPage();

                // Create a radio button that is added to a radio group.
                PdfFormField field = PdfFormField.CreateRadioButton(pdfDoc, rect, radioGroup, LANGUAGES[page - 1]);
                field.SetBorderWidth(1);
                field.SetBorderColor(ColorConstants.BLACK);

                // Method specifies on which page the form field's widget must be shown.
                field.SetPage(page);
                doc.ShowTextAligned(new Paragraph(LANGUAGES[page - 1]).SetFont(font).SetFontSize(18),
                                    70, 786, page, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0);
            }

            form.AddField(radioGroup);

            doc.Close();
        }
Example #9
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();
        }
        public virtual void CreatePDF(String dest)
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest));

            PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDocument, true);

            PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "NotoNaskhArabic-Regular.ttf",
                                                     PdfEncodings.IDENTITY_H);

            // ادفعني
            String text = "\u0627\u062F\u0641\u0639\u0646\u064A";

            Rectangle rect = new Rectangle(50, 650, 100, 25);

            // Create a button for the form field, set its font and size
            PdfButtonFormField pushButton = PdfFormField.CreatePushButton(pdfDocument, rect, "Name", text);

            pushButton
            .SetFont(font)
            .SetFontSize(10);

            // Add the button to the form
            form.AddField(pushButton);

            pdfDocument.Close();
        }
        public virtual void ButtonFieldTest01()
        {
            String             filename = destinationFolder + "buttonFieldTest01.pdf";
            PdfWriter          writer   = new PdfWriter(new FileStream(filename, FileMode.Create));
            PdfDocument        pdfDoc   = new PdfDocument(writer);
            PdfAcroForm        form     = PdfAcroForm.GetAcroForm(pdfDoc, true);
            Rectangle          rect     = new Rectangle(36, 700, 20, 20);
            Rectangle          rect1    = new Rectangle(36, 680, 20, 20);
            PdfButtonFormField group    = PdfFormField.CreateRadioGroup(pdfDoc, "TestGroup", "1");

            PdfFormField.CreateRadioButton(pdfDoc, rect, group, "1");
            PdfFormField.CreateRadioButton(pdfDoc, rect1, group, "2");
            form.AddField(group);
            PdfButtonFormField pushButton = PdfFormField.CreatePushButton(pdfDoc, new Rectangle(36, 650, 40, 20), "push"
                                                                          , "Capcha");
            PdfButtonFormField checkBox = PdfFormField.CreateCheckBox(pdfDoc, new Rectangle(36, 560, 20, 20), "TestCheck"
                                                                      , "1");

            form.AddField(pushButton);
            form.AddField(checkBox);
            pdfDoc.Close();
            CompareTool compareTool  = new CompareTool();
            String      errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_buttonFieldTest01.pdf", destinationFolder
                                                                    , "diff_");

            if (errorMessage != null)
            {
                NUnit.Framework.Assert.Fail(errorMessage);
            }
        }
Example #12
0
        public virtual void EncryptAes256Pdf2PermissionsTest02()
        {
            String filename = "encryptAes256Pdf2PermissionsTest02.pdf";
            // This test differs from the previous one (encryptAes256Pdf2PermissionsTest01) only in permissions.
            // Here we do not allow to fill the form in.
            int         permissions = EncryptionConstants.ALLOW_SCREENREADERS | EncryptionConstants.ALLOW_DEGRADED_PRINTING;
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(destinationFolder + filename, new WriterProperties().SetPdfVersion
                                                                        (PdfVersion.PDF_2_0).SetStandardEncryption(USER, OWNER, permissions, EncryptionConstants.ENCRYPTION_AES_256
                                                                                                                   )));

            pdfDoc.GetDocumentInfo().SetMoreInfo(customInfoEntryKey, customInfoEntryValue);
            PdfAcroForm      form       = PdfAcroForm.GetAcroForm(pdfDoc, true);
            PdfTextFormField textField1 = PdfFormField.CreateText(pdfDoc, new Rectangle(100, 600, 200, 30), "Name", "Enter your name"
                                                                  );

            form.AddField(textField1);
            PdfTextFormField textField2 = PdfFormField.CreateText(pdfDoc, new Rectangle(100, 550, 200, 30), "Surname",
                                                                  "Enter your surname");

            form.AddField(textField2);
            PdfButtonFormField group = PdfFormField.CreateRadioGroup(pdfDoc, "Sex", "Male");

            PdfFormField.CreateRadioButton(pdfDoc, new Rectangle(100, 530, 10, 10), group, "Male");
            PdfFormField.CreateRadioButton(pdfDoc, new Rectangle(120, 530, 10, 10), group, "Female");
            form.AddField(group);
            pdfDoc.Close();
            CompareTool compareTool  = new CompareTool();
            String      errorMessage = compareTool.CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename
                                                                    , destinationFolder, "diff_", USER, USER);

            if (errorMessage != null)
            {
                NUnit.Framework.Assert.Fail(errorMessage);
            }
        }
        public virtual void CreatePDF(String dest)
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest));

            PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDocument, true);

            PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "NotoSansGujarati-Regular.ttf",
                                                     PdfEncodings.IDENTITY_H);

            // મને દબાણ કરો
            String text = "\u0AAE\u0AA8\u0AC7\u0020\u0AA6\u0AAC\u0ABE\u0AA3\u0020\u0A95\u0AB0\u0ACB";

            Rectangle rect = new Rectangle(50, 650, 100, 25);

            // Create a button for the form field, set its font and size
            PdfButtonFormField pushButton = PdfFormField.CreatePushButton(pdfDocument, rect, "Name", text);

            pushButton
            .SetFont(font)
            .SetFontSize(10);

            // Add the button to the form
            form.AddField(pushButton);

            pdfDocument.Close();
        }
Example #14
0
        public virtual void CreatePDF(String dest)
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest));

            PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDocument, true);

            // Embedded parameter indicates whether the font is to be embedded into the target document.
            // We set it to make sure that the resultant document looks the same within different environments
            PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "NotoSansTamil-Regular.ttf",
                                                     PdfEncodings.IDENTITY_H, true);

            // என்னை தள்ளி விடு
            String text =
                "\u0B8E\u0BA9\u0BCD\u0BA9\u0BC8\u0020\u0BA4\u0BB3\u0BCD\u0BB3\u0BBF\u0020\u0BB5\u0BBF\u0B9F\u0BC1";

            // Embed entire font without any subsetting. Please note that without subset it's impossible to edit a form field
            // with the predefined font
            font.SetSubset(false);
            Rectangle rect = new Rectangle(50, 650, 140, 30);

            // Create a button for the form field, set its font and size
            PdfButtonFormField pushButton = PdfFormField.CreatePushButton(pdfDocument, rect, "Name", text);

            pushButton
            .SetFont(font)
            .SetFontSize(10);

            // Add the button to the form
            form.AddField(pushButton);

            pdfDocument.Close();
        }
Example #15
0
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.attach.impl.layout.form.renderer.AbstractFormFieldRenderer#applyAcroField(com.itextpdf.layout.renderer.DrawContext)
         */
        protected internal override void ApplyAcroField(DrawContext drawContext)
        {
            PdfDocument        doc        = drawContext.GetDocument();
            PdfAcroForm        form       = PdfAcroForm.GetAcroForm(doc, true);
            Rectangle          area       = flatRenderer.GetOccupiedArea().GetBBox().Clone();
            PdfPage            page       = doc.GetPage(occupiedArea.GetPageNumber());
            String             groupName  = this.GetProperty <String>(Html2PdfProperty.FORM_FIELD_VALUE);
            PdfButtonFormField radioGroup = (PdfButtonFormField)form.GetField(groupName);
            bool addNew = false;

            if (null == radioGroup)
            {
                radioGroup = PdfFormField.CreateRadioGroup(doc, groupName, "on");
                addNew     = true;
            }
            if (IsBoxChecked())
            {
                radioGroup.SetValue(GetModelId());
            }
            PdfFormField radio = PdfFormField.CreateRadioButton(doc, area, radioGroup, GetModelId());

            radio.SetCheckType(PdfFormField.TYPE_CIRCLE);
            if (addNew)
            {
                form.AddField(radioGroup, page);
            }
            else
            {
                form.ReplaceField(GetModelId(), radioGroup);
            }
            WriteAcroFormFieldLangAttribute(doc);
        }
Example #16
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 #17
0
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.attach.impl.layout.form.renderer.AbstractFormFieldRenderer#applyAcroField(com.itextpdf.layout.renderer.DrawContext)
         */
        protected internal override void ApplyAcroField(DrawContext drawContext)
        {
            String             name     = GetModelId();
            PdfDocument        doc      = drawContext.GetDocument();
            Rectangle          area     = flatRenderer.GetOccupiedArea().GetBBox().Clone();
            PdfPage            page     = doc.GetPage(occupiedArea.GetPageNumber());
            PdfButtonFormField checkBox = PdfFormField.CreateCheckBox(doc, area, name, IsBoxChecked() ? "Yes" : "Off");

            PdfAcroForm.GetAcroForm(doc, true).AddField(checkBox, page);
        }
 private void AddFormFieldsToDocument(PdfDocument pdfDoc, PdfAcroForm acroForm) {
     Rectangle rect = new Rectangle(36, 700, 20, 20);
     Rectangle rect1 = new Rectangle(36, 680, 20, 20);
     PdfButtonFormField group = PdfFormField.CreateRadioGroup(pdfDoc, "TestGroup", "1");
     PdfFormField.CreateRadioButton(pdfDoc, rect, group, "1");
     PdfFormField.CreateRadioButton(pdfDoc, rect1, group, "2");
     acroForm.AddField(group);
     PdfButtonFormField pushButton = PdfFormField.CreatePushButton(pdfDoc, new Rectangle(36, 650, 40, 20), "push"
         , "Capcha");
     PdfButtonFormField checkBox = PdfFormField.CreateCheckBox(pdfDoc, new Rectangle(36, 560, 20, 20), "TestCheck"
         , "1");
     acroForm.AddField(pushButton);
     acroForm.AddField(checkBox);
 }
Example #19
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            PdfFont     font   = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H);
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);

            // Define the position of a button that measures 108 by 26
            Rectangle          rect       = new Rectangle(36, 780, 108, 26);
            PdfButtonFormField pushButton = PdfFormField.CreatePushButton(pdfDoc, rect, "japanese",
                                                                          JAPANESE_TEXT, font, 12f);

            form.AddField(pushButton);

            pdfDoc.Close();
        }
        public virtual void PdfAButtonFieldTest()
        {
            PdfDocument pdf;
            Stream      @is      = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            String      file     = "pdfAButtonField.pdf";
            String      filename = destinationFolder + file;

            pdf = new PdfADocument(new PdfWriter(new FileStream(filename, FileMode.Create)), PdfAConformanceLevel.PDF_A_1B
                                   , new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB ICC preference", @is));
            PageSize pageSize = PageSize.LETTER;
            Document doc      = new Document(pdf, pageSize);

            PdfFontFactory.Register(sourceFolder + "FreeSans.ttf", sourceFolder + "FreeSans.ttf");
            PdfFont            font  = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", true);
            PdfButtonFormField group = PdfFormField.CreateRadioGroup(pdf, "group", "", PdfAConformanceLevel.PDF_A_1B);

            group.SetReadOnly(true);
            Paragraph p = new Paragraph();
            Text      t = new Text("supported");

            t.SetFont(font);
            p.Add(t);
            Image     ph = new Image(new PdfFormXObject(new Rectangle(10, 10)));
            Paragraph pc = new Paragraph().Add(ph);

            PdfAFormFieldTest.PdfAButtonFieldTestRenderer r = new PdfAFormFieldTest.PdfAButtonFieldTestRenderer(pc, group
                                                                                                                , "v1");
            pc.SetNextRenderer(r);
            p.Add(pc);
            Paragraph pc1 = new Paragraph().Add(ph);

            PdfAFormFieldTest.PdfAButtonFieldTestRenderer r1 = new PdfAFormFieldTest.PdfAButtonFieldTestRenderer(pc, group
                                                                                                                 , "v2");
            pc1.SetNextRenderer(r1);
            Paragraph p2 = new Paragraph();
            Text      t2 = new Text("supported 2");

            t2.SetFont(font);
            p2.Add(t2).Add(pc1);
            doc.Add(p);
            doc.Add(p2);
            //set generateAppearance param to false to retain custom appearance
            group.SetValue("v1", false);
            PdfAcroForm.GetAcroForm(pdf, true).AddField(group);
            pdf.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp/PdfAFormFieldTest/cmp_"
                                                                             + file, destinationFolder, "diff_"));
        }
Example #21
0
 public override void Draw(DrawContext drawContext)
 {
     base.Draw(drawContext);
     if (!IsFlatten())
     {
         String    value    = GetDefaultValue();
         String    name     = GetModelId();
         UnitValue fontSize = (UnitValue)this.GetPropertyAsUnitValue(Property.FONT_SIZE);
         if (!fontSize.IsPointValue())
         {
             fontSize = UnitValue.CreatePointValue(DEFAULT_FONT_SIZE);
         }
         PdfDocument doc  = drawContext.GetDocument();
         Rectangle   area = GetOccupiedArea().GetBBox().Clone();
         ApplyMargins(area, false);
         PdfPage            page   = doc.GetPage(occupiedArea.GetPageNumber());
         PdfButtonFormField button = PdfFormField.CreatePushButton(doc, area, name, value, doc.GetDefaultFont(), fontSize
                                                                   .GetValue());
         button.GetWidgets()[0].SetHighlightMode(PdfAnnotation.HIGHLIGHT_NONE);
         button.SetBorderWidth(0);
         button.SetBackgroundColor(null);
         TransparentColor color = GetPropertyAsTransparentColor(Property.FONT_COLOR);
         if (color != null)
         {
             button.SetColor(color.GetColor());
         }
         PdfAcroForm forms = PdfAcroForm.GetAcroForm(doc, true);
         //Add fields only if it isn't already added. This can happen on split.
         if (forms.GetField(name) == null)
         {
             forms.AddField(button, page);
         }
         if (doc.IsTagged())
         {
             TagTreePointer formParentPointer = doc.GetTagStructureContext().GetAutoTaggingPointer();
             IList <String> kidsRoles         = formParentPointer.GetKidsRoles();
             int            lastFormIndex     = kidsRoles.LastIndexOf(StandardRoles.FORM);
             TagTreePointer formPointer       = formParentPointer.MoveToKid(lastFormIndex);
             String         lang = this.GetProperty <String>(Html2PdfProperty.FORM_ACCESSIBILITY_LANGUAGE);
             if (lang != null)
             {
                 formPointer.GetProperties().SetLanguage(lang);
             }
             formParentPointer.MoveToParent();
         }
     }
 }
 public virtual void FormFieldTaggingTest07() {
     String outFileName = destinationFolder + "taggedPdfWithForms07.pdf";
     String cmpFileName = sourceFolder + "cmp_taggedPdfWithForms07.pdf";
     PdfWriter writer = new PdfWriter(outFileName);
     PdfReader reader = new PdfReader(sourceFolder + "taggedDocWithFields.pdf");
     PdfDocument pdfDoc = new PdfDocument(reader, writer);
     // Original document is already tagged, so there is no need to mark it as tagged again
     //        pdfDoc.setTagged();
     PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(pdfDoc, true);
     PdfButtonFormField pushButton = PdfFormField.CreatePushButton(pdfDoc, new Rectangle(36, 650, 40, 20), "push"
         , "Capcha");
     TagTreePointer tagPointer = pdfDoc.GetTagStructureContext().GetAutoTaggingPointer();
     tagPointer.MoveToKid(StandardRoles.DIV);
     acroForm.AddField(pushButton);
     pdfDoc.Close();
     CompareOutput(outFileName, cmpFileName);
 }
Example #23
0
        public virtual void DefaultRadiobuttonFieldTest()
        {
            String             file     = "defaultRadiobuttonFieldTest.pdf";
            String             filename = destinationFolder + file;
            PdfDocument        pdfDoc   = new PdfDocument(new PdfWriter(filename));
            PdfAcroForm        form     = PdfAcroForm.GetAcroForm(pdfDoc, true);
            Rectangle          rect1    = new Rectangle(36, 700, 20, 20);
            Rectangle          rect2    = new Rectangle(36, 680, 20, 20);
            PdfButtonFormField group    = PdfFormField.CreateRadioGroup(pdfDoc, "TestGroup", "1");

            PdfFormField.CreateRadioButton(pdfDoc, rect1, group, "1");
            PdfFormField.CreateRadioButton(pdfDoc, rect2, group, "2");
            form.AddField(group);
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp_" + file, destinationFolder
                                                                             , "diff_"));
        }
Example #24
0
            public override void Draw(DrawContext drawContext)
            {
                PdfAcroForm form = PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true);

                // Define the coordinates of the middle
                float x = (GetOccupiedAreaBBox().GetLeft() + GetOccupiedAreaBBox().GetRight()) / 2;
                float y = (GetOccupiedAreaBBox().GetTop() + GetOccupiedAreaBBox().GetBottom()) / 2;

                // Define the position of a check box that measures 20 by 20
                Rectangle rect = new Rectangle(x - 10, y - 10, 20, 20);

                // The 4th parameter is the initial value of checkbox: 'Yes' - checked, 'Off' - unchecked
                // By default, checkbox value type is cross.
                PdfButtonFormField checkBox = PdfFormField.CreateCheckBox(drawContext.GetDocument(), rect, name, "Yes");

                form.AddField(checkBox);
            }
Example #25
0
        public virtual void CustomizedRadiobuttonFieldTest()
        {
            String             file     = "customizedRadiobuttonFieldTest.pdf";
            String             filename = destinationFolder + file;
            PdfDocument        pdfDoc   = new PdfDocument(new PdfWriter(filename));
            PdfAcroForm        form     = PdfAcroForm.GetAcroForm(pdfDoc, true);
            Rectangle          rect1    = new Rectangle(36, 700, 20, 20);
            Rectangle          rect2    = new Rectangle(36, 680, 20, 20);
            PdfButtonFormField group2   = PdfFormField.CreateRadioGroup(pdfDoc, "TestGroup2", "1");

            PdfFormField.CreateRadioButton(pdfDoc, rect1, group2, "1").SetBorderWidth(2).SetBorderColor(ColorConstants
                                                                                                        .RED).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetVisibility(PdfFormField.VISIBLE);
            PdfFormField.CreateRadioButton(pdfDoc, rect2, group2, "2").SetBorderWidth(2).SetBorderColor(ColorConstants
                                                                                                        .RED).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetVisibility(PdfFormField.VISIBLE);
            form.AddField(group2);
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp_" + file, destinationFolder
                                                                             , "diff_"));
        }
Example #26
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();
        }
        public virtual void PdfA1DocWithPdfA1RadioButtonFieldTest()
        {
            String name     = "pdfA1DocWithPdfA1RadioButtonField";
            String fileName = destinationFolder + name + ".pdf";
            String cmp      = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1RadioButtonField.pdf";
            Stream @is      = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            PdfAConformanceLevel conformanceLevel = PdfAConformanceLevel.PDF_A_1B;
            PdfADocument         pdfDoc           = new PdfADocument(new PdfWriter(fileName), conformanceLevel, new PdfOutputIntent("Custom"
                                                                                                                                    , "", "http://www.color.org", "sRGB IEC61966-2.1", @is));
            PdfAcroForm        form       = PdfAcroForm.GetAcroForm(pdfDoc, true);
            PdfButtonFormField radioGroup = PdfFormField.CreateRadioGroup(pdfDoc, "radio group", "", conformanceLevel);

            PdfFormField.CreateRadioButton(pdfDoc, new Rectangle(36, 496, 20, 20), radioGroup, "1", conformanceLevel).
            SetBorderWidth(2).SetBorderColor(ColorConstants.ORANGE);
            PdfFormField.CreateRadioButton(pdfDoc, new Rectangle(66, 496, 20, 20), radioGroup, "2", conformanceLevel).
            SetBorderWidth(2).SetBorderColor(ColorConstants.ORANGE);
            form.AddField(radioGroup);
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, destinationFolder));
            NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName));
        }
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);

            // Radio buttons will be added to this radio group
            PdfButtonFormField group = PdfFormField.CreateRadioGroup(pdfDoc, "Language", "");

            Table table = new Table(UnitValue.CreatePercentArray(2)).UseAllAvailableWidth();
            Cell  cell  = new Cell().Add(new Paragraph("English"));

            table.AddCell(cell);

            cell = new Cell();

            // The renderer creates radio button for the current radio group in the current cell
            cell.SetNextRenderer(new AddRadioButtonRenderer(cell, group, "english"));
            table.AddCell(cell);

            cell = new Cell().Add(new Paragraph("French"));
            table.AddCell(cell);

            cell = new Cell();
            cell.SetNextRenderer(new AddRadioButtonRenderer(cell, group, "french"));
            table.AddCell(cell);

            cell = new Cell().Add(new Paragraph("Dutch"));
            table.AddCell(cell);

            cell = new Cell();
            cell.SetNextRenderer(new AddRadioButtonRenderer(cell, group, "dutch"));
            table.AddCell(cell);

            doc.Add(table);

            form.AddField(group);

            doc.Close();
        }
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);

            // Radio buttons will be added to this radio group
            PdfButtonFormField radioGroup = PdfFormField.CreateRadioGroup(pdfDoc, "answer", "answer 1");

            Table table = new Table(UnitValue.CreatePercentArray(2)).UseAllAvailableWidth();

            for (int i = 0; i < 25; i++)
            {
                Cell cell = new Cell().Add(new Paragraph("Question " + i));
                table.AddCell(cell);

                cell = new Cell().Add(new Paragraph("Answer " + i));
                table.AddCell(cell);
            }

            for (int i = 0; i < 25; i++)
            {
                Cell cell = new Cell().Add(new Paragraph("Radio: " + i));
                table.AddCell(cell);

                cell = new Cell();

                // The renderer creates radio button for the current radio group in the current cell
                cell.SetNextRenderer(new AddRadioButtonRenderer(cell, radioGroup, "answer " + i));
                table.AddCell(cell);
            }

            doc.Add(table);

            form.AddField(radioGroup);

            pdfDoc.Close();
        }
 public PdfAButtonFieldTestRenderer(Paragraph para, PdfButtonFormField group, String value)
     : base(para)
 {
     _group = group;
     _value = value;
 }