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; } }