import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.nio.charset.Charset;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.tool.xml.XMLWorkerHelper;
public class Test {
public static final String HTML = "E:/MyHtml.html";
public static final String DEST = "E:/hero.pdf";
/**
* Creates a PDF with the words "Hello World"
* @param file
* @throws IOException
* @throws DocumentException
*/
public void createPdf(String file) throws Exception {
// step 1
Document document = new Document();
// step 2
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
// step 3
document.open();
String value = TestVelocity.get();
@SuppressWarnings("deprecation")
Reader reader = null;
reader = new StringReader(value);
// step 4
XMLWorkerHelper.getInstance().parseXHtml(writer, document, reader);
// XMLWorkerHelper.getInstance().parseXHtml(writer, document,
// new FileInputStream(HTML) , Charset.forName("UTF-8"));
// step 5
document.close();
}
/**
* Main method
*/
public static void main(String[] args) throws Exception{
File file = new File(DEST);
file.getParentFile().mkdirs();
new Test().createPdf(DEST);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
velocity+itext导出pdf
共25个文件
jar:5个
vm:2个
prefs:2个
4星 · 超过85%的资源 需积分: 15 83 下载量 123 浏览量
2015-05-28
17:20:28
上传
评论
收藏 3.33MB RAR 举报
温馨提示
velocity+itext的整合导出pdf
资源推荐
资源详情
资源评论
收起资源包目录
Test.rar (25个子文件)
Test
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.core.resources.prefs 57B
org.eclipse.wst.common.component 450B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 500B
org.eclipse.jdt.core.prefs 364B
src
hello.vm 228B
Test.java 2KB
TestVelocity.java 2KB
.project 1KB
WebRoot
META-INF
MANIFEST.MF 36B
WEB-INF
web.xml 404B
classes
Test.class 2KB
hello.vm 228B
TestVelocity.class 2KB
lib
xmlworker-5.5.6.jar 240KB
commons-collections-3.2.1.jar 562KB
itextpdf-5.5.6.jar 2.16MB
velocity-1.7.jar 439KB
commons-lang-2.4.jar 256KB
index.jsp 834B
velocity.log 0B
.mymetadata 285B
.classpath 529B
.myeclipse
共 25 条
- 1
资源评论
- 岳丰源2017-01-24不错,非常棒,只不过是itext5的
- yml6112017-12-29还没试用!
- 雨天忘记2018-04-13需要先评论才能下载
- jinwanyuan18132017-10-16资源还可以呀
攫住你的心
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功