iText PDF操作(查找关键字、插入图片)
Demo地址
https://download.csdn.net/download/L_C_Baker/12316480
增加pom依赖
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.10</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
PdfKeywordFinder调用
返回查找到关键字的首个文字的左上角坐标值
输入值
参数 | 类型 | 描述 | 取值 |
---|---|---|---|
pdfName | String | 源文件位置 | F:/testfiles/pfile.pdf |
keyword | String | 查找关键字 |
返回参数( List<float[]> 关键字出现的位置信息)
参数 | 类型 | 描述 |
---|---|---|
float[0] | float | 位置页码 起始为1 |
float[1] | float | 左侧偏移量 (原点为左下角) |
float[2] | float | 底部偏移量 (原点为左下角) |
返回查找到关键字的末尾文字的右下角坐标值
输入值
参数 | 类型 | 描述 | 取值 |
---|---|---|---|
pdfName | String | 源文件位置 | F:/testfiles/pfile.pdf |
keyword | String | 查找关键字 |
返回参数( List<float[]> 关键字出现的位置信息)
参数 | 类型 | 描述 |
---|---|---|
float[0] | float | 位置页码 起始为1 |
float[1] | float | 左侧偏移量 (原点为左下角) |
float[2] | float | 底部偏移量 (原点为左下角) |
InsertImageToPdf调用
插入图片的信息
参数 | 类型 | 描述 |
---|---|---|
imagePath | String | 待插入图片 |
insertPage | int | 插入页码 起始为1 |
insertX | int | 插入位置 x偏移 |
insertY | int | 插入图片 y偏移 |
picWidth | int | 插入图片宽度 |
picHeight | int | 插入图片高度 |
picRotate | float | 插入图片旋转角度 |
在目标文件中插入多张图片,每个InsertPicInfo是一副图片的信息
输入值
参数 | 类型 | 描述 | 取值 |
---|---|---|---|
source | String | 源文件位置 | F:/testfiles/pfile.pdf |
targetPath | String | 输出文件位置 | |
insertInfos | List | 插入图片的信息集合 |