通过html生成pdf,可使用[睿印](https://gitee.com/Rayin/rayin) 工具包,睿印java工具包是集成openhtmltopdf,pdfbox的开源工具包,集成了thymeleaf 动态脚本,并可自动加载字体,默认支持中文显示。
1. 首先新建java maven项目,引入jar包
```xml
<dependency>
<groupId>ink.rayin</groupId>
<artifactId>rayin-htmladapter-openhtmltopdf</artifactId>
<version>1.0.8</version>
</dependency>
```
2. 新建html,保存至test/resources下,命名为element1.html
```html
<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8"/>
<style>
body {
font-family: FangSong,HanaMinB;
line-height: 1.2;
/*设置背景色*/
/*background: #00FF00 ;*/
/*设置背景图片*/
/*background-image:url(data:image/gif;base64,AAAA) no-repeat fixed top;*/
}
/** 指定pdf纸张大小 **/
@page {
size: A4 ;
margin: 1cm;
/*margin-bottom: 1cm;*/
/*border: thin solid black;*

这篇博客介绍了如何使用开源工具包睿印(Rayin)将HTML转换为PDF,包括集成的库和配置步骤。内容涉及HTML样例、测试类的创建以及最终生成的PDF效果。此外,还展示了如何使用PDFBox读取PDF的书签。

1336

被折叠的 条评论
为什么被折叠?



