html代码转化成pdf文件
来源:互联网 发布:淘宝国新西兰能用吗 编辑:程序博客网 时间:2024/06/05 11:27
所需依赖
<dependency><groupId>com.itextpdf</groupId><artifactId>itextpdf</artifactId><version>5.3.2</version><type>jar</type><scope>compile</scope></dependency><dependency><groupId>com.itextpdf</groupId><artifactId>itext-asian</artifactId><version>5.2.0</version><type>jar</type><scope>compile</scope></dependency><dependency><groupId>com.itextpdf</groupId><artifactId>itext-hyph-xml</artifactId><version>5.1.1</version><type>jar</type><scope>compile</scope></dependency><dependency><groupId>com.itextpdf.tool</groupId><artifactId>xmlworker</artifactId><version>5.4.1</version><scope>system</scope><systemPath>${project.basedir}/lib/xmlworker-1.2.1-micmiu.jar</systemPath></dependency>
http://download.csdn.net/detail/qq_18860653/9693066
xmlworker-1.2.1-micmiu.jar的文件建议用本文给的,不然会出现乱码。还有,注意html标签都需要关闭(<a></a>、<br />)
java代码
package yyf.utils.office.itext;import java.io.ByteArrayInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;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;/** * html代码转化为pdf * @author Yu Yufeng * */public class HTMlToPDF {public static void main(String[] args) throws DocumentException, IOException {// step 1Document document = new Document();// step 2PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("i://a.pdf"));// step 3document.open();// document.// step 4String s = "<h1>测试</h1>";InputStream in = new ByteArrayInputStream(s.getBytes());// in = new FileInputStream("i://a.html");XMLWorkerHelper.getInstance().parseXHtml(writer, document, in, Charset.forName("UTF-8"));// step 5document.close();System.out.println("success");}public static InputStream stringToInputStream(String str) {try {InputStream is = new ByteArrayInputStream(str.getBytes());int byteRead;while ((byteRead = is.read()) != -1) {System.out.print((char) byteRead);}is.close();return is;} catch (Exception e) {return null;}}}
1 0
- html代码转化成pdf文件
- 把HTML转化成PDF文件
- JAVA+代码+--++JSP+-+HTML+-++PDF+转化
- html转化成pdf工具
- PDF文件转化成word,ppt,excel,图片(png,jpg...),tiff,rtf,txt,html,PDF组合,PDF编辑,PDF创建
- Itext5.8.8 Html 转化成PDF
- HTML转化为PDF
- java操作html转换成pdf文件的实例代码
- 将pdf文件转化成swf文件
- 有关Freemaker转化成pdf文件的html特殊字符的处理
- 将PDF 转化 为 Word,Html 等文件
- HTML代码转化成字符串
- html阅读pdf文件主要代码。
- 如何将PPT转化成PDF文件
- pd4ml实现HTML转化PDF
- 把html转化成string代码
- 如何将ppt文件转化成pdf文件
- pdf2htmlEX将pdf文件转化为html最优参数以及把生成文件等比例缩小
- 部署图(Deployment Diagram)—UML图(九)
- perl学习笔记---debug
- MarkDown编辑器基本用法
- 禁止直接在Webservice.asmx页面调用的方法
- android 广播
- html代码转化成pdf文件
- 构件图(Component Diagram)—UML图(八)
- [李景山php]每天TP5-20161230|thinkphp5-Cookie.php
- 多线程下单例模式:懒加载(延迟加载)和即时加载
- 协作图(Collaboration Diagram)—UML图(七)
- c语言中用宏定义一个常量,数字后面带个U, L, F的含义
- 时序图(Sequence Diagram)—UML图(六)
- 递归求n阶勒让德多项式的值
- qq相册图片轮播js代码