Package org.summerboot.jexpress.util.pdf
Class PDFBox
java.lang.Object
org.summerboot.jexpress.util.pdf.PDFBox
- Author:
- Changski Tie Zheng Zhang 张铁铮, 魏泽北, 杜旺财, 杜富贵
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.apache.pdfbox.pdmodel.encryption.AccessPermissionprotected static final intprotected static File[]static final float -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static StringbuildBaseDocumentUri1(File baseDirectory) static org.apache.pdfbox.pdmodel.encryption.AccessPermissionstatic org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicybuildStandardProtectionPolicy(String userPwd, String ownerPwd) static org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicybuildStandardProtectionPolicy(String userPwd, String ownerPwd, org.apache.pdfbox.pdmodel.encryption.AccessPermission ap, int keyLenth) static org.apache.pdfbox.pdmodel.font.PDFontstatic File[]getFonts()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) static PDFBox.LayoutInfolayoutThenGetInfo(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 intstatic 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) static List<BufferedImage> 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) static List<BufferedImage> pdf2Images(File pdfFile, float dpi, org.apache.pdfbox.rendering.ImageType imageType, org.apache.pdfbox.rendering.RenderDestination destination) static List<BufferedImage> pdf2Images(org.apache.pdfbox.pdmodel.PDDocument document, float dpi, org.apache.pdfbox.rendering.ImageType imageType, org.apache.pdfbox.rendering.RenderDestination destination) static intuseFonts(com.openhtmltopdf.pdfboxout.PdfRendererBuilder builder, org.apache.pdfbox.pdmodel.PDDocument doc) static byte[]writePDF(PDFBox.Writer writer, Object dto, float pdfVersion)
-
Field Details
-
POINTS_PER_MM
public static final float POINTS_PER_MM- See Also:
-
FONTS
-
fontFiles
-
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
-
loadFonts
- Throws:
IOException
-
getFontFiles
-
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
-
buildStandardProtectionPolicy
-
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
<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
- 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- aStringcontaining 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- aStringcontaining 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- aStringcontaining 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 documentdpi- 300imageType-destination-- Returns:
- Throws:
IOException
-
images2Bytes
public static List<byte[]> images2Bytes(List<BufferedImage> images, String formatName) throws IOException - Parameters:
images-formatName- aStringcontaining 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
-