Skip to content

Commit 2fef42a

Browse files
introfogiText-CI
authored andcommitted
Move all logic from PdfA/UaDocuments to pluggalbe mechanisms into PdfDocument
DEVSIX-8623 Autoported commit. Original commit hash: [2564cb2e1]
1 parent 9835be3 commit 2fef42a

File tree

5 files changed

+9
-62
lines changed

5 files changed

+9
-62
lines changed

itext.tests/itext.html2pdf.tests/itext/html2pdf/HtmlConverterPdfA4Test.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ You should have received a copy of the GNU Affero General Public License
2828
using iText.Pdfa;
2929
using iText.Pdfa.Checker;
3030
using iText.Pdfa.Exceptions;
31+
using iText.Pdfa.Logs;
3132
using iText.Test;
3233
using iText.Test.Attributes;
3334

@@ -85,24 +86,24 @@ public virtual void ConvertToPdfA4ColorsTest() {
8586
}
8687

8788
[NUnit.Framework.Test]
89+
[LogMessage(PdfALogMessageConstant.WRITER_PROPERTIES_PDF_VERSION_WAS_OVERRIDDEN, LogLevel = LogLevelConstants
90+
.WARN)]
8891
public virtual void ConvertToPdfA4MetaDataInvalidTest() {
8992
String sourceHtml = SOURCE_FOLDER + "simple.html";
9093
String destinationPdf = DESTINATION_FOLDER + "pdfA4InvalidMetadataTest.pdf";
94+
String cmpPdf = SOURCE_FOLDER + "cmp_pdfA4InvalidMetadataTest.pdf";
9195
ConverterProperties converterProperties = new ConverterProperties();
9296
converterProperties.SetPdfAConformance(PdfAConformance.PDF_A_4);
9397
converterProperties.SetDocumentOutputIntent(new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
9498
, new FileStream(SOURCE_FOLDER + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read)));
9599
converterProperties.SetBaseUri("no_link");
96100
using (FileStream fOutput = new FileStream(sourceHtml, FileMode.Open, FileAccess.Read)) {
97-
using (PdfWriter pdfWriter = new PdfWriter(destinationPdf)) {
98-
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => {
99-
HtmlConverter.ConvertToPdf(fOutput, pdfWriter, converterProperties);
100-
}
101-
);
102-
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfaExceptionMessageConstant.THE_FILE_HEADER_SHALL_CONTAIN_RIGHT_PDF_VERSION
103-
, "2"), e.Message);
101+
using (PdfWriter pdfWriter = new PdfWriter(destinationPdf, new WriterProperties().SetPdfVersion(PdfVersion
102+
.PDF_1_7))) {
103+
HtmlConverter.ConvertToPdf(fOutput, pdfWriter, converterProperties);
104104
}
105105
}
106+
HtmlConverterTest.CompareAndCheckCompliance(destinationPdf, cmpPdf);
106107
}
107108

108109
[NUnit.Framework.Test]

itext.tests/itext.html2pdf.tests/itext/html2pdf/HtmlConverterTest.cs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ You should have received a copy of the GNU Affero General Public License
2222
*/
2323
using System;
2424
using System.IO;
25-
using iText.Commons.Utils;
2625
using iText.Html2pdf.Exceptions;
2726
using iText.Kernel.Pdf;
2827
using iText.Kernel.Utils;
2928
using iText.Layout;
30-
using iText.Pdfa;
31-
using iText.Pdfa.Exceptions;
3229
using iText.Test;
3330
using iText.Test.Pdfa;
3431

@@ -88,44 +85,6 @@ public virtual void CannotConvertHtmlToDocumentInReadingModeTest() {
8885
);
8986
}
9087

91-
[NUnit.Framework.Test]
92-
public virtual void ConvertHtmlToDocumentIncorrectConverterPropertiesTest() {
93-
String sourceHtml = SOURCE_FOLDER + "simple.html";
94-
String destinationPdf = DESTINATION_FOLDER + "simpleA4.pdf";
95-
ConverterProperties converterProperties = new ConverterProperties();
96-
converterProperties.SetPdfAConformance(PdfAConformance.PDF_A_3U);
97-
converterProperties.SetDocumentOutputIntent(new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
98-
, new FileStream(SOURCE_FOLDER + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read)));
99-
PdfADocument pdfDocument = new PdfADocument(new PdfWriter(destinationPdf), PdfAConformance.PDF_A_4E, new PdfOutputIntent
100-
("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(SOURCE_FOLDER + "sRGB Color Space Profile.icm"
101-
, FileMode.Open, FileAccess.Read)));
102-
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => {
103-
HtmlConverter.ConvertToPdf(sourceHtml, pdfDocument, converterProperties);
104-
}
105-
);
106-
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfaExceptionMessageConstant.THE_FILE_HEADER_SHALL_CONTAIN_RIGHT_PDF_VERSION
107-
, "2"), e.Message);
108-
}
109-
110-
[NUnit.Framework.Test]
111-
public virtual void ConvertHtmlToDocumentWithDifferentColorProfileTest() {
112-
String sourceHtml = SOURCE_FOLDER + "simple.html";
113-
String destinationPdf = DESTINATION_FOLDER + "simpleA4.pdf";
114-
ConverterProperties converterProperties = new ConverterProperties();
115-
converterProperties.SetPdfAConformance(PdfAConformance.PDF_A_4E);
116-
converterProperties.SetDocumentOutputIntent(new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
117-
, new FileStream(SOURCE_FOLDER + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read)));
118-
PdfADocument pdfDocument = new PdfADocument(new PdfWriter(destinationPdf), PdfAConformance.PDF_A_4E, new PdfOutputIntent
119-
("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(SOURCE_FOLDER + "USWebUncoated.icc"
120-
, FileMode.Open, FileAccess.Read)));
121-
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => {
122-
HtmlConverter.ConvertToPdf(sourceHtml, pdfDocument, converterProperties);
123-
}
124-
);
125-
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfaExceptionMessageConstant.THE_FILE_HEADER_SHALL_CONTAIN_RIGHT_PDF_VERSION
126-
, "2"), e.Message);
127-
}
128-
12988
private static PdfDocument CreateTempDoc() {
13089
MemoryStream outputStream = new MemoryStream();
13190
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outputStream));

itext/itext.html2pdf/itext/html2pdf/HtmlConverter.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ namespace iText.Html2pdf {
6161
/// instance.
6262
/// </remarks>
6363
public class HtmlConverter {
64-
private static readonly IList<PdfAConformance> pdf2Conformances = new List<PdfAConformance>(JavaUtil.ArraysAsList
65-
(PdfAConformance.PDF_A_4, PdfAConformance.PDF_A_4E, PdfAConformance.PDF_A_4F));
66-
6764
/// <summary>Instantiates a new HtmlConverter instance.</summary>
6865
private HtmlConverter() {
6966
}
@@ -109,11 +106,6 @@ public static void ConvertToPdf(String html, Stream pdfStream) {
109106
/// instance
110107
/// </param>
111108
public static void ConvertToPdf(String html, Stream pdfStream, ConverterProperties converterProperties) {
112-
if (converterProperties != null && pdf2Conformances.Contains(converterProperties.GetPdfAConformance())) {
113-
ConvertToPdf(html, new PdfWriter(pdfStream, new WriterProperties().SetPdfVersion(PdfVersion.PDF_2_0)), converterProperties
114-
);
115-
return;
116-
}
117109
ConvertToPdf(html, new PdfWriter(pdfStream), converterProperties);
118110
}
119111

@@ -315,11 +307,6 @@ public static void ConvertToPdf(Stream htmlStream, Stream pdfStream) {
315307
/// </param>
316308
public static void ConvertToPdf(Stream htmlStream, Stream pdfStream, ConverterProperties converterProperties
317309
) {
318-
if (converterProperties != null && pdf2Conformances.Contains(converterProperties.GetPdfAConformance())) {
319-
ConvertToPdf(htmlStream, new PdfWriter(pdfStream, new WriterProperties().SetPdfVersion(PdfVersion.PDF_2_0)
320-
), converterProperties);
321-
return;
322-
}
323310
ConvertToPdf(htmlStream, new PdfWriter(pdfStream), converterProperties);
324311
}
325312

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
05f7aade95c3730debd74a5d6b9a470a36c6f418
1+
2564cb2e17ed1d5d4b91cfa0cbf2ceaa971b37e9

0 commit comments

Comments
 (0)