日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

itextpdf html转pdf

發布時間:2023/12/14 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 itextpdf html转pdf 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

itextpdf html轉pdf

? ? ? ? ? ? ? ? ? ? ? ? ? ??

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

**************

相關類與接口

? ? ? ? ? ? ? ? ?

HtmlConverter

public class HtmlConverter {private HtmlConverter() {}*********** 轉換為pdfpublic static void convertToPdf(String html, OutputStream pdfStream) {public static void convertToPdf(String html, OutputStream pdfStream, ConverterProperties converterProperties) {public static void convertToPdf(String html, PdfWriter pdfWriter) {public static void convertToPdf(String html, PdfWriter pdfWriter, ConverterProperties converterProperties) {public static void convertToPdf(String html, PdfDocument pdfDocument, ConverterProperties converterProperties) {public static void convertToPdf(File htmlFile, File pdfFile) throws IOException {public static void convertToPdf(File htmlFile, File pdfFile, ConverterProperties converterProperties) throws IOException {public static void convertToPdf(InputStream htmlStream, OutputStream pdfStream) throws IOException {public static void convertToPdf(InputStream htmlStream, OutputStream pdfStream, ConverterProperties converterProperties) throws IOException {public static void convertToPdf(InputStream htmlStream, PdfDocument pdfDocument) throws IOException {public static void convertToPdf(InputStream htmlStream, PdfWriter pdfWriter) throws IOException {public static void convertToPdf(InputStream htmlStream, PdfWriter pdfWriter, ConverterProperties converterProperties) throws IOException {public static void convertToPdf(InputStream htmlStream, PdfDocument pdfDocument, ConverterProperties converterProperties) throws IOException {*********** 轉換為documentpublic static Document convertToDocument(String html, PdfWriter pdfWriter) {public static Document convertToDocument(InputStream htmlStream, PdfWriter pdfWriter) throws IOException {public static Document convertToDocument(String html, PdfWriter pdfWriter, ConverterProperties converterProperties) {public static Document convertToDocument(InputStream htmlStream, PdfWriter pdfWriter, ConverterProperties converterProperties) throws IOException {public static Document convertToDocument(String html, PdfDocument pdfDocument, ConverterProperties converterProperties) {public static Document convertToDocument(InputStream htmlStream, PdfDocument pdfDocument, ConverterProperties converterProperties) throws IOException {*********** 轉換為elementpublic static List<IElement> convertToElements(String html) {public static List<IElement> convertToElements(InputStream htmlStream) throws IOException {public static List<IElement> convertToElements(String html, ConverterProperties converterProperties) {public static List<IElement> convertToElements(InputStream htmlStream, ConverterProperties converterProperties) throws IOException {static IMetaInfo createPdf2HtmlMetaInfo() {private static IMetaInfo resolveMetaInfo(ConverterProperties converterProperties) {private static class HtmlMetaInfo implements IMetaInfo {

? ? ? ? ? ? ? ? ? ? ??

Converterproperties

public class ConverterProperties {private static final int DEFAULT_LIMIT_OF_LAYOUTS = 10;private MediaDeviceDescription mediaDeviceDescription;private FontProvider fontProvider;private ITagWorkerFactory tagWorkerFactory;private ICssApplierFactory cssApplierFactory;private OutlineHandler outlineHandler;private String baseUri;private IResourceRetriever resourceRetriever;private boolean createAcroForm = false;private String charset;private boolean immediateFlush = true;private int limitOfLayouts = 10;private IMetaInfo metaInfo;public ConverterProperties() {public ConverterProperties(ConverterProperties other) {public ConverterProperties setCharset(String charset) {public ConverterProperties setBaseUri(String baseUri) {public ConverterProperties setEventMetaInfo(IMetaInfo metaInfo) {public ConverterProperties setLimitOfLayouts(int limitOfLayouts) {public ConverterProperties setImmediateFlush(boolean immediateFlush) {public ConverterProperties setCreateAcroForm(boolean createAcroForm) {public ConverterProperties setFontProvider(FontProvider fontProvider) {public ConverterProperties setOutlineHandler(OutlineHandler outlineHandler) {public ConverterProperties setTagWorkerFactory(ITagWorkerFactory tagWorkerFactory) {public ConverterProperties setCssApplierFactory(ICssApplierFactory cssApplierFactory) {public ConverterProperties setResourceRetriever(IResourceRetriever resourceRetriever) {public ConverterProperties setMediaDeviceDescription(MediaDeviceDescription mediaDeviceDescription) {public boolean isCreateAcroForm() {public boolean isImmediateFlush() {public String getCharset() {public String getBaseUri() {IMetaInfo getEventMetaInfo() {public int getLimitOfLayouts() {public FontProvider getFontProvider() {public OutlineHandler getOutlineHandler() {public ITagWorkerFactory getTagWorkerFactory() {public IResourceRetriever getResourceRetriever() {public ICssApplierFactory getCssApplierFactory() {public MediaDeviceDescription getMediaDeviceDescription() {

? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ? ? ?

**************

示例

? ? ? ? ? ? ? ??

public class Test8 {private static final String source = "./html/1.html";private static final String source2 = "./html/2.html";private static final String dest = "./dest/html.pdf";private static final String dest2 = "./dest/html2.pdf";public static void fun() throws Exception{ConverterProperties properties = new ConverterProperties();FontProvider fontProvider = new FontProvider();fontProvider.addFont("./fonts/simkai.ttf");properties.setFontProvider(fontProvider); //添加中文支持HtmlConverter.convertToPdf(new FileInputStream(source),new PdfWriter(dest),properties);}public static void fun2() throws Exception{ //轉換包含圖片的htmlConverterProperties properties = new ConverterProperties();FontProvider fontProvider = new FontProvider();fontProvider.addFont("./fonts/simkai.ttf");properties.setFontProvider(fontProvider);//properties.setBaseUri("."); //包含html、css、image的目錄,默認為當前項目路徑HtmlConverter.convertToPdf(new FileInputStream(source2),new PdfWriter(dest2),properties);}public static void main(String[] args) throws Exception{fun();fun2();} }

? ? ? ? ? ? ? ? ? ? ??

源文件:1.html

<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security"> <head><meta charset="UTF-8"><title>Title</title> </head> <body> <div align="center"><h1>瓜田李下</h1><span style="color: coral;font-size: 20px">海賊王</span> </div> </body> </html>

? ? ? ? ? ? ? ? ??

源文件:2.html

<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security"> <head><meta charset="UTF-8"><title>Title</title> </head> <style>.cla{color: coral;} </style> <body> <div align="center"><h2>瓜田李下</h2><br><img src="./image/ymhd.jpg"><br><span class="cla">灌籃高手</span> </div> </body> </html>

? ? ? ? ? ? ? ? ? ? ?

轉換后的pdf文件:html.pdf

? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ?

轉換后的pdf文件:html2.pdf

? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ? ? ?

總結

以上是生活随笔為你收集整理的itextpdf html转pdf的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。