public virtual void ChoiceFieldsWithUnicodeTest()
        {
            String      outPdf = destinationFolder + "choiceFieldsWithUnicodeTest.pdf";
            String      cmpPdf = sourceFolder + "cmp_choiceFieldsWithUnicodeTest.pdf";
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outPdf));
            PdfFont     font   = PdfFontFactory.CreateFont(sourceFolder + "NotoSansCJKjp-Bold.otf", "Identity-H");

            font.SetSubset(false);
            PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);

            pdfDoc.AddNewPage();
            // 规
            form.AddField(PdfFormField.CreateComboBox(pdfDoc, new Rectangle(36, 666, 40, 80), "combo1", "\u89c4", new
                                                      String[] { "\u89c4", "\u89c9" }, font, null).SetBorderColor(ColorConstants.BLACK));
            // 觉
            form.AddField(PdfFormField.CreateComboBox(pdfDoc, new Rectangle(136, 666, 40, 80), "combo2", "\u89c4", new
                                                      String[] { "\u89c4", "\u89c9" }, font, null).SetValue("\u89c9").SetBorderColor(ColorConstants.BLACK));
            // 规
            form.AddField(PdfFormField.CreateList(pdfDoc, new Rectangle(236, 666, 50, 80), "list1", "\u89c4", new String
                                                  [] { "\u89c4", "\u89c9" }, font, null).SetBorderColor(ColorConstants.BLACK));
            // 觉
            form.AddField(PdfFormField.CreateList(pdfDoc, new Rectangle(336, 666, 50, 80), "list2", "\u89c4", new String
                                                  [] { "\u89c4", "\u89c9" }, font, null).SetValue("\u89c9").SetBorderColor(ColorConstants.BLACK));
            pdfDoc.Close();
            CompareTool compareTool  = new CompareTool();
            String      errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder);

            if (errorMessage != null)
            {
                NUnit.Framework.Assert.Fail(errorMessage);
            }
        }
        public virtual void ChoiceFieldTest01()
        {
            String      filename = destinationFolder + "choiceFieldTest01.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(210, 490, 150, 20);

            String[]           options = new String[] { "First Item", "Second Item", "Third Item", "Fourth Item" };
            PdfChoiceFormField choice  = PdfFormField.CreateComboBox(pdfDoc, rect, "TestField", "First Item", options);

            form.AddField(choice);
            Rectangle          rect1   = new Rectangle(210, 250, 150, 90);
            PdfChoiceFormField choice1 = PdfFormField.CreateList(pdfDoc, rect1, "TestField1", "Second Item", options);

            choice1.SetMultiSelect(true);
            form.AddField(choice1);
            pdfDoc.Close();
            CompareTool compareTool  = new CompareTool();
            String      errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_choiceFieldTest01.pdf", destinationFolder
                                                                    , "diff_");

            if (errorMessage != null)
            {
                NUnit.Framework.Assert.Fail(errorMessage);
            }
        }
Exemple #3
0
            public override void Draw(DrawContext drawContext)
            {
                PdfFont font;

                try
                {
                    font = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);
                }
                catch (IOException e)
                {
                    throw new PdfException(e);
                }

                String[][] optionsArray = new String[options.Length][];
                for (int i = 0; i < options.Length; i++)
                {
                    optionsArray[i]    = new String[2];
                    optionsArray[i][0] = exports[i];
                    optionsArray[i][1] = options[i];
                }

                PdfAcroForm form = PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true);

                // The 3rd parameter is the combobox name, the 4th parameter is the combobox's initial value
                PdfChoiceFormField choice = PdfFormField.CreateComboBox(drawContext.GetDocument(),
                                                                        GetOccupiedAreaBBox(), name, name, optionsArray);

                choice.SetFont(font);
                choice.GetWidgets()[0].SetBorderStyle(PdfAnnotation.STYLE_BEVELED);
                choice.SetVisibility(PdfFormField.VISIBLE_BUT_DOES_NOT_PRINT);
                choice.SetBorderColor(ColorConstants.GRAY);
                choice.SetJustification(PdfFormField.ALIGN_CENTER);
                form.AddField(choice);
            }
Exemple #4
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);
        }
        public virtual void PdfA1DocWithPdfA1ComboBoxFieldTest()
        {
            String  name     = "pdfA1DocWithPdfA1ComboBoxField";
            String  fileName = destinationFolder + name + ".pdf";
            String  cmp      = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1ComboBoxField.pdf";
            PdfFont fontCJK  = PdfFontFactory.CreateFont(sourceFolder + "NotoSansCJKtc-Light.otf", PdfEncodings.IDENTITY_H
                                                         , true);
            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);

            form.AddField(PdfFormField.CreateComboBox(pdfDoc, new Rectangle(156, 616, 70, 70), "combo", "用", new String
                                                      [] { "用", "规", "表" }, fontCJK, conformanceLevel));
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, destinationFolder));
            NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName));
        }