Class PDFBox

java.lang.Object
org.summerboot.jexpress.util.pdf.PDFBox

public class PDFBox extends Object
Author:
Changski Tie Zheng Zhang 张铁铮, 魏泽北, 杜旺财, 杜富贵
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
    static interface 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final org.apache.pdfbox.pdmodel.encryption.AccessPermission
     
    protected static final int
     
    protected static File[]
     
    protected static Map<File,String>
     
    protected static final Map<String,org.apache.pdfbox.pdmodel.font.PDFont>
     
    static final float
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static String
    buildBaseDocumentUri1(File baseDirectory)
     
    static org.apache.pdfbox.pdmodel.encryption.AccessPermission
     
    static org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy
     
    static org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy
    buildStandardProtectionPolicy(String userPwd, String ownerPwd, org.apache.pdfbox.pdmodel.encryption.AccessPermission ap, int keyLenth)
     
    static org.apache.pdfbox.pdmodel.font.PDFont
     
    static File[]
     
    static Map<File,String>
     
    static byte[]
    html2PDF(String html, File baseDir, org.apache.pdfbox.pdmodel.encryption.ProtectionPolicy protectionPolicy, org.apache.pdfbox.pdmodel.PDDocumentInformation info, float pdfVersion)
     
    static byte[]
    html2PDF(String html, File baseDir, org.apache.pdfbox.pdmodel.encryption.ProtectionPolicy protectionPolicy, org.apache.pdfbox.pdmodel.PDDocumentInformation info, float pdfVersion, float pageWidth, float pageHeight, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.PageSizeUnits units)
     
    static List<byte[]>
    images2Bytes(List<BufferedImage> images, String formatName)
     
    layoutThenGetInfo(String html, File baseDir)
    <html> <head> <style> @page { margin: 0px; size: ${pageWidth}mm 1mm; } </style> </head> </html> if (isSinglePage) { PDFBox.LayoutInfo layoutInfo = PDFBox.layoutThenGetInfo(html, baseDir); if (layoutInfo.getPageCount() > 1) { float pageHeightMillimeters = layoutInfo.getPageHeight() * layoutInfo.getPageCount() / PDFBox.POINTS_PER_MM + 5;//add extral space html = html.replaceFirst("1mm;", pageHeightMillimeters + "mm;"); } }
    static int
    loadFonts(File fontCacheDir, File fontDir)
     
    static List<byte[]>
    pdf2Images(byte[] pdfData, float dpi, String formatName, org.apache.pdfbox.rendering.RenderDestination destination)
     
    static List<byte[]>
    pdf2Images(byte[] pdfData, float dpi, org.apache.pdfbox.rendering.ImageType imageType, String formatName, org.apache.pdfbox.rendering.RenderDestination destination)
     
    pdf2Images(byte[] pdfData, float dpi, org.apache.pdfbox.rendering.ImageType imageType, org.apache.pdfbox.rendering.RenderDestination destination)
     
    static List<byte[]>
    pdf2Images(File pdfFile, float dpi, org.apache.pdfbox.rendering.ImageType imageType, String formatName, org.apache.pdfbox.rendering.RenderDestination destination)
     
    pdf2Images(File pdfFile, float dpi, org.apache.pdfbox.rendering.ImageType imageType, org.apache.pdfbox.rendering.RenderDestination destination)
     
    pdf2Images(org.apache.pdfbox.pdmodel.PDDocument document, float dpi, org.apache.pdfbox.rendering.ImageType imageType, org.apache.pdfbox.rendering.RenderDestination destination)
     
    static int
    useFonts(com.openhtmltopdf.pdfboxout.PdfRendererBuilder builder, org.apache.pdfbox.pdmodel.PDDocument doc)
     
    static byte[]
    writePDF(PDFBox.Writer writer, Object dto, float pdfVersion)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • POINTS_PER_MM

      public static final float POINTS_PER_MM
      See Also:
    • FONTS

      protected static final Map<String,org.apache.pdfbox.pdmodel.font.PDFont> FONTS
    • fontFiles

      protected static File[] fontFiles
    • fonts

      protected static Map<File,String> fonts
    • DEFAULT_AP

      protected static final org.apache.pdfbox.pdmodel.encryption.AccessPermission DEFAULT_AP
    • DEFAULT_KEY_LENGTH

      protected static final int DEFAULT_KEY_LENGTH
      See Also:
  • Constructor Details

    • PDFBox

      public PDFBox()
  • Method Details

    • getFont

      public static org.apache.pdfbox.pdmodel.font.PDFont getFont(String name)
    • loadFonts

      public static int loadFonts(File fontCacheDir, File fontDir) throws IOException
      Throws:
      IOException
    • getFontFiles

      public static File[] getFontFiles()
    • getFonts

      public static Map<File,String> getFonts()
      Returns:
      <font file, fontFamily>
    • useFonts

      public static int useFonts(com.openhtmltopdf.pdfboxout.PdfRendererBuilder builder, org.apache.pdfbox.pdmodel.PDDocument doc) throws IOException
      Throws:
      IOException
    • buildDefaultAccessPermission

      public static org.apache.pdfbox.pdmodel.encryption.AccessPermission buildDefaultAccessPermission()
    • buildStandardProtectionPolicy

      public static org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy buildStandardProtectionPolicy(String userPwd, String ownerPwd)
    • buildStandardProtectionPolicy

      public static org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy buildStandardProtectionPolicy(String userPwd, String ownerPwd, org.apache.pdfbox.pdmodel.encryption.AccessPermission ap, int keyLenth)
    • html2PDF

      public static byte[] html2PDF(String html, File baseDir, org.apache.pdfbox.pdmodel.encryption.ProtectionPolicy protectionPolicy, org.apache.pdfbox.pdmodel.PDDocumentInformation info, float pdfVersion, float pageWidth, float pageHeight, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.PageSizeUnits units) throws IOException
      Throws:
      IOException
    • layoutThenGetInfo

      public static PDFBox.LayoutInfo layoutThenGetInfo(String html, File baseDir) throws IOException
      
       <html>
       <head>
       <style>
        @page {
            margin: 0px;
            size: ${pageWidth}mm 1mm;
        }
       </style>
       </head>
       </html>
      
       if (isSinglePage) {
            PDFBox.LayoutInfo layoutInfo = PDFBox.layoutThenGetInfo(html, baseDir);
            if (layoutInfo.getPageCount() > 1) {
                float pageHeightMillimeters = layoutInfo.getPageHeight() * layoutInfo.getPageCount() / PDFBox.POINTS_PER_MM + 5;//add extral space
                html = html.replaceFirst("1mm;", pageHeightMillimeters + "mm;");
            }
       }
       
      Parameters:
      html -
      baseDir -
      Returns:
      Throws:
      IOException
    • html2PDF

      public static byte[] html2PDF(String html, File baseDir, org.apache.pdfbox.pdmodel.encryption.ProtectionPolicy protectionPolicy, org.apache.pdfbox.pdmodel.PDDocumentInformation info, float pdfVersion) throws IOException
      Throws:
      IOException
    • buildBaseDocumentUri1

      protected static String buildBaseDocumentUri1(File baseDirectory) throws IOException
      Throws:
      IOException
    • pdf2Images

      public static List<byte[]> pdf2Images(byte[] pdfData, float dpi, String formatName, org.apache.pdfbox.rendering.RenderDestination destination) throws IOException
      Parameters:
      pdfData -
      dpi -
      formatName - a String containing the informal name of a format (e.g., "jpeg", "png" or "tiff".
      destination -
      Returns:
      Throws:
      IOException
    • pdf2Images

      public static List<byte[]> pdf2Images(byte[] pdfData, float dpi, org.apache.pdfbox.rendering.ImageType imageType, String formatName, org.apache.pdfbox.rendering.RenderDestination destination) throws IOException
      Parameters:
      pdfData -
      dpi -
      imageType -
      formatName - a String containing the informal name of a format (e.g., "jpeg", "png" or "tiff".
      destination -
      Returns:
      Throws:
      IOException
    • pdf2Images

      public static List<byte[]> pdf2Images(File pdfFile, float dpi, org.apache.pdfbox.rendering.ImageType imageType, String formatName, org.apache.pdfbox.rendering.RenderDestination destination) throws IOException
      Parameters:
      pdfFile -
      dpi -
      imageType -
      formatName - a String containing the informal name of a format (e.g., "jpeg", "png" or "tiff".
      destination -
      Returns:
      Throws:
      IOException
    • pdf2Images

      public static List<BufferedImage> pdf2Images(byte[] pdfData, float dpi, org.apache.pdfbox.rendering.ImageType imageType, org.apache.pdfbox.rendering.RenderDestination destination) throws IOException
      Throws:
      IOException
    • pdf2Images

      public static List<BufferedImage> pdf2Images(File pdfFile, float dpi, org.apache.pdfbox.rendering.ImageType imageType, org.apache.pdfbox.rendering.RenderDestination destination) throws IOException
      Throws:
      IOException
    • pdf2Images

      public static List<BufferedImage> pdf2Images(org.apache.pdfbox.pdmodel.PDDocument document, float dpi, org.apache.pdfbox.rendering.ImageType imageType, org.apache.pdfbox.rendering.RenderDestination destination) throws IOException
      Parameters:
      document - make sure the caller will close the document
      dpi - 300
      imageType -
      destination -
      Returns:
      Throws:
      IOException
    • images2Bytes

      public static List<byte[]> images2Bytes(List<BufferedImage> images, String formatName) throws IOException
      Parameters:
      images -
      formatName - a String containing the informal name of a format (e.g., "jpeg", "png" or "tiff".
      Returns:
      Throws:
      IOException
    • writePDF

      public static byte[] writePDF(PDFBox.Writer writer, Object dto, float pdfVersion) throws IOException
      Throws:
      IOException