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)); }
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); }
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 MultiSelectByIndexOutOfBoundsTest() { String srcPdf = sourceFolder + "multiSelectTest.pdf"; String outPdf = destinationFolder + "multiSelectByIndexOutOfBoundsTest.pdf"; String cmpPdf = sourceFolder + "cmp_multiSelectByIndexOutOfBoundsTest.pdf"; PdfDocument document = new PdfDocument(new PdfReader(srcPdf), new PdfWriter(outPdf)); PdfAcroForm form = PdfAcroForm.GetAcroForm(document, false); PdfChoiceFormField field = (PdfChoiceFormField)form.GetField("choice"); field.SetListSelected(new int[] { 5 }); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder)); }
public virtual void CorruptedOptAndValueSetToNullTest() { String srcPdf = sourceFolder + "corruptedOptAndValueSetToNullTest.pdf"; String outPdf = destinationFolder + "corruptedOptAndValueSetToNullTest.pdf"; String cmpPdf = sourceFolder + "cmp_corruptedOptAndValueSetToNullTest.pdf"; PdfDocument document = new PdfDocument(new PdfReader(srcPdf), new PdfWriter(outPdf)); PdfAcroForm form = PdfAcroForm.GetAcroForm(document, false); PdfChoiceFormField choice = (PdfChoiceFormField)form.GetField("choice"); choice.SetListSelected(new String[] { null, "three" }); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder)); }
public virtual void TopIndexTest() { String srcPdf = sourceFolder + "choiceFieldNotFittingTest.pdf"; String outPdf = destinationFolder + "topIndexTest.pdf"; String cmpPdf = sourceFolder + "cmp_topIndexTest.pdf"; PdfDocument document = new PdfDocument(new PdfReader(srcPdf), new PdfWriter(outPdf)); PdfAcroForm form = PdfAcroForm.GetAcroForm(document, false); PdfChoiceFormField field = (PdfChoiceFormField)form.GetField("choice"); field.SetListSelected(new String[] { "seven" }); int topIndex = field.GetIndices().GetAsNumber(0).IntValue(); field.SetTopIndex(topIndex); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder)); }
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(); }
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 + "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)); }