Skip to content

Commit 655cb6c

Browse files
committed
Check whether embedded fonts define all glyphs referenced for rendering for PDF/UA-2
DEVSIX-8997
1 parent 34cfc1e commit 655cb6c

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/test/java/com/itextpdf/html2pdf/HtmlConverterPdfUA1UA2Test.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ public void unsupportedGlyphTest() throws IOException, InterruptedException {
131131
String destinationPdfUa1 = DESTINATION_FOLDER + "unsupportedGlyphUa1.pdf";
132132
String destinationPdfUa2 = DESTINATION_FOLDER + "unsupportedGlyphUa2.pdf";
133133

134-
String expectedUa1Message = MessageFormatUtil.format(
134+
String expectedUaMessage = MessageFormatUtil.format(
135135
PdfUAExceptionMessageConstants.GLYPH_IS_NOT_DEFINED_OR_WITHOUT_UNICODE, '中');
136136

137-
convertToUa1AndCheckCompliance(sourceHtml, destinationPdfUa1, cmpPdfUa1, false, expectedUa1Message);
138-
convertToUa2AndCheckCompliance(sourceHtml, destinationPdfUa2, cmpPdfUa2, false);
137+
convertToUa1AndCheckCompliance(sourceHtml, destinationPdfUa1, cmpPdfUa1, false, expectedUaMessage);
138+
convertToUa2AndCheckCompliance(sourceHtml, destinationPdfUa2, cmpPdfUa2, false, expectedUaMessage);
139139
}
140140

141141
@Test
@@ -247,9 +247,8 @@ public void inputWithTitleTagTest() throws IOException, InterruptedException {
247247
ConverterProperties converterProperties = new ConverterProperties();
248248
converterProperties.setCreateAcroForm(true);
249249

250-
convertToUa1AndCheckCompliance(sourceHtml, destinationPdfUa1, cmpPdfUa1, converterProperties, true,
251-
null);
252-
convertToUa2AndCheckCompliance(sourceHtml, destinationPdfUa2, cmpPdfUa2, converterProperties, true);
250+
convertToUa1AndCheckCompliance(sourceHtml, destinationPdfUa1, cmpPdfUa1, converterProperties, true, null);
251+
convertToUa2AndCheckCompliance(sourceHtml, destinationPdfUa2, cmpPdfUa2, converterProperties, true, null);
253252
}
254253

255254
@Test
@@ -385,7 +384,15 @@ private void convertToUa1AndCheckCompliance(String sourceHtml, String destinatio
385384
private void convertToUa2AndCheckCompliance(String sourceHtml, String destinationPdf, String cmpPdf,
386385
boolean isExpectedOk)
387386
throws IOException, InterruptedException {
388-
convertToUa2AndCheckCompliance(sourceHtml, destinationPdf, cmpPdf, new ConverterProperties(), isExpectedOk);
387+
convertToUa2AndCheckCompliance(sourceHtml, destinationPdf, cmpPdf, new ConverterProperties(), isExpectedOk,
388+
null);
389+
}
390+
391+
private void convertToUa2AndCheckCompliance(String sourceHtml, String destinationPdf, String cmpPdf,
392+
boolean isExpectedOk, String expectedErrorMessage)
393+
throws IOException, InterruptedException {
394+
convertToUa2AndCheckCompliance(sourceHtml, destinationPdf, cmpPdf, new ConverterProperties(), isExpectedOk,
395+
expectedErrorMessage);
389396
}
390397

391398
private void convertToUa1AndCheckCompliance(String sourceHtml, String destinationPdf, String cmpPdf,
@@ -418,7 +425,8 @@ private void convertToUa1AndCheckCompliance(String sourceHtml, String destinatio
418425
}
419426

420427
private void convertToUa2AndCheckCompliance(String sourceHtml, String destinationPdf, String cmpPdf,
421-
ConverterProperties converterProperties, boolean isExpectedOk)
428+
ConverterProperties converterProperties, boolean isExpectedOk,
429+
String expectedErrorMessage)
422430
throws IOException, InterruptedException {
423431
PdfDocument pdfDocument = new PdfUADocument(new PdfWriter(destinationPdf, new WriterProperties().setPdfVersion(
424432
PdfVersion.PDF_2_0)), new PdfUAConfig(PdfUAConformance.PDF_UA_2, "simple doc", "en-US"));
@@ -434,8 +442,15 @@ private void convertToUa2AndCheckCompliance(String sourceHtml, String destinatio
434442
converterPropertiesCopy.setFontProvider(fontProvider);
435443
converterPropertiesCopy.setBaseUri(SOURCE_FOLDER);
436444
converterPropertiesCopy.setOutlineHandler(OutlineHandler.createStandardHandler());
437-
HtmlConverter.convertToPdf(new FileInputStream(sourceHtml), pdfDocument, converterPropertiesCopy);
438445

439-
compareAndCheckCompliance(destinationPdf, cmpPdf, isExpectedOk);
446+
if (expectedErrorMessage != null) {
447+
Exception e = Assertions.assertThrows(PdfUAConformanceException.class,
448+
() -> HtmlConverter.convertToPdf(new FileInputStream(sourceHtml), pdfDocument,
449+
converterPropertiesCopy));
450+
Assertions.assertEquals(expectedErrorMessage, e.getMessage());
451+
} else {
452+
HtmlConverter.convertToPdf(new FileInputStream(sourceHtml), pdfDocument, converterPropertiesCopy);
453+
compareAndCheckCompliance(destinationPdf, cmpPdf, isExpectedOk);
454+
}
440455
}
441456
}

0 commit comments

Comments
 (0)