java 生成pdf 三种_Java的生成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.

+0

你需要找到的jar包含''com.lowagie.text.DocumentException并添加它给你的类路径 –

+0

@Scary Wombat我也试过,抛出一个不同的错误。有很多版本的库和没有指南,我不知道该使用:( –

+0

是',org/xhtmlrenderer/extend/UserAgentCallback'是的,冲洗和重新打包 –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值