Home >Java >javaTutorial >How Can iText 7 and pdfHTML 2 Efficiently Convert HTML to PDF, Handling CSS and Images?
HTMLWorker, despite its deprecation, has limitations. It does not consider CSS styling and requires manual image provision to prevent errors. It also requires deprecated objects and methods for operation.
While XML Worker initially showed promise, it faced image display issues. By incorporating an ImageProvider and configuring CSS, the image can be displayed, but its positioning (e.g., floating right) remained unaddressed.
In iText 7.1.0 with pdfHTML 2.0.0, CSS positioning is resolved. The code simplifies to this:
HtmlConverter.convertToPdf(new File(src), new File(dest));
iText 7 offers a streamlined and powerful HTML to PDF conversion. It automatically respects CSS, including float positioning, and supports various HTML elements.
iText 7 is available under the AGPL, allowing free use for open source projects. Closed source uses require a commercial license. Legacy systems using older iText versions should migrate to iText 7 for maintenance and security reasons.
The above is the detailed content of How Can iText 7 and pdfHTML 2 Efficiently Convert HTML to PDF, Handling CSS and Images?. For more information, please follow other related articles on the PHP Chinese website!