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 virtual void NotFittingByHeightTest() { String filename = "notFittingByHeightTest.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + filename)); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); for (int i = 15; i <= 50; i += 15) { PdfFormField[] fields = new PdfFormField[] { PdfFormField.CreateMultilineText(pdfDoc, new Rectangle(100, 800 - i * 4, 150, i), "multi " + i, "MULTI"), PdfFormField.CreateText(pdfDoc, new Rectangle(300, 800 - i * 4, 150, i), "single " + i, "SINGLE") }; foreach (PdfFormField field in fields) { field.SetFontSize(40); field.SetBorderColor(ColorConstants.BLACK); form.AddField(field); } } pdfDoc.Close(); CompareTool compareTool = new CompareTool(); String errorMessage = compareTool.CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename , destinationFolder, "diff_"); if (errorMessage != null) { NUnit.Framework.Assert.Fail(errorMessage); } }
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 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 MultilineTextFieldRedundantSpacesAreTrimmedTest() { String filename = destinationFolder + "multilineTextFieldRedundantSpacesAreTrimmedTest.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filename)); pdfDoc.AddNewPage(); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); PdfPage page = pdfDoc.GetFirstPage(); Rectangle rect = new Rectangle(210, 490, 90, 200); PdfTextFormField field = PdfFormField.CreateMultilineText(pdfDoc, rect, "TestField", "before spaces after spaces" ); form.AddField(field, page); pdfDoc.Close(); CompareTool compareTool = new CompareTool(); String errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_multilineTextFieldRedundantSpacesAreTrimmedTest.pdf" , destinationFolder, "diff_"); if (errorMessage != null) { NUnit.Framework.Assert.Fail(errorMessage); } }