[Solved] Use jsoup to normalize html itext html to PDF to solve the problem of missing spaces

/** * Normalize html using jsoup * * @param html html content * @return normalized html */ private static String formatHtml(String html) { org.jsoup.nodes.Document doc = Jsoup.parse(html); //Set the export format to keep spaces doc.outputSettings(new org.jsoup.nodes.Document.OutputSettings().prettyPrint(false)); // remove excessive width String style = doc.attr(“style”); if (StringUtils.isNotEmpty(style) & amp; & amp; style.contains(“width”)) { doc.attr(“style”, “”); } […]