The example of this article tells the way Java implement HTML to PDF. Share it for everyone for your reference. The specifics are as follows:
Package test; Import Java.io.File; Import Java.fileoutPutstream; Import Java.io.outputStream; Import mport org.xhtmlrenderer.pdf.itextRenderer; Import com.lowagie.text.pdf .Basefont; Public Class WordTopdf { / ** * @param ARGS * / Public Static Void Main (String [] ARGS) Throws Exception {// Todo Auto-Gonement Method String inputfile = "d: //test.html"; String url = new file (inputFile) .touri (). TOURL (). Tostring (); string outputFile = "d: //test.pdf"; system.out.println (url); outputStream OS = Ew FileoutPutstream (Outputfile ).; olver.addfont ("c: /windows/fonts/simsun.ttc", basefont . Identity_h, basefont.not_embedded); // Solve the relative path problem of the picture // renderr.getsharedcontext (). err.createpdf ( OS); OS.Close ();}}It is hoped that this article is helpful to everyone's Java program design.