Previously, developers faced difficulties converting HTML to PDF using HTMLWorker due to deprecated methods and lack of CSS support. XMLWorker also had limitations, particularly with image positioning. To resolve these issues, iText 7 and the pdfHTML add-on were developed.
The simplified approach to converting the provided HTML to PDF using iText 7.1.0 pdfHTML 2.0.0 is:
public static final String SRC = "src/main/resources/html/sample.html"; public static final String DEST = "target/results/sample.pdf"; public void createPdf(String src, String dest) throws IOException { HtmlConverter.convertToPdf(new File(src), new File(dest)); }
This results in a PDF that respects CSS positioning, including the image on the right.
The above is the detailed content of How to Convert HTML to PDF While Respecting CSS Positioning Rules Using iText7?. For more information, please follow other related articles on the PHP Chinese website!