|
| 1 | +using System; |
| 2 | +using System.IO; |
| 3 | +using iText.Forms; |
| 4 | +using iText.Forms.Fields; |
| 5 | +using iText.Kernel.Font; |
| 6 | +using iText.Kernel.Geom; |
| 7 | +using iText.Kernel.Pdf; |
| 8 | +using iText.Kernel.Utils; |
| 9 | +using iText.Test; |
| 10 | + |
| 11 | +namespace iText.Pdfa { |
| 12 | + public class PdfAPushbuttonfieldTest : ExtendedITextTest { |
| 13 | + public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext |
| 14 | + .CurrentContext.TestDirectory) + "/resources/itext/pdfa/"; |
| 15 | + |
| 16 | + public static readonly String cmpFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext |
| 17 | + .CurrentContext.TestDirectory) + "/resources/itext/pdfa/cmp/PdfAPushbuttonfieldTest/"; |
| 18 | + |
| 19 | + public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory |
| 20 | + + "/test/itext/pdfa/PdfAPushbuttonfieldTest/"; |
| 21 | + |
| 22 | + [NUnit.Framework.OneTimeSetUp] |
| 23 | + public static void BeforeClass() { |
| 24 | + CreateDestinationFolder(destinationFolder); |
| 25 | + } |
| 26 | + |
| 27 | + /// <exception cref="System.IO.IOException"/> |
| 28 | + /// <exception cref="System.Exception"/> |
| 29 | + [NUnit.Framework.Test] |
| 30 | + public virtual void PdfA1bButtonAppearanceTest() { |
| 31 | + String name = "pdfA1b_ButtonAppearanceTest"; |
| 32 | + String outPath = destinationFolder + name + ".pdf"; |
| 33 | + String cmpPath = cmpFolder + "cmp_" + name + ".pdf"; |
| 34 | + String diff = "diff_" + name + "_"; |
| 35 | + PdfWriter writer = new PdfWriter(outPath); |
| 36 | + Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); |
| 37 | + PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1" |
| 38 | + , @is); |
| 39 | + PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent); |
| 40 | + doc.SetTagged(); |
| 41 | + doc.GetCatalog().SetLang(new PdfString("en-US")); |
| 42 | + doc.AddNewPage(); |
| 43 | + PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true); |
| 44 | + Rectangle rect = new Rectangle(36, 626, 100, 40); |
| 45 | + PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", true); |
| 46 | + PdfFormField button = PdfFormField.CreatePushButton(doc, rect, "push button", "push", font, 12, PdfAConformanceLevel |
| 47 | + .PDF_A_1B); |
| 48 | + form.AddField(button); |
| 49 | + doc.Close(); |
| 50 | + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff |
| 51 | + )); |
| 52 | + } |
| 53 | + |
| 54 | + /// <exception cref="System.IO.IOException"/> |
| 55 | + /// <exception cref="System.Exception"/> |
| 56 | + [NUnit.Framework.Test] |
| 57 | + public virtual void PdfA1bButtonAppearanceRegenerateTest() { |
| 58 | + String name = "pdfA1b_ButtonAppearanceRegenerateTest"; |
| 59 | + String outPath = destinationFolder + name + ".pdf"; |
| 60 | + String cmpPath = cmpFolder + "cmp_" + name + ".pdf"; |
| 61 | + String diff = "diff_" + name + "_"; |
| 62 | + PdfWriter writer = new PdfWriter(outPath); |
| 63 | + Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); |
| 64 | + PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1" |
| 65 | + , @is); |
| 66 | + PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent); |
| 67 | + doc.SetTagged(); |
| 68 | + doc.GetCatalog().SetLang(new PdfString("en-US")); |
| 69 | + doc.AddNewPage(); |
| 70 | + PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true); |
| 71 | + Rectangle rect = new Rectangle(36, 626, 100, 40); |
| 72 | + PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", true); |
| 73 | + PdfFormField button = PdfFormField.CreatePushButton(doc, rect, "push button", "push", font, 12, PdfAConformanceLevel |
| 74 | + .PDF_A_1B); |
| 75 | + button.RegenerateField(); |
| 76 | + form.AddField(button); |
| 77 | + doc.Close(); |
| 78 | + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff |
| 79 | + )); |
| 80 | + } |
| 81 | + |
| 82 | + /// <exception cref="System.IO.IOException"/> |
| 83 | + /// <exception cref="System.Exception"/> |
| 84 | + [NUnit.Framework.Test] |
| 85 | + public virtual void PdfA1bButtonAppearanceSetValueTest() { |
| 86 | + String name = "pdfA1b_ButtonAppearanceSetValueTest"; |
| 87 | + String outPath = destinationFolder + name + ".pdf"; |
| 88 | + String cmpPath = cmpFolder + "cmp_" + name + ".pdf"; |
| 89 | + String diff = "diff_" + name + "_"; |
| 90 | + PdfWriter writer = new PdfWriter(outPath); |
| 91 | + Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); |
| 92 | + PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1" |
| 93 | + , @is); |
| 94 | + PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent); |
| 95 | + doc.SetTagged(); |
| 96 | + doc.GetCatalog().SetLang(new PdfString("en-US")); |
| 97 | + doc.AddNewPage(); |
| 98 | + PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true); |
| 99 | + Rectangle rect = new Rectangle(36, 626, 100, 40); |
| 100 | + PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", true); |
| 101 | + PdfFormField button = PdfFormField.CreatePushButton(doc, rect, "push button", "push", font, 12, PdfAConformanceLevel |
| 102 | + .PDF_A_1B); |
| 103 | + button.SetValue("button"); |
| 104 | + form.AddField(button); |
| 105 | + doc.Close(); |
| 106 | + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff |
| 107 | + )); |
| 108 | + } |
| 109 | + } |
| 110 | +} |
0 commit comments