Esempio n. 1
0
        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));
        }
        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);
            }
        }
Esempio n. 3
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();
        }
        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();
        }
Esempio n. 5
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();
        }