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相关推荐

  1. JAVA使用itextpdf插件生成pdf

    使用itextpdf插件实现pdf生成 1.引入pdf的依赖如下: <dependency><groupId>org.jfree</groupId><arti ...

  2. Java中使用ItextPdf工具根据PDF合同模板填充pdf

    Java中使用itextPdf工具根据PDF合同模板填充内容 设置PDF合同模板的文本域 导入itextPdf的pom依赖 编写生成填充pdf代码 1:设置PDF合同模板的文本域 ​ 设置PDF文本域 ...

  3. itextpdf text转pdf

    itextpdf text转pdf ********************* 示例 public class Test7 {private static final String source = ...

  4. 使用itextpdf实现截取pdf文档第几页到第几页,进行分片

    itextpdf实现截取pdf文档第几页到第几页 起因:pdf文档太大,100M以上,导致前端根本无法显示.解决方案,后端进行pdf文档分片操作,例如十页十页的传给前端. 1.使用itextpdf 导 ...

  5. itextpdf 生成表格pdf+背景图片(可转图片)

    itextpdf生成表格pdf+背景图片(可转图片) 导入jar,manven引用 <dependency><groupId>com.itextpdf</groupId& ...

  6. 记-ItextPDF+freemaker 生成PDF文件---导致服务宕机

    摘要:已经上线的项目,出现服务挂掉的情况. 介绍:该服务是专门做打印的,业务需求是生成PDF文件进行页面预览,主要是使用ItextPDF+freemaker技术生成一系列PDF文件,其中生成流程有:解 ...

  7. 使用itextpdf实现横板PDF文件与竖版PDF文件的相互转换

    在实际的开发过程中,可能会遇到以下的一些场景: 一个全部为竖版的PDF文件,现在需要将其全部转换为横版PDF文件: 一个全部为竖版的PDF文件,现在需要将指定页转换为横版PDF文件: 一个PDF文件中 ...

  8. java Itextpdf 图片转pdf并压缩下载至浏览器

    注:图片存放在服务器D盘指定目录下,该目录URL存放于数据库表中 maven项目 jdk1.7 <!-- itextpdf --> <dependency><groupI ...

  9. java pdf插件下载_java使用itextpdf插件生成pdf

    可以去mvn repository下载itext的jar包,需要的组件有两个,itextpdf-5.5.13和itext-asian-5.2.0(中文编译) maven库地址:https://mvnr ...

  10. java 生成pdf插件_java使用itextpdf插件生成pdf

    可以去mvn repository下载itext的jar包,需要的组件有两个,itextpdf-5.5.13和itext-asian-5.2.0(中文编译) maven库地址:https://mvnr ...

最新文章

  1. 即将到来的金三银四,这10道springboot常见面试题你需要了解下
  2. 如何针对CMS系统进行SEO优化_
  3. 一次项目组聚餐,让我重新认识了很多人
  4. 【控制】《多智能体系统一致性与复杂网络同步控制》郭凌老师-第4章-具有扰动的混沌系统主-从同步
  5. shell 实例收集
  6. 谁说菜鸟不会数据分析python下载_刻意练习9:《谁说菜鸟不会数据分析python篇》第3章编程基础总计46页学习笔记...
  7. 编写一个函数实现从 1 到 n 共 n 个数的累加_leetcode306_go_累加数
  8. CodeForces - 1168B Good Triple(思维+暴力)
  9. 刘敏:优麒麟开源操作系统运营实践 | DEV. Together 2021 中国开发者生态峰会
  10. 10亿个数中找出最大的10000个数
  11. 机器学习基石-作业三-第2题分析以及通过H证明EIN的讨论
  12. redmine-project.net vs redmine vs trac vs apis项目管理软件选型比较
  13. Intel® Nehalem/Westmere架构/微架构/流水线 (3) - 流水线前端
  14. 怎么才能成为一名PHP专家?
  15. 温故而知新 Ajax 的新坑 dataType: 'json'
  16. gta5线下联机_《GTA5》典藏版实物开箱,紫外线照射地图会有R星彩蛋
  17. 基于java题库及试卷管理模块的设计与开发(含源文件)
  18. zul页面报org.xml.sax.SAXParseException
  19. CSDN博客 不登录不能复制粘贴
  20. Java POI word常用方法 在Cell插入子表格

热门文章

  1. 斗鱼显示弹幕服务器连接失败,斗鱼看不到弹幕怎么办 斗鱼无法看到弹幕的解决方法...
  2. python去掉停用词_Python - 删除停用词
  3. 乐高spike python_SPIKE Prime科创套装 篇四:乐高教育SPIKE Prime入门编程和搭建活动教学...
  4. uniapp使用阿里icon详细步骤
  5. sqluldr2导出过blob字段_转载:利用sqluldr2导出数据和sqlldr导入数据的方法
  6. svn分支合并到主干(Merge)
  7. 海思hitool工具使用
  8. React跨域解决方案
  9. 48 个 Linux 面试问题和答案
  10. tongweb java_home_中间件 东方通tongweb的使用