1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > itext将html转换为pdf 使用itext将html转换为pdf

itext将html转换为pdf 使用itext将html转换为pdf

时间:2024-05-29 13:54:02

相关推荐

itext将html转换为pdf 使用itext将html转换为pdf

package test;

/*

* private static final String DEST = "C:/Users/钟倩文/Desktop/pdf测试文件/HelloWorld_CN_HTML.pdf";

private static final String HTML = "D:/毕业设计/pdfBox/test/src/html/test.html";

private static final String FONT = "D:/毕业设计/pdfBox/test/src/resources/simhei.ttf";

* */

import com.itextpdf.text.Document;

import com.itextpdf.text.DocumentException;

import com.itextpdf.text.pdf.PdfWriter;

import com.itextpdf.tool.xml.XMLWorkerFontProvider;

import com.itextpdf.tool.xml.XMLWorkerHelper;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.nio.charset.Charset;

/**

* Created by lujianing on /5/7.

*/

public class test1 {

private static final String DEST = "C:/Users/钟倩文/Desktop/pdf测试文件/HelloWorld_CN_HTML.pdf";

private static final String HTML = "D:/毕业设计/pdfBox/test/src/html/test.html";

private static final String FONT = "D:/毕业设计/pdfBox/test/src/resources/simhei.ttf";

public static void main(String[] args) throws IOException, DocumentException {

// step 1

Document document = new Document();

// step 2

PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST));

// step 3

document.open();

// step 4

XMLWorkerFontProvider fontImp = new XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS);

fontImp.register(FONT);

XMLWorkerHelper.getInstance().parseXHtml(writer, document,

new FileInputStream(HTML), null, Charset.forName("UTF-8"), fontImp);

// step 5

document.close();

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。