If you want to use a specific font in your HTML content, you could provide a ConverterProperties with appropriate FontProvider. nvertToPdf( new File( "./input.html"), new File( "output.pdf"), converterProperties) Code language: Java ( java ) ConverterProperties converterProperties = new ConverterProperties() In this case, you can configure the converter to load every base path as shown below. As the library cannot detect where this CSS is from, it is our responsibility to point from where the relative paths are calculated.įor instance, the server base URL is. However, the CSS file is referred from the server root. In the above case, the image was loaded because it was found in the same path as the HTML file. Main.css is not applied due to relative path But there are variations to these methods which you can find from the documentation. The above set of methods are the most common ones. nvertToPdf(htmlStringStream, fileOutputStream) Code language: Java ( java ) If you have the HTML content as a java InputStream object, you convert the stream into PDF using iText as shown below. This way of conversion would be ideal along with a template engine like thymeleaf. nvertToPdf( "Hello String Content!", fileOutputStream) Code language: Java ( java ) OutputStream fileOutputStream = new FileOutputStream( "string-output.pdf") If you have the HTML content as a String, then you may want to use the following itext utility method to convert HTML to a pdf file. nvertToPdf( new File( "./simple-input.html"), new File( "simple-output.pdf")) Code language: Java ( java ) HTML String to PDF To convert HTML files to PDF, you need to use the following java method. To convert HTML to PDF, the iText java library provides plenty of utility methods. The html2pdf gives utility methods that help us to convert HTML files or content into PDF. The kernel dependency provides the core module for PDF support. com.itextpdf kernel 7.1.14 com.itextpdf html2pdf 3.0.3 Code language: HTML, XML ( xml ) To add support for itext-pdf dependencies, you need to add the following kernel and HTML to pdf dependencies. In this post, we will take a look at a simple example of HTML to PDF conversion. Itext PDF library lets you convert HTML to PDF documents. Let’s learn how to convert HTML to pdf using java and the itext pdf library.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |