You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
2.2 KiB

  1. using System;
  2. using iText.Forms.Fields;
  3. using iText.Kernel.Geom;
  4. using iText.Kernel.Pdf;
  5. using iText.Kernel.Utils;
  6. using iText.Test;
  7. namespace iText.Forms {
  8. [NUnit.Framework.Category("IntegrationTest")]
  9. public class RectangleIntegrationTest {
  10. private static readonly String DESTINATION_FOLDER = TestUtil.GetOutputPath() + "/forms/RectangleTest/";
  11. private static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
  12. .CurrentContext.TestDirectory) + "/resources/itext/forms/RectangleTest/";
  13. [NUnit.Framework.OneTimeSetUp]
  14. public static void InitDestinationFolder() {
  15. ITextTest.CreateOrClearDestinationFolder(DESTINATION_FOLDER);
  16. }
  17. [NUnit.Framework.Test]
  18. public virtual void CreatePdfWithSignatureFields() {
  19. String outPdf = DESTINATION_FOLDER + "RectangleTest.pdf";
  20. String cmpPdf = SOURCE_FOLDER + "cmp_RectangleTest.pdf";
  21. PdfWriter writer = new PdfWriter(DESTINATION_FOLDER + "RectangleTest.pdf");
  22. PdfDocument pdfDoc = new PdfDocument(writer);
  23. PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
  24. for (int i = 0; i <= 3; i++) {
  25. int rotation = 90 * i;
  26. PdfPage page = pdfDoc.AddNewPage();
  27. page.SetRotation(rotation);
  28. float x = 20;
  29. float y = 500;
  30. float width = 100;
  31. float height = 50;
  32. float spacing = 50;
  33. for (int j = 1; j <= 3; j++) {
  34. Rectangle rect = new Rectangle(x, y, width, height);
  35. String fieldName = "page" + i + "_Signature" + j;
  36. PdfFormField signatureField = new SignatureFormFieldBuilder(pdfDoc, fieldName).SetPage(page).SetWidgetRectangle
  37. (rect).CreateSignature();
  38. form.AddField(signatureField);
  39. x += width + spacing;
  40. }
  41. }
  42. pdfDoc.Close();
  43. NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_"
  44. ));
  45. }
  46. }
  47. }