| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package jnpf.util;
- import com.lowagie.text.pdf.PdfReader;
- import lombok.Cleanup;
- import lombok.extern.slf4j.Slf4j;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStream;
- import java.nio.file.Files;
- /**
- * PDF工具
- * @author JNPF开发平台组
- * @version V5.0.0
- * @copyright 引迈信息技术有限公司
- * @date 2025/1/14 15:00
- */
- @Slf4j
- public class PdfUtil {
- /**
- * 校验pdf文件是否包含js脚本
- **/
- public static boolean containsJavaScript(File file) {
- try {
- return containsJavaScript(Files.readAllBytes(file.toPath()));
- } catch (IOException e) {
- log.error("PDF文档解析失败: {}", e.getMessage());
- }
- return false;
- }
- /**
- * 校验pdf文件是否包含js脚本
- **/
- public static boolean containsJavaScript(byte[] filebyte) {
- try {
- @Cleanup PdfReader reader = new PdfReader(filebyte);
- String javaScript = reader.getJavaScript();
- if(StringUtil.isNotEmpty(javaScript)) {
- return true;
- }
- } catch (Exception e) {
- log.error("PDF文档解析失败: {}", e.getMessage());
- }
- return false;
- }
- /**
- * 校验pdf文件是否包含js脚本
- **/
- public static boolean containsJavaScript(InputStream inputStream) {
- try {
- @Cleanup PdfReader reader = new PdfReader(inputStream);
- String javaScript = reader.getJavaScript();
- if(StringUtil.isNotEmpty(javaScript)) {
- return true;
- }
- } catch (Exception e) {
- log.error("PDF文档解析失败: {}", e.getMessage());
- }
- return false;
- }
- }
|