Class PDFUtil

java.lang.Object
cn.net.pap.common.pdf.PDFUtil

public class PDFUtil extends Object
  • Constructor Details

    • PDFUtil

      public PDFUtil()
  • Method Details

    • extractPage

      public static ByteArrayOutputStream extractPage(String pdfFilePath, int pageNum) throws IOException
      用低内存方式提取 PDF 单页,避免一次性加载整个文件
      Parameters:
      pdfFilePath - PDF 文件路径
      pageNum - 要提取的页码(从1开始)
      Returns:
      单页 PDF 的 ByteArrayOutputStream
      Throws:
      IOException - IO异常或非法页码
    • convertPDFToJPG

      public static boolean convertPDFToJPG(String pdfFilePath, String outputPath, Integer DPI)
      单页 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

      public static void convertPDFA(String inputFilePath, String outputFilePath) throws Exception
      convert PDF/A
      Parameters:
      inputFilePath -
      outputFilePath -
      Throws:
      Exception
    • drawText

      public static void drawText(String pdfPath, List<CoordsDTO> coordsDTOList) throws IOException
      写文字,支持字体大小和按照写入顺序读取.
      Parameters:
      pdfPath -
      coordsDTOList -
      Throws:
      IOException
    • findFont

      public static org.apache.pdfbox.pdmodel.font.PDType0Font findFont(String text)
      查询可用的字体
      Parameters:
      text -
      Returns:
    • drawParagraphs

      public static void drawParagraphs(String pdfPath, List<String> paragraphs) throws IOException
      写入段落
      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

      public static Boolean jpg2Pdf(String jpgPath, String pdfPath)
    • dir2Pdf

      public static Boolean dir2Pdf(String dirPath, String pdfPath, Integer DPI)
    • analyzePdf

      public static void analyzePdf(String filePath) throws IOException
      分析
      Parameters:
      filePath -
      Throws:
      IOException