-
Notifications
You must be signed in to change notification settings - Fork 670
Closed
Description
Describe the bug
When converting HTML to PDF, using HTMLWorker.parseToList
, font size specified in % is interpreted as pixels
To Reproduce
@Test
public void testFontSize() throws Exception {
StringReader reader = new StringReader(
"<span style=\"font-size:8.0pt\">Text 8.0pt</span><br/>"
+ "<span style=\"font-size:20px\">Text 20px</span><br/>"
+ "<span style=\"font-size:85%\">Text 85%</span><br/>"
+ "<span style=\"font-size:1.5em\">Text 1.5em</span><br/>");
StyleSheet styleSheet = new StyleSheet();
Map<String, Object> interfaceProps = new HashMap<>();
List<Element> elements = HTMLWorker.parseToList(reader, styleSheet, interfaceProps);
Document document = new Document();
PdfWriter instance = PdfWriter.getInstance(document, new FileOutputStream("Font Size.pdf"));
document.open();
instance.getInfo().put(PdfName.CREATOR, new PdfString(Document.getVersion()));
for(Element e: elements) {
document.add(e);
}
document.close();
}
Expected behavior
All font size variants, including %, should be properly interpreted and shown approximately as the HTML in a browser.
Screenshots
HTML in a browser:
System:
- OS: Windows 11
- Used Font: default