It is necessary to generate a pdf file from the html file.
I use the following libraries: itextpdf-5.4.0 , core-renderer-R8 .
Eclipse highlights the following renderer.createPDF(os); and writes in the tip
The method createPDF (OutputStream) from the type ITextRenderer refers to the missing type DocumentException
When compiling it swears by this:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type com.lowagie.text.DocumentException cannot be resolved. It is indirectly referenced from required .class files
The method createPDF (OutputStream) from the type ITextRenderer refers to the missing type DocumentException at q.test.main (test.java:32)
How to fix it?
Actually, my code is:
package q; import java.io.IOException; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.OutputStream; import java.net.MalformedURLException; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import org.xhtmlrenderer.pdf.*; import com.itextpdf.text.DocumentException; public class test { public static void main(String[] args) throws IOException, DocumentException { String File_To_Convert = "Index2.html"; String url = new File(File_To_Convert).toURI().toURL().toString(); System.out.println(""+url); String HTML_TO_PDF = "ConvertedFile.pdf"; OutputStream os = new FileOutputStream(HTML_TO_PDF); ITextRenderer renderer = new ITextRenderer(); renderer.setDocument(url); renderer.layout(); renderer.createPDF(os); os.close(); } }