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);
            }
        }
        public virtual void MultiSelectByValueTest()
        {
            String      outPdf   = destinationFolder + "multiSelectByValueTest.pdf";
            String      cmpPdf   = sourceFolder + "cmp_multiSelectByValueTest.pdf";
            PdfDocument document = new PdfDocument(new PdfWriter(outPdf));

            document.AddNewPage();
            PdfAcroForm        form   = PdfAcroForm.GetAcroForm(document, true);
            PdfChoiceFormField choice = (PdfChoiceFormField)PdfFormField.CreateList(document, new Rectangle(336, 666,
                                                                                                            50, 80), "choice", "two", new String[] { "one", "two", "three", "four" }, null, null).SetBorderColor(ColorConstants
                                                                                                                                                                                                                 .BLACK);

            choice.SetMultiSelect(true);
            choice.SetListSelected(new String[] { "one", "three", "eins", "drei" });
            NUnit.Framework.Assert.AreEqual(new int[] { 0, 2 }, choice.GetIndices().ToIntArray());
            PdfArray values = (PdfArray)choice.GetValue();

            String[] valuesAsStrings = new String[values.Size()];
            for (int i = 0; i < values.Size(); i++)
            {
                valuesAsStrings[i] = values.GetAsString(i).ToUnicodeString();
            }
            NUnit.Framework.Assert.AreEqual(new String[] { "one", "three", "eins", "drei" }, valuesAsStrings);
            form.AddField(choice);
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
        }
Example #4
0
        public virtual void LongOptionWrappedIntoTwoLinesTest()
        {
            // TODO DEVSIX-4480 iText wraps the text into more than one line when generating listbox appearance
            String      outFileName = destinationFolder + "longOptionWrappedIntoTwoLinesTest.pdf";
            String      cmpFileName = sourceFolder + "cmp_longOptionWrappedIntoTwoLinesTest.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
            PdfAcroForm form        = PdfAcroForm.GetAcroForm(pdfDocument, true);
            String      shortOption = "Short option";
            String      longOption  = "Long long long long long long long option";

            String[]           options = new String[] { shortOption, longOption };
            Rectangle          rect    = new Rectangle(50, 650, 100, 100);
            PdfChoiceFormField choice  = PdfFormField.CreateList(pdfDocument, rect, "List", "Short option", options);

            form.AddField(choice);
            pdfDocument.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             ));
        }
        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 + "NotoSansGujarati-Regular.ttf",
                                                     PdfEncodings.IDENTITY_H, true);

            // 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 line1 = "\u0AB5\u0ABE\u0A88\u0AB8\u0AB0\u0AC9\u0AAF\u0AA8\u0AC7";

            // રાજ્યમાં
            String line2 = "\u0AB0\u0ABE\u0A9C\u0ACD\u0AAF\u0AAE\u0ABE\u0A82";

            // વસતા
            String line3 = "\u0AB5\u0AB8\u0AA4\u0ABE";

            // Create an array with text lines
            String[] options = new String[] { line1, line2, line3 };

            Rectangle rect = new Rectangle(50, 650, 120, 70);

            // Create choice form field with parameters and set values
            PdfChoiceFormField choice = PdfFormField.CreateList(pdfDocument, rect, "List", "Test", options);

            choice
            .SetMultiSelect(true)
            .SetFont(font)
            .SetFontSize(10);

            form.AddField(choice);

            pdfDocument.Close();
        }
Example #6
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 + "KhmerOS.ttf",
                                                     PdfEncodings.IDENTITY_H, true);

            // 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 line1 = "\u1797\u17B6\u179F\u17B6\u1781\u17D2\u1798\u17C2\u179A";

            // ឆ្នាំ១៩៤៨
            String line2 = "\u1786\u17D2\u1793\u17B6\u17C6\u17E1\u17E9\u17E4\u17E8";

            // បុព្វកថា
            String line3 = "\u1794\u17BB\u1796\u17D2\u179C\u1780\u1790\u17B6";

            // Create an array with text lines
            String[] options = new String[] { line1, line2, line3 };

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

            // Create choice form field with parameters and set values
            PdfChoiceFormField choice = PdfFormField.CreateList(pdfDocument, rect, "List", "Test", options);

            choice
            .SetMultiSelect(true)
            .SetFont(font)
            .SetFontSize(10);

            form.AddField(choice);

            pdfDocument.Close();
        }
Example #7
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 + "NotoSansDevanagari-Regular.ttf",
                                                     PdfEncodings.IDENTITY_H, true);

            // 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 line1 = "\u092A\u0915\u0935\u093E\u0928";

            // मरीया।
            String line2 = "\u092E\u0930\u0940\u092F\u093E\u0964";

            // जलदेव
            String line3 = "\u091C\u0932\u0926\u0947\u0935";

            // Create an array with text lines
            String[] options = new String[] { line1, line2, line3 };

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

            // Create choice form field with parameters and set values
            PdfChoiceFormField choice = PdfFormField.CreateList(pdfDocument, rect, "List", "Test", options);

            choice
            .SetMultiSelect(true)
            .SetFont(font)
            .SetFontSize(10);

            form.AddField(choice);

            pdfDocument.Close();
        }
        public virtual void PdfA1DocWithPdfA1ListFieldTest()
        {
            String  name         = "pdfA1DocWithPdfA1ListField";
            String  fileName     = destinationFolder + name + ".pdf";
            String  cmp          = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1ListField.pdf";
            PdfFont fontFreeSans = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", 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);
            PdfChoiceFormField f    = PdfFormField.CreateList(pdfDoc, new Rectangle(86, 556, 50, 200), "list", "9", new String
                                                              [] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }, fontFreeSans, conformanceLevel);

            f.SetValue("4");
            f.SetTopIndex(2);
            f.SetListSelected(new String[] { "3", "5" });
            form.AddField(f);
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, destinationFolder));
            NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName));
        }