|
1 | 1 | /*
|
2 | 2 | This file is part of the iText (R) project.
|
3 |
| -Copyright (c) 1998-2023 Apryse Group NV |
| 3 | +Copyright (c) 1998-2024 Apryse Group NV |
4 | 4 | Authors: Apryse Software.
|
5 | 5 |
|
6 | 6 | This program is offered under a commercial and under the AGPL license.
|
@@ -36,8 +36,10 @@ You should have received a copy of the GNU Affero General Public License
|
36 | 36 | using iText.Layout;
|
37 | 37 | using iText.Layout.Element;
|
38 | 38 | using iText.Layout.Properties;
|
| 39 | +using iText.Pdfa; |
39 | 40 | using iText.Test;
|
40 | 41 | using iText.Test.Attributes;
|
| 42 | +using iText.Test.Pdfa; |
41 | 43 |
|
42 | 44 | namespace iText.Html2pdf {
|
43 | 45 | [NUnit.Framework.Category("IntegrationTest")]
|
@@ -340,6 +342,40 @@ public virtual void HtmlToElementsSvgObjectTest() {
|
340 | 342 | NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
|
341 | 343 | }
|
342 | 344 |
|
| 345 | + [NUnit.Framework.Test] |
| 346 | + public virtual void HtmlToElementsFormTest() { |
| 347 | + FileStream htmlFile = new FileStream(sourceFolder + "formelements.html", FileMode.Open, FileAccess.Read); |
| 348 | + String cmpPdf = sourceFolder + "cmp_htmlToElementsForms.pdf"; |
| 349 | + String outPdf = destinationFolder + "htmlToElementsForms.pdf"; |
| 350 | + IList<IElement> elements = HtmlConverter.ConvertToElements(htmlFile, new ConverterProperties().SetBaseUri( |
| 351 | + sourceFolder)); |
| 352 | + using (Document document = new Document(new PdfDocument(new PdfWriter(outPdf)))) { |
| 353 | + foreach (IElement element in elements) { |
| 354 | + document.Add((IBlockElement)element); |
| 355 | + } |
| 356 | + } |
| 357 | + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder)); |
| 358 | + } |
| 359 | + |
| 360 | + [NUnit.Framework.Test] |
| 361 | + public virtual void HtmlToElementsToPDFATest() { |
| 362 | + FileStream htmlFile = new FileStream(sourceFolder + "formelements.html", FileMode.Open, FileAccess.Read); |
| 363 | + String cmpPdf = sourceFolder + "cmp_htmlToElementsFormsPDFA.pdf"; |
| 364 | + String outPdf = destinationFolder + "htmlToElementsFormsPDFA.pdf"; |
| 365 | + PdfOutputIntent intent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", new |
| 366 | + FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read)); |
| 367 | + IList<IElement> elements = HtmlConverter.ConvertToElements(htmlFile, new ConverterProperties().SetBaseUri( |
| 368 | + sourceFolder).SetCreateAcroForm(true).SetPdfAConformanceLevel(PdfAConformanceLevel.PDF_A_4)); |
| 369 | + using (Document document = new Document(new PdfADocument(new PdfWriter(outPdf, new WriterProperties().SetPdfVersion |
| 370 | + (PdfVersion.PDF_2_0)), PdfAConformanceLevel.PDF_A_4, intent))) { |
| 371 | + foreach (IElement element in elements) { |
| 372 | + document.Add((IBlockElement)element); |
| 373 | + } |
| 374 | + } |
| 375 | + NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf)); |
| 376 | + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder)); |
| 377 | + } |
| 378 | + |
343 | 379 | private static void AddElementsToDocument(Document document, IList<IElement> elements) {
|
344 | 380 | foreach (IElement elem in elements) {
|
345 | 381 | if (elem is IBlockElement) {
|
|
0 commit comments