我正在尝试开发一个应用程序,它将html文件或url作为输入并呈现与PDF文件相同的内容。我为此目的使用yahp。我已经导入了yahp.jar
文件,但是我遇到了以下异常:
java.lang.ClassNotFoundException: org.allcolor.yahp.cl.converter.CHtmlToPdfFlyingSaucerTransformer
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.allcolor.yahp.converter.CClassLoader.findClass(CClassLoader.java:1495)
at org.allcolor.yahp.converter.CClassLoader.findClass(CClassLoader.java:1477)
at org.allcolor.yahp.converter.CClassLoader.loadClass(CClassLoader.java:2056)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.allcolor.yahp.converter.CYaHPConverter.getTransformer(CYaHPConverter.java:383)
at org.allcolor.yahp.converter.CYaHPConverter.convertToPdf(CYaHPConverter.java:246)
at HtmlToPDF.htmlToPdfFile(HtmlToPDF.java:74)
at HtmlToPDF.main(HtmlToPDF.java:52)
SEVERE: Error while getting transformer 'org.allcolor.yahp.cl.converter.CHtmlToPdfFlyingSaucerTransformer' ! : org.allcolor.yahp.cl.converter.CHtmlToPdfFlyingSaucerTransformer
org.allcolor.yahp.converter.IHtmlToPdfTransformer$CConvertException
at org.allcolor.yahp.converter.CYaHPConverter.convertToPdf(CYaHPConverter.java:255)
at HtmlToPDF.htmlToPdfFile(HtmlToPDF.java:74)Done
at HtmlToPDF.main(HtmlToPDF.java:52)
Caused by: java.lang.NullPointerException
at org.allcolor.yahp.converter.CYaHPConverter.convertToPdf(CYaHPConverter.java:247)
... 2 more
Destroying YAHP ClassLoader Tree
Exception in thread "AWT-Windows" java.lang.IllegalStateException: Shutdown in progress
at java.lang.ApplicationShutdownHooks.add(Unknown Source)
at java.lang.Runtime.addShutdownHook(Unknown Source)
at sun.awt.windows.WToolkit.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
答案 0 :(得分:0)
iText“XML Worker”允许开发人员以程序员友好的方式将XML文件转换为PDF文档。 iText还可以使用HTML元素上实现的CSS样式将HTML转换为PDF。 看this