protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); Document doc = new Document(pdfDoc); PdfFont font = PdfFontFactory.CreateFont(StandardFonts.HELVETICA); Rectangle rect = new Rectangle(40, 788, 20, 18); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); // Radio buttons will be added to this radio group PdfButtonFormField radioGroup = PdfFormField.CreateRadioGroup(pdfDoc, "Language", ""); for (int page = 1; page <= LANGUAGES.Length; page++) { pdfDoc.AddNewPage(); // Create a radio button that is added to a radio group. PdfFormField field = PdfFormField.CreateRadioButton(pdfDoc, rect, radioGroup, LANGUAGES[page - 1]); field.SetBorderWidth(1); field.SetBorderColor(ColorConstants.BLACK); // Method specifies on which page the form field's widget must be shown. field.SetPage(page); doc.ShowTextAligned(new Paragraph(LANGUAGES[page - 1]).SetFont(font).SetFontSize(18), 70, 786, page, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0); } form.AddField(radioGroup); doc.Close(); }
public virtual void PdfA1aCheckFieldOffAppearanceTest() { String name = "pdfA1a_checkFieldOffAppearance"; 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_1A, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); doc.SetTagged(); doc.GetCatalog().SetLang(new PdfString("en-US")); doc.AddNewPage(); PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true); PdfFormField chk = PdfFormField.CreateCheckBox(doc, new Rectangle(100, 500, 50, 50), "name", "Off", PdfFormField .TYPE_CHECK, PdfAConformanceLevel.PDF_A_1A); chk.SetBorderColor(ColorConstants.BLACK); chk.SetBorderWidth(1); form.AddField(chk); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff )); }
public virtual void BorderStyleInCreatedFormFieldsTest() { String outPdf = destinationFolder + "borderStyleInCreatedFormFields.pdf"; String cmpPdf = sourceFolder + "cmp_borderStyleInCreatedFormFields.pdf"; using (PdfDocument doc = new PdfDocument(new PdfWriter(outPdf))) { PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true); PdfFormField formField1 = PdfTextFormField.CreateText(doc, new Rectangle(100, 600, 100, 50), "firstField", "Hello, iText!"); formField1.GetWidgets()[0].SetBorderStyle(PdfAnnotation.STYLE_BEVELED); formField1.SetBorderWidth(2).SetBorderColor(ColorConstants.BLUE); PdfFormField formField2 = PdfTextFormField.CreateText(doc, new Rectangle(100, 500, 100, 50), "secondField" , "Hello, iText!"); formField2.GetWidgets()[0].SetBorderStyle(PdfAnnotation.STYLE_UNDERLINE); formField2.SetBorderWidth(2).SetBorderColor(ColorConstants.BLUE); PdfFormField formField3 = PdfTextFormField.CreateText(doc, new Rectangle(100, 400, 100, 50), "thirdField", "Hello, iText!"); formField3.GetWidgets()[0].SetBorderStyle(PdfAnnotation.STYLE_INSET); formField3.SetBorderWidth(2).SetBorderColor(ColorConstants.BLUE); form.AddField(formField1); form.AddField(formField2); form.AddField(formField3); form.FlattenFields(); } NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder)); }
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 + "NotoNaskhArabic-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 = "\u0641\u064A\u0020\u0627\u0644\u0642\u064A\u0627\u0645\u0020\u0628\u0646\u0634\u0627\u0637"; // Initialize the array with 3 lines of text. These lines will be used as combo box options String[] comboText = new String[] { line1, line1, line1 }; // Create a form field and apply the properties on it PdfFormField formField = PdfTextFormField.CreateComboBox(document.GetPdfDocument(), new Rectangle(50, 750, 100, 25), "test", line1, comboText); formField .SetBorderWidth(1) .SetJustification(2) .SetFont(font) .SetFontSizeAutoScale(); form.AddField(formField); document.Close(); }
public virtual void TextStartsAfterFieldBorderTest() { // TODO DEVSIX-4809 text in form filed with borders must start after border String outPdf = destinationFolder + "textStartsAfterFieldBorderTest.pdf"; String cmpPdf = sourceFolder + "cmp_textStartsAfterFieldBorderTest.pdf"; using (PdfDocument doc = new PdfDocument(new PdfWriter(outPdf))) { PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true); PdfFormField insetFormField = PdfTextFormField.CreateText(doc, new Rectangle(90, 600, 200, 100), "insetFormField" ); insetFormField.GetWidgets()[0].SetBorderStyle(PdfName.I); insetFormField.SetBorderWidth(15f).SetBorderColor(DeviceRgb.RED).SetValue("Text after border").RegenerateField (); PdfFormField solidFormField = PdfTextFormField.CreateText(doc, new Rectangle(300, 600, 200, 100), "solidFormField" ); solidFormField.GetWidgets()[0].SetBorderStyle(PdfName.S); solidFormField.SetBorderWidth(15f).SetBorderColor(DeviceRgb.RED).SetValue("Text after border").RegenerateField (); PdfFormField underlineFormField = PdfTextFormField.CreateText(doc, new Rectangle(90, 450, 200, 100), "underlineFormField" ); underlineFormField.GetWidgets()[0].SetBorderStyle(PdfName.U); underlineFormField.SetBorderWidth(15f).SetBorderColor(DeviceRgb.RED).SetValue("Text after border").RegenerateField (); PdfFormField simpleFormField = PdfTextFormField.CreateText(doc, new Rectangle(300, 450, 200, 100), "formField1" ); simpleFormField.SetBorderWidth(15f); simpleFormField.SetValue("Text after border").RegenerateField(); form.AddField(insetFormField); form.AddField(solidFormField); form.AddField(underlineFormField); form.AddField(simpleFormField); } NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_" )); }
/// <summary>Applies the default field properties.</summary> /// <param name="inputField">the input field</param> internal virtual void ApplyDefaultFieldProperties(PdfFormField inputField) { inputField.GetWidgets()[0].SetHighlightMode(PdfAnnotation.HIGHLIGHT_NONE); inputField.SetBorderWidth(0); TransparentColor color = GetPropertyAsTransparentColor(Property.FONT_COLOR); if (color != null) { inputField.SetColor(color.GetColor()); } }
public virtual void DashedBorderWithBackgroundTest() { String outPdf = destinationFolder + "dashedBorderWithBackground.pdf"; String cmpPdf = sourceFolder + "cmp_dashedBorderWithBackground.pdf"; using (PdfDocument doc = new PdfDocument(new PdfWriter(outPdf))) { PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true); PdfFormField formField = PdfTextFormField.CreateText(doc, new Rectangle(100, 600, 200, 100), "formField"); formField.GetWidgets()[0].SetBorderStyle(PdfName.D); formField.SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).SetBackgroundColor(DeviceRgb.GREEN); formField.RegenerateField(); form.AddField(formField); } NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder)); }
public virtual void FormFieldFilledWithStringTest() { String value = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + "formFieldWithStringTest.pdf")); PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "NotoSansCJKtc-Light.otf", PdfEncodings.IDENTITY_H ); PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(pdfDoc, true); PdfFormField form = PdfTextFormField.CreateMultilineText(pdfDoc, new Rectangle(59, 715, 127, 69), "field", "", font, 10f); form.SetBorderWidth(2).SetBorderColor(ColorConstants.BLACK).SetValue(value); acroForm.AddField(form); pdfDoc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "formFieldWithStringTest.pdf" , sourceFolder + "cmp_formFieldWithStringTest.pdf", destinationFolder, "diff_")); }
private void AddCheckBox(PdfDocument pdfDoc, float fontSize, float yPos, float checkBoxW, PdfFormField checkBox ) { PdfPage page = pdfDoc.GetFirstPage(); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); if (fontSize >= 0) { checkBox.SetFontSize(fontSize); } checkBox.SetBorderWidth(1); checkBox.SetBorderColor(ColorConstants.BLACK); form.AddField(checkBox, page); PdfCanvas canvas = new PdfCanvas(page); canvas.SaveState().BeginText().MoveText(50 + checkBoxW + 10, yPos).SetFontAndSize(PdfFontFactory.CreateFont (), 12).ShowText("okay?").EndText().RestoreState(); }
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 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) { // 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) { // 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 FormFieldBordersTest() { String outPdf = destinationFolder + "formFieldBorders.pdf"; String cmpPdf = sourceFolder + "cmp_formFieldBorders.pdf"; using (PdfDocument doc = new PdfDocument(new PdfWriter(outPdf))) { PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true); PdfFormField simpleField = PdfTextFormField.CreateText(doc, new Rectangle(300, 300, 200, 100), "simpleField" ); simpleField.RegenerateField(); PdfFormField insetField = PdfTextFormField.CreateText(doc, new Rectangle(50, 600, 200, 100), "insetField"); insetField.GetWidgets()[0].SetBorderStyle(PdfName.I); insetField.SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).RegenerateField(); PdfFormField underlineField = PdfTextFormField.CreateText(doc, new Rectangle(300, 600, 200, 100), "underlineField" ); underlineField.GetWidgets()[0].SetBorderStyle(PdfName.U); underlineField.SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).RegenerateField(); PdfFormField solidField = PdfTextFormField.CreateText(doc, new Rectangle(50, 450, 200, 100), "solidField"); solidField.GetWidgets()[0].SetBorderStyle(PdfName.S); solidField.SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).RegenerateField(); PdfFormField dashField = PdfTextFormField.CreateText(doc, new Rectangle(300, 450, 200, 100), "dashField"); dashField.GetWidgets()[0].SetBorderStyle(PdfName.D); dashField.SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).RegenerateField(); PdfFormField beveledField = PdfTextFormField.CreateText(doc, new Rectangle(50, 300, 200, 100), "beveledField" ); beveledField.GetWidgets()[0].SetBorderStyle(PdfName.B); beveledField.SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).RegenerateField(); form.AddField(simpleField); form.AddField(insetField); form.AddField(underlineField); form.AddField(solidField); form.AddField(dashField); form.AddField(beveledField); } NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder)); }