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_")); }
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 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)); }
public virtual void PdfA1DocWithPdfA1ButtonFieldTest() { String name = "pdfA1DocWithPdfA1ButtonField"; String fileName = destinationFolder + name + ".pdf"; String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1ButtonField.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); PdfFormField emptyField = PdfFormField.CreateEmptyField(pdfDoc, conformanceLevel).SetFieldName("empty"); emptyField.AddKid(PdfFormField.CreateButton(pdfDoc, new Rectangle(36, 756, 20, 20), PdfAnnotation.PRINT, conformanceLevel ).SetFieldName("button").SetValue("hello")); form.AddField(emptyField); pdfDoc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, destinationFolder)); NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName)); }
/// <exception cref="System.IO.IOException"/> public virtual void CreatePdf(String dest) { PdfDocument pdf = new PdfDocument(new PdfWriter(dest)); pdf.SetDefaultPageSize(PageSize.A4); Document doc = new Document(pdf); Paragraph title = new Paragraph("Application for employment").SetTextAlignment(TextAlignment.CENTER).SetFontSize(16); doc.Add(title); PdfAcroForm form = PdfAcroForm.GetAcroForm(doc.GetPdfDocument(), true); PdfTextFormField nameField = PdfTextFormField.CreateText(doc.GetPdfDocument(), new Rectangle(99, 753, 425, 15), "name", ""); nameField.SetRequired(true); form.AddField(nameField); doc.Close(); }
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); }
public virtual void FormFieldTest02() { String filename = destinationFolder + "formFieldTest02.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filename)); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); Rectangle rect = new Rectangle(210, 490, 150, 22); PdfTextFormField field = PdfFormField.CreateText(pdfDoc, rect, "fieldName", "some value"); form.AddField(field); pdfDoc.Close(); CompareTool compareTool = new CompareTool(); String errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_formFieldTest02.pdf", destinationFolder , "diff_"); if (errorMessage != null) { NUnit.Framework.Assert.Fail(errorMessage); } }
public virtual void CreatePDF(String dest) { // Create a pdf document along with a Document (default root layout element) instance PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest)); Document document = new Document(pdfDocument); PdfAcroForm form = PdfAcroForm.GetAcroForm(document.GetPdfDocument(), true); PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "NotoSerifHebrew-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 line1 = "\u05E8\u05E2\u0020\u05D5\u05DE\u05E8\u0020\u05D4\u05D9\u05D4\u0020\u05DC\u05D4\u05DD" + "\u0020\u05DC\u05D9\u05D4\u05D5\u05D3\u05D9\u05DD"; // כל String line2 = "\u05DB\u05DC"; // אדם String line3 = "\u05D0\u05D3\u05DD"; // Initialize the array with 3 lines of text. These lines will be used as combo box options String[] comboText = new String[] { line1, line2, line3 }; // Create a form field and apply the properties on it PdfFormField formField = PdfTextFormField.CreateComboBox(document.GetPdfDocument(), new Rectangle(50, 750, 125, 15), "test", line1, comboText); formField .SetBorderWidth(1) .SetJustification(2) .SetFont(font) .SetFontSizeAutoScale(); form.AddField(formField); document.Close(); }
public virtual void PdfA1DocWithPdfA1SignatureFieldTest() { String name = "pdfA1DocWithPdfA1SignatureField"; String fileName = destinationFolder + name + ".pdf"; String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1SignatureField.pdf"; PdfFont fontFreeSans = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", true); fontFreeSans.SetSubset(false); 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.CreateSignature(pdfDoc, conformanceLevel).SetFieldName("signature").SetFont(fontFreeSans ).SetFontSize(20)); 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 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 byte[] CreateForm() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfDocument pdfDoc = new PdfDocument(new PdfWriter(baos)); PdfFont font = PdfFontFactory.CreateFont(); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); Rectangle rect = new Rectangle(36, 770, 104, 36); PdfTextFormField textField = PdfFormField.CreateText(pdfDoc, rect, "text", "text", font, 20f); // Being set as true, the field can contain multiple lines of text; // if false, the field's text is restricted to a single line. textField.SetMultiline(true); form.AddField(textField); pdfDoc.Close(); return(baos.ToArray()); }
public virtual void AutoScaleFontSizeInFormFields() { String outPdf = destinationFolder + "autoScaleFontSizeInFormFields.pdf"; String cmpPdf = sourceFolder + "cmp_autoScaleFontSizeInFormFields.pdf"; PdfWriter writer = new PdfWriter(outPdf); PdfDocument pdfDoc = new PdfDocument(writer); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); PdfFormField field = PdfFormField.CreateText(pdfDoc, new Rectangle(36, 786, 80, 20), "name", "TestValueAndALittleMore" ); form.AddField(field.SetFontSizeAutoScale()); pdfDoc.Close(); CompareTool compareTool = new CompareTool(); String errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_"); if (errorMessage != null) { NUnit.Framework.Assert.Fail(errorMessage); } }
public virtual void CreatePDF(String dest) { // Create a pdf document along with a Document (default root layout element) instance PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest)); Document document = new Document(pdfDocument); PdfAcroForm form = PdfAcroForm.GetAcroForm(document.GetPdfDocument(), true); PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "NotoSansKannada-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 line1 = "\u0C97\u0CB0\u0CC1\u0CA1\u0CA8\u0C82\u0CA6\u0CA6\u0CBF"; // ಅಶೋಕನ String line2 = "\u0C85\u0CB6\u0CCB\u0C95\u0CA8"; // ಬ್ರಾಹ್ಮೀ String line3 = "\u0CAC\u0CCD\u0CB0\u0CBE\u0CB9\u0CCD\u0CAE\u0CC0"; // Initialize the array with 3 lines of text. These lines will be used as combo box options String[] comboText = new String[] { line1, line2, line3 }; // Create a form field and apply the properties on it PdfFormField formField = PdfTextFormField.CreateComboBox(document.GetPdfDocument(), new Rectangle(50, 750, 80, 15), "test", line1, comboText); formField .SetBorderWidth(1) .SetJustification(1) .SetFont(font) .SetFontSizeAutoScale(); form.AddField(formField); document.Close(); }
public virtual void CreatePDF(String dest) { // Create a pdf document along with a Document (default root layout element) instance PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest)); Document document = new Document(pdfDocument); PdfAcroForm form = PdfAcroForm.GetAcroForm(document.GetPdfDocument(), 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 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"; // Initialize the array with 3 lines of text. These lines will be used as combo box options String[] comboText = new String[] { line1, line2, line3 }; // Create a form field and apply the properties on it PdfFormField formField = PdfTextFormField.CreateComboBox(document.GetPdfDocument(), new Rectangle(50, 750, 50, 15), "test", line1, comboText); formField .SetBorderWidth(1) .SetJustification(1) .SetFont(font) .SetFontSizeAutoScale(); form.AddField(formField); document.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) { // Create a pdf document along with a Document (default root layout element) instance PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest)); Document document = new Document(pdfDocument); PdfAcroForm form = PdfAcroForm.GetAcroForm(document.GetPdfDocument(), true); PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "NotoSansGurmukhi-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 line1 = "\u0A38\u0A3E\u0A30\u0A47\u0020\u0A07\u0A28\u0A38\u0A3E\u0A28"; // ਜਦ String line2 = "\u0A1C\u0A26"; // ਪਰਿਵਾਰ String line3 = "\u0A2A\u0A30\u0A3F\u0A35\u0A3E\u0A30"; // Initialize the array with 3 lines of text. These lines will be used as combo box options String[] comboText = new String[] { line1, line2, line3 }; // Create a form field and apply the properties on it PdfFormField formField = PdfTextFormField.CreateComboBox(document.GetPdfDocument(), new Rectangle(50, 750, 150, 15), "test", line1, comboText); formField .SetBorderWidth(1) .SetJustification(1) .SetFont(font) .SetFontSizeAutoScale(); form.AddField(formField); document.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(); }
public virtual void CreatePDF(String dest) { // Create a pdf document along with a Document (default root layout element) instance PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest)); Document document = new Document(pdfDocument); PdfAcroForm form = PdfAcroForm.GetAcroForm(document.GetPdfDocument(), 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 line1 = "\u0E04\u0E33\u0E1B\u0E23\u0E32\u0E23\u0E20"; // สมาชิก String line2 = "\u0E2A\u0E21\u0E32\u0E0A\u0E34\u0E01"; // ความยุติธรรม String line3 = "\u0E04\u0E27\u0E32\u0E21\u0E22\u0E38\u0E15\u0E34\u0E18\u0E23\u0E23\u0E21"; // Initialize the array with 3 lines of text. These lines will be used as combo box options String[] comboText = new String[] { line1, line2, line3 }; // Create a form field and apply the properties on it PdfFormField formField = PdfTextFormField.CreateComboBox(document.GetPdfDocument(), new Rectangle(50, 750, 75, 15), "test", line1, comboText); formField .SetBorderWidth(1) .SetJustification(1) .SetFont(font) .SetFontSizeAutoScale(); form.AddField(formField); document.Close(); }
public virtual void CreatePDF(String dest) { // Create a pdf document along with a Document (default root layout element) instance PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest)); Document document = new Document(pdfDocument); PdfAcroForm form = PdfAcroForm.GetAcroForm(document.GetPdfDocument(), true); PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "NotoSansTelugu-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 line1 = "\u0C24\u0C46\u0C32\u0C41\u0C17\u0C41"; // గుణింతాలు String line2 = "\u0C17\u0C41\u0C23\u0C3F\u0C02\u0C24\u0C3E\u0C32\u0C41"; // ఆంధ్రుల గురించి String line3 = "\u0C06\u0C02\u0C27\u0C4D\u0C30\u0C41\u0C32\u0020\u0C17\u0C41\u0C30\u0C3F\u0C02\u0C1A\u0C3F"; // Initialize the array with 3 lines of text. These lines will be used as combo box options String[] comboText = new String[] { line1, line2, line3 }; // Create a form field and apply the properties on it PdfFormField formField = PdfTextFormField.CreateComboBox(document.GetPdfDocument(), new Rectangle(50, 750, 75, 15), "test", line1, comboText); formField .SetBorderWidth(1) .SetJustification(1) .SetFont(font) .SetFontSizeAutoScale(); form.AddField(formField); document.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 MultilineTextFieldWithAlignmentTest() { String outPdf = destinationFolder + "multilineTextFieldWithAlignment.pdf"; String cmpPdf = sourceFolder + "cmp_multilineTextFieldWithAlignment.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outPdf)); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); Rectangle rect = new Rectangle(210, 600, 150, 100); PdfTextFormField field = PdfFormField.CreateMultilineText(pdfDoc, rect, "fieldName", "some value\nsecond line\nthird" ); field.SetJustification(PdfTextFormField.ALIGN_RIGHT); form.AddField(field); pdfDoc.Close(); CompareTool compareTool = new CompareTool(); String errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_"); if (errorMessage != null) { NUnit.Framework.Assert.Fail(errorMessage); } }
public virtual void PdfA1DocWithPdfA1ChoiceFieldTest() { String name = "pdfA1DocWithPdfA1ChoiceField"; String fileName = destinationFolder + name + ".pdf"; String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1ChoiceField.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); PdfArray options = new PdfArray(); options.Add(new PdfString("Name")); options.Add(new PdfString("Surname")); form.AddField(PdfFormField.CreateChoice(pdfDoc, new Rectangle(36, 696, 100, 70), "choice", "1", options, 0 , fontFreeSans, conformanceLevel)); pdfDoc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, destinationFolder)); NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName)); }
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(); }
public virtual void FormFieldTest03() { PdfReader reader = new PdfReader(sourceFolder + "formFieldFile.pdf"); String filename = destinationFolder + "formFieldTest03.pdf"; PdfWriter writer = new PdfWriter(new FileStream(filename, FileMode.Create)); PdfDocument pdfDoc = new PdfDocument(reader, writer); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); PdfPage page = pdfDoc.GetFirstPage(); Rectangle rect = new Rectangle(210, 490, 150, 22); PdfTextFormField field = PdfFormField.CreateText(pdfDoc, rect, "TestField", "some value"); form.AddField(field, page); pdfDoc.Close(); CompareTool compareTool = new CompareTool(); String errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_formFieldTest03.pdf", destinationFolder , "diff_"); if (errorMessage != null) { NUnit.Framework.Assert.Fail(errorMessage); } }
public virtual void FlushedPagesTest() { String filename = destinationFolder + "flushedPagesTest.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filename)); pdfDoc.AddNewPage().Flush(); pdfDoc.AddNewPage().Flush(); pdfDoc.AddNewPage(); PdfTextFormField field = PdfFormField.CreateText(pdfDoc, new Rectangle(100, 100, 300, 20), "name", ""); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); form.AddField(field); pdfDoc.Close(); CompareTool compareTool = new CompareTool(); String errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_flushedPagesTest.pdf", destinationFolder , "diff_"); if (errorMessage != null) { NUnit.Framework.Assert.Fail(errorMessage); } }
public virtual void FormFieldTest04() { String filename = destinationFolder + "formFieldTest04.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "formFieldFile.pdf"), new PdfWriter(filename )); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); PdfPage page = pdfDoc.GetFirstPage(); Rectangle rect = new Rectangle(210, 490, 150, 22); PdfTextFormField field = PdfFormField.CreateText(pdfDoc, rect, "TestField", "some value in courier font", PdfFontFactory.CreateFont(StandardFonts.COURIER), 10); form.AddField(field, page); pdfDoc.Close(); CompareTool compareTool = new CompareTool(); String errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_formFieldTest04.pdf", destinationFolder , "diff_"); if (errorMessage != null) { NUnit.Framework.Assert.Fail(errorMessage); } }
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)); }
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 virtual void PdfA1bCheckFieldOnAppearanceTest() { String name = "pdfA1b_checkFieldOnAppearance"; 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); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); doc.AddNewPage(); PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true); PdfFormField chk = PdfFormField.CreateCheckBox(doc, new Rectangle(100, 500, 50, 50), "name", "On", PdfFormField .TYPE_CHECK, PdfAConformanceLevel.PDF_A_1B); chk.SetBorderColor(ColorConstants.BLACK); chk.SetBorderWidth(1); form.AddField(chk); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff )); }