public virtual void BorderWidthIndentMultilineTest() { String filename = destinationFolder + "borderWidthIndentMultilineTest.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filename)); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); PdfTextFormField field = PdfFormField.CreateMultilineText(pdfDoc, new Rectangle(100, 500, 400, 300), "multi" , "Does this text overlap the border? Well it shouldn't!"); field.SetFontSize(30); field.SetBorderColor(ColorConstants.RED); field.SetBorderWidth(50); form.AddField(field); PdfTextFormField field2 = PdfFormField.CreateMultilineText(pdfDoc, new Rectangle(100, 400, 400, 50), "multiAuto" , "Does this autosize text overlap the border? Well it shouldn't! Does it fit accurately though?"); field2.SetFontSize(0); field2.SetBorderColor(ColorConstants.RED); field2.SetBorderWidth(20); form.AddField(field2); pdfDoc.Close(); CompareTool compareTool = new CompareTool(); String errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_borderWidthIndentMultilineTest.pdf" , destinationFolder, "diff_"); if (errorMessage != null) { NUnit.Framework.Assert.Fail(errorMessage); } }
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_" )); }
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); // ಗರುಡನಂದದಿ String filedValue = "\u0C97\u0CB0\u0CC1\u0CA1\u0CA8\u0C82\u0CA6\u0CA6\u0CBF"; String fieldName = "Field name"; 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); // Create a form field and set some of the properties PdfFormField formField = PdfTextFormField.CreateText(document.GetPdfDocument(), new Rectangle(50, 750, 80, 25)); formField .SetValue(filedValue) .SetBorderWidth(2) .SetFont(font) .SetFontSize(10) .SetJustification(1) .SetFieldName(fieldName); 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 + "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 EncryptAes256Pdf2PermissionsTest01() { String filename = "encryptAes256Pdf2PermissionsTest01.pdf"; int permissions = EncryptionConstants.ALLOW_FILL_IN | EncryptionConstants.ALLOW_SCREENREADERS | EncryptionConstants .ALLOW_DEGRADED_PRINTING; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + filename, new WriterProperties().SetPdfVersion (PdfVersion.PDF_2_0).SetStandardEncryption(USER, OWNER, permissions, EncryptionConstants.ENCRYPTION_AES_256 ))); pdfDoc.GetDocumentInfo().SetMoreInfo(customInfoEntryKey, customInfoEntryValue); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); PdfTextFormField textField1 = PdfFormField.CreateText(pdfDoc, new Rectangle(100, 600, 200, 30), "Name", "Enter your name" ); form.AddField(textField1); PdfTextFormField textField2 = PdfFormField.CreateText(pdfDoc, new Rectangle(100, 550, 200, 30), "Surname", "Enter your surname"); form.AddField(textField2); PdfButtonFormField group = PdfFormField.CreateRadioGroup(pdfDoc, "Sex", "Male"); PdfFormField.CreateRadioButton(pdfDoc, new Rectangle(100, 530, 10, 10), group, "Male"); PdfFormField.CreateRadioButton(pdfDoc, new Rectangle(120, 530, 10, 10), group, "Female"); form.AddField(group); pdfDoc.Close(); CompareTool compareTool = new CompareTool(); String errorMessage = compareTool.CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename , destinationFolder, "diff_", USER, USER); if (errorMessage != null) { NUnit.Framework.Assert.Fail(errorMessage); } }
protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); PdfTextFormField field = PdfFormField.CreateText(pdfDoc, new Rectangle(36, 788, 523, 18), "myfile", ""); // If true is passed, then the text entered in the field will represent the pathname of a file // whose contents are to be submitted as the value of the field. field.SetFileSelect(true); // When the mouse is released inside the annotation's area (that's what PdfName.U stands for), // then the focus will be set on the "mytitle" field. field.SetAdditionalAction(PdfName.U, PdfAction.CreateJavaScript( "this.getField('myfile').browseForFileToSubmit();" + "this.getField('mytitle').setFocus();")); form.AddField(field); PdfTextFormField title = PdfFormField.CreateText(pdfDoc, new Rectangle(36, 752, 523, 18), "mytitle", ""); form.AddField(title); pdfDoc.Close(); }
protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); Document doc = new Document(pdfDoc); doc.Add(new Paragraph("This is a paragraph.\nForm field will be inserted after it")); float fieldHeight = 20; float fieldWidth = 100; // 1st method: calculate position and create form field, using document's root layout area Rectangle freeBBox = doc.GetRenderer().GetCurrentArea().GetBBox(); float top = freeBBox.GetTop(); PdfTextFormField field = PdfFormField.CreateText(pdfDoc, new Rectangle(freeBBox.GetLeft(), top - fieldHeight, fieldWidth, fieldHeight), "myField", "Value"); form.AddField(field); doc.Add(new AreaBreak()); // 2nd method: create field using custom renderer doc.Add(new Paragraph("This is another paragraph.\nForm field will be inserted right after it.")); doc.Add(new TextFieldLayoutElement().SetWidth(fieldWidth).SetHeight(fieldHeight)); doc.Add(new Paragraph("This paragraph follows the form field")); pdfDoc.Close(); }
public virtual void MultilineFormFieldTest() { String filename = destinationFolder + "multilineFormFieldTest.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filename)); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); PdfTextFormField name = PdfFormField.CreateMultilineText(pdfDoc, new Rectangle(150, 600, 277, 44), "fieldName" , "", null, 0); name.SetScroll(false); name.SetBorderColor(ColorConstants.GRAY); String itextLicence = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; name.SetValue(itextLicence); form.AddField(name); pdfDoc.Close(); CompareTool compareTool = new CompareTool(); String errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_multilineFormFieldTest.pdf" , destinationFolder, "diff_"); if (errorMessage != null) { NUnit.Framework.Assert.Fail(errorMessage); } }
public override void Draw(DrawContext drawContext) { PdfTextFormField field = PdfTextFormField.CreateText(drawContext.GetDocument(), GetOccupiedAreaBBox(), fieldName); PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true) .AddField(field); }
// ******************************************************************** // Fct: AddTestFields // // Descr: - // // Owner: erst // ******************************************************************** public static void AddTestFields(String src, String dest) { float XKoord = 0; float YKoord = 0; string CommentContent = String.Empty; PdfFont fontHelvetica = PdfFontFactory.CreateFont(StandardFonts.HELVETICA); try { PdfDocument scrPdf = new PdfDocument(new PdfReader(src)); PdfDocument destPdf = new PdfDocument(new PdfWriter(dest)); PageSize ps = PageSize.A4; destPdf.SetDefaultPageSize(ps); int lastPageNo = scrPdf.GetPageNumber(scrPdf.GetLastPage()); lastPageNo = 3; PdfPage srcPage = scrPdf.GetFirstPage(); PdfPage destPage = null; int annotNo = 0; for (int i = 1; i <= lastPageNo; i++) { srcPage = scrPdf.GetPage(i); annotNo = 1; // copy page destPdf.AddPage(srcPage.CopyTo(destPdf)); destPage = destPdf.GetPage(i); while (GetNextPdfComment(destPage, ref XKoord, ref YKoord, ref CommentContent, ref annotNo)) { PdfCanvas canvas = new PdfCanvas(destPage); canvas.BeginText().SetFontAndSize(fontHelvetica, 8).MoveText(XKoord, YKoord).ShowText(CommentContent).EndText(); //Add acroform PdfAcroForm form = PdfAcroForm.GetAcroForm(destPdf, true); //Create text field PdfTextFormField user1 = PdfTextFormField.CreateText(destPdf, new Rectangle(XKoord, YKoord - 10, 60, 8), CommentContent + "_User", "enter User", fontHelvetica, 6); PdfTextFormField date1 = PdfTextFormField.CreateText(destPdf, new Rectangle(XKoord, YKoord - 20, 60, 8), CommentContent + "_Date", "enter date", fontHelvetica, 6); form.AddField(user1); form.AddField(date1); } } scrPdf.Close(); destPdf.Close(); } catch (Exception ex) { throw ex; } finally { } }
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 override void Draw(DrawContext drawContext) { base.Draw(drawContext); PdfAcroForm form = PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true); PdfTextFormField field = PdfFormField.CreateText(drawContext.GetDocument(), occupiedArea.GetBBox(), "myField2", "Another Value"); form.AddField(field); }
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)); }
override public void Draw(DrawContext drawContext) { base.Draw(drawContext); iText.Kernel.Geom.Rectangle cuadro = GetOccupiedAreaBBox(); cuadro.MoveUp(margenExterior).MoveRight(margenExterior); cuadro.SetHeight(cuadro.GetHeight() - (margenExterior * 2)); cuadro.SetWidth(cuadro.GetWidth() - (margenExterior * 2)); PdfTextFormField field = PdfFormField.CreateText(drawContext.GetDocument(), cuadro, fieldName, valor); field.SetJustification(justificacion); field.SetVisibility(PdfFormField.VISIBLE); field.SetFontSize(fontSize); PdfAcroForm form = PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true); form.AddField(field); }
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_")); }
public virtual void WriteUtf8FieldNameAndValue() { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + "writeUtf8FieldNameAndValue.pdf")); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); PdfTextFormField field = PdfTextFormField.CreateText(pdfDoc, new Rectangle(99, 753, 425, 15), "", ""); field.SetFont(PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H)); // لا field.Put(PdfName.T, new PdfString("\u0644\u0627", PdfEncodings.UTF8)); // 福昕 福昕UTF8 field.Put(PdfName.V, new PdfString("\u798F\u6615 \u798F\u6615UTF8", PdfEncodings.UTF8)); field.RegenerateField(); form.AddField(field); pdfDoc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "writeUtf8FieldNameAndValue.pdf" , sourceFolder + "cmp_writeUtf8FieldNameAndValue.pdf", destinationFolder, "diffFieldNameAndValue_")); }
public virtual byte[] CreateForm() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfDocument pdfDoc = new PdfDocument(new PdfWriter(baos)); Rectangle rect = new Rectangle(36, 720, 108, 86); PdfTextFormField textFormField = PdfFormField.CreateText(pdfDoc, rect, FIELD_NAME, "text"); // Being set as true, the field can contain multiple lines of text; // if false, the field's text is restricted to a single line. textFormField.SetMultiline(true); PdfAcroForm.GetAcroForm(pdfDoc, true).AddField(textFormField); pdfDoc.Close(); return(baos.ToArray()); }
public virtual void AddFieldWithKidsTest() { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new ByteArrayOutputStream())); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); PdfFormField root = PdfFormField.CreateEmptyField(pdfDoc); root.SetFieldName("root"); PdfFormField child = PdfFormField.CreateEmptyField(pdfDoc); child.SetFieldName("child"); root.AddKid(child); PdfTextFormField text1 = PdfFormField.CreateText(pdfDoc, new Rectangle(100, 700, 200, 20), "text1", "test" ); child.AddKid(text1); form.AddField(root); NUnit.Framework.Assert.AreEqual(3, form.GetFormFields().Count); }
/// <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(); }
protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest)); PdfFormField personal = PdfFormField.CreateEmptyField(pdfDoc); personal.SetFieldName("personal"); PdfTextFormField name = PdfFormField.CreateText(pdfDoc, new Rectangle(36, 760, 108, 30), "name", ""); personal.AddKid(name); PdfTextFormField password = PdfFormField.CreateText(pdfDoc, new Rectangle(150, 760, 300, 30), "password", ""); personal.AddKid(password); PdfAcroForm.GetAcroForm(pdfDoc, true).AddField(personal, pdfDoc.GetFirstPage()); pdfDoc.Close(); }
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 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 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) { // 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 + "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 + "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 + "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 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); } }