我現在用的罐子是從行家repoJava的生成PDF與飛碟
我測試的代碼是從以前的堆棧solution
我擔心它可能已過時,因爲庫貶值。當測試下面的代碼:
import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import org.w3c.dom.Document;
import org.xhtmlrenderer.pdf.ITextRenderer;
public class test
{
public static void main(String[] args)
{
ITextRenderer renderer = new ITextRenderer();
// if you have html source in hand, use it to generate document object
renderer.setDocumentFromString("C:/Users/Goran/Documents/Documents/Development/workspace/FlyingSaucer/data/input/report.xhtml");
renderer.layout();
String fileNameWithPath = "C:/Users/Goran/Documents/Documents/Development/workspace/FlyingSaucer/data/output/" + "PDF-FromHtmlString.pdf";
FileOutputStream fos = new FileOutputStream(fileNameWithPath);
renderer.createPDF(fos);
fos.close();
System.out.println("File 2: '" + fileNameWithPath + "' created.");
}
}
我有以下錯誤此此行:renderer.createPDF(fos);
The type com.lowagie.text.DocumentException cannot be resolved. It is indirectly referenced from required .class files
任何人都可以提供一些線索這光,還是建議在創建PDF文檔的最佳方式java嗎?我有XML和XHTML文檔可用。
編輯當我從repo
Exception in thread "main" java.lang.NoClassDefFoundError: org/xhtmlrenderer/extend/UserAgentCallback
at test.main(test.java:16)
Caused by: java.lang.ClassNotFoundException: org.xhtmlrenderer.extend.UserAgentCallback
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
添加com.lowagie.text庫我是即使使用正確的庫/最最新的嗎?
有誰擁有最近的圖書館或知道他們存儲的回購鏈接他們?
編輯2被遺棄的想法使用飛碟和使用ApacheFop建議。當前錯誤是:
Mar 10, 2016 9:58:23 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
Mar 10, 2016 9:58:23 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
Mar 10, 2016 9:58:23 PM org.apache.fop.events.LoggingEventListener processEvent
INFO: Rendered page #1.
你需要找到的jar包含''com.lowagie.text.DocumentException並添加它給你的類路徑 –
@Scary Wombat我也試過,拋出一個不同的錯誤。有很多版本的庫和沒有指南,我不知道該使用:( – codeCompiler77
是',org/xhtmlrenderer/extend/UserAgentCallback'是的,沖洗和重新打包 –