Software Versions:
- html2pdf v2.0.1
- iText 7.1.1
The HTML label that spans the width of the page is as follows:
<label class="test">Patient</label>
CSS Styling:
.test {
display: block;
font-weight: bold;
color: #009fd1;
font-size: .6em;
text-align: left;
padding: 0.5rem;
background: #085a9f;
border-radius: 3px;
}
https://i.sstatic.net/OCT8y.png
However, when converting this HTML to PDF using iText, the label appears differently:
https://i.sstatic.net/wgWDv.png
It seems like the issue lies with the display: block
and border-radius: 3px
properties.
Could this be a problem with iText?
Here is the code snippet for the conversion process:
public ByteArrayOutputStream createPdf(String html) throws IOException {
ByteArrayOutputStream baos = null;
html = replaceStylesheet(html);
try {
baos = new ByteArrayOutputStream();
WriterProperties writerProperties = new WriterProperties();
PdfWriter pdfWriter = new PdfWriter(baos, writerProperties);
PdfDocument pdfDoc = new PdfDocument(pdfWriter);
PageSize pageSize = PageSize.A4;
pdfDoc.setDefaultPageSize(pageSize);
pdfDoc.getCatalog().setLang(new PdfString("en-US"));
pdfDoc.setTagged();
PdfViewerPreferences pdfViewerPreferences = new PdfViewerPreferences();
pdfViewerPreferences.setDisplayDocTitle(true);
pdfDoc.getCatalog().setViewerPreferences(pdfViewerPreferences);
String header = "© 2018 Generated by OpenNCP Portal";
Header headerHandler = new Header(header);
PageXofY footerHandler = new PageXofY(pdfDoc);
pdfDoc.addEventHandler(PdfDocumentEvent.START_PAGE,headerHandler);
pdfDoc.addEventHandler(PdfDocumentEvent.END_PAGE,footerHandler);
ConverterProperties props = new ConverterProperties();
FontProvider dfp = new DefaultFontProvider(true, false, false);
props.setFontProvider(dfp);
HtmlConverter.convertToDocument(html, pdfDoc, props);
footerHandler.writeTotal(pdfDoc);
pdfDoc.close();
} catch (Exception e) {
LOGGER.error("Error occurred when converting HTML to PDF", e);
}
return baos;
}