gpt4 book ai didi

java - 如何在Java中将HTML文件转换为PDF?

转载 作者:行者123 更新时间:2023-12-01 04:20:20 24 4
gpt4 key购买 nike

我正在尝试开发一个应用程序,它将 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)

最佳答案

iText“XML Worker”允许开发人员以程序员友好的方式将 XML 文件转换为 PDF 文档。 iText 还可以使用 HTML 元素上实现的 CSS 样式将 HTML 转换为 PDF。看this

关于java - 如何在Java中将HTML文件转换为PDF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18980869/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com