通过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;*/
}
.page_break { page-break-after:always;}
.seclev2 {
text-indent:20pt;
}