Package cn.net.pap.common.pdf
Class PDFUtil
java.lang.Object
cn.net.pap.common.pdf.PDFUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddProtect(String pdfFilePath, String ownerPassword, String userPassword, String outputFilePath) 添加禁止编辑(密码)static void添加数字签名static void添加印章static voidanalyzePdf(String filePath) 分析static voidconvertPDFA(String inputFilePath, String outputFilePath) convert PDF/Astatic booleanconvertPDFToJPG(String pdfFilePath, String outputPath, Integer DPI) 单页 PDF 转换 JPGstatic Booleanstatic voiddrawParagraphs(String pdfPath, List<String> paragraphs) 写入段落static voiddrawRectangleBy4Point(String pdfPath, PointDTO leftBottom, PointDTO rightBottom, PointDTO rightTop, PointDTO leftTop) 画矩形, 或者是表格的一个长方形的框。 提供一个从左下角开始,左上角结束的逆时针的四个点坐标.static void写文字,支持字体大小和按照写入顺序读取.static ByteArrayOutputStreamextractPage(String pdfFilePath, int pageNum) 用低内存方式提取 PDF 单页,避免一次性加载整个文件static org.apache.pdfbox.pdmodel.font.PDType0Font查询可用的字体static Boolean
-
Constructor Details
-
PDFUtil
public PDFUtil()
-
-
Method Details
-
extractPage
用低内存方式提取 PDF 单页,避免一次性加载整个文件- Parameters:
pdfFilePath- PDF 文件路径pageNum- 要提取的页码(从1开始)- Returns:
- 单页 PDF 的 ByteArrayOutputStream
- Throws:
IOException- IO异常或非法页码
-
convertPDFToJPG
单页 PDF 转换 JPG- Parameters:
pdfFilePath- PDF文件绝对路径outputPath- JPG文件绝对路径DPI- DPI
-
addStamp
public static void addStamp(String pdfFilePath, String imageFilePath, String outputFilePath) throws Exception 添加印章- Parameters:
pdfFilePath-imageFilePath-outputFilePath-- Throws:
Exception
-
addSign
public static void addSign(String pdfFilePath, String keystorePath, String keystorePassword, String outputFilePath) throws Exception 添加数字签名- Parameters:
pdfFilePath-keystorePath- *.p12 可以申请SSL证书(*.key, .crt),然后使用openssl 命令转换为 p12 证书keystorePassword- 密码outputFilePath-- Throws:
Exception
-
addProtect
public static void addProtect(String pdfFilePath, String ownerPassword, String userPassword, String outputFilePath) throws Exception 添加禁止编辑(密码)- Parameters:
pdfFilePath-ownerPassword-userPassword-outputFilePath-- Throws:
Exception
-
convertPDFA
convert PDF/A- Parameters:
inputFilePath-outputFilePath-- Throws:
Exception
-
drawText
写文字,支持字体大小和按照写入顺序读取.- Parameters:
pdfPath-coordsDTOList-- Throws:
IOException
-
findFont
查询可用的字体- Parameters:
text-- Returns:
-
drawParagraphs
写入段落- Parameters:
pdfPath-paragraphs-- Throws:
IOException
-
drawRectangleBy4Point
public static void drawRectangleBy4Point(String pdfPath, PointDTO leftBottom, PointDTO rightBottom, PointDTO rightTop, PointDTO leftTop) throws IOException 画矩形, 或者是表格的一个长方形的框。 提供一个从左下角开始,左上角结束的逆时针的四个点坐标.- Parameters:
pdfPath-leftBottom- 左下角rightBottom- 右下角rightTop- 右上角leftTop- 左上角- Throws:
IOException
-
jpg2Pdf
-
dir2Pdf
-
analyzePdf
分析- Parameters:
filePath-- Throws:
IOException
-