Package adams.core.io
Class PDFBox
- java.lang.Object
-
- adams.core.io.PDFBox
-
public class PDFBox extends Object
Helper class for PDFBox library.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
-
-
Constructor Summary
Constructors Constructor Description PDFBox()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
close(org.apache.pdfbox.pdmodel.PDDocument document)
Closes the document again.static List<BufferedImage>
extractImages(byte[] data)
Extracts images from a PDF document.static List<BufferedImage>
extractImages(File file)
Extracts images from a PDF document.static List<BufferedImage>
extractImages(org.apache.pdfbox.pdmodel.PDDocument document)
Extracts images from a PDF document.static List<RenderedImage>
extractImagesFromResources(org.apache.pdfbox.pdmodel.PDResources resources)
Extracts images from PDF resources.static String
extractText(byte[] data)
Extracts the text from the PDF.static String
extractText(File file)
Extracts the text from the PDF.static int
getPageCount(File file)
Returns the number of pages in the PDF document.static org.apache.pdfbox.pdmodel.PDDocument
load(File file)
Loads the PDF file.static org.apache.pdfbox.pdmodel.PDDocument
load(String filename)
Loads the PDF file.static boolean
print(File file)
Prints the PDF document.static boolean
print(String filename)
Prints the PDF document.static boolean
print(org.apache.pdfbox.pdmodel.PDDocument document)
Prints the PDF document.static boolean
printWithDialog(File file)
Prints the PDF document, bringing up a dialog.static boolean
printWithDialog(org.apache.pdfbox.pdmodel.PDDocument document)
Prints the PDF document, bringing up a dialog.static boolean
save(org.apache.pdfbox.pdmodel.PDDocument doc, File file)
Saves the PDF document under the specified filename.static boolean
save(org.apache.pdfbox.pdmodel.PDDocument doc, String file)
Saves the PDF document under the specified filename.
-
-
-
Method Detail
-
load
public static org.apache.pdfbox.pdmodel.PDDocument load(String filename)
Loads the PDF file.- Parameters:
filename
- the filename of the PDF- Returns:
- the PDF document, null if failed to load
-
load
public static org.apache.pdfbox.pdmodel.PDDocument load(File file)
Loads the PDF file.- Parameters:
file
- the PDF file- Returns:
- the PDF document, null if failed to load
-
close
public static void close(org.apache.pdfbox.pdmodel.PDDocument document)
Closes the document again.- Parameters:
document
- the document to close, can be null
-
save
public static boolean save(org.apache.pdfbox.pdmodel.PDDocument doc, String file)
Saves the PDF document under the specified filename.- Parameters:
doc
- the document to savefile
- the file to save the document to- Returns:
- true if successfully saved
-
save
public static boolean save(org.apache.pdfbox.pdmodel.PDDocument doc, File file)
Saves the PDF document under the specified filename.- Parameters:
doc
- the document to savefile
- the file to save the document to- Returns:
- true if successfully saved
-
print
public static boolean print(String filename)
Prints the PDF document.- Parameters:
filename
- the filename of the PDF to print- Returns:
- true if successfully printed
-
print
public static boolean print(File file)
Prints the PDF document.- Parameters:
file
- the PDF file print- Returns:
- true if successfully printed
-
print
public static boolean print(org.apache.pdfbox.pdmodel.PDDocument document)
Prints the PDF document.- Parameters:
document
- the PDF document to print- Returns:
- true if successfully printed
-
printWithDialog
public static boolean printWithDialog(File file)
Prints the PDF document, bringing up a dialog.- Parameters:
file
- the PDF file print- Returns:
- true if successfully printed
-
printWithDialog
public static boolean printWithDialog(org.apache.pdfbox.pdmodel.PDDocument document)
Prints the PDF document, bringing up a dialog.- Parameters:
document
- the PDF document to print- Returns:
- true if successfully printed
-
getPageCount
public static int getPageCount(File file)
Returns the number of pages in the PDF document.- Parameters:
file
- the PDF file to get the page count for- Returns:
- the page count, -1 if failed to determine
-
extractText
public static String extractText(File file)
Extracts the text from the PDF.- Parameters:
file
- the PDF to get the text from- Returns:
- the text, null if failed to extract
-
extractText
public static String extractText(byte[] data)
Extracts the text from the PDF.- Parameters:
data
- the PDF (binary data) to get the text from- Returns:
- the text, null if failed to extract
-
extractImagesFromResources
public static List<RenderedImage> extractImagesFromResources(org.apache.pdfbox.pdmodel.PDResources resources) throws IOException
Extracts images from PDF resources.- Parameters:
resources
- the resources to extract the images from- Returns:
- the list of extracted images
- Throws:
IOException
- if extraction fails
-
extractImages
public static List<BufferedImage> extractImages(org.apache.pdfbox.pdmodel.PDDocument document) throws IOException
Extracts images from a PDF document.- Parameters:
document
- the document to extract the images from- Returns:
- the list of extracted images
- Throws:
IOException
- if extraction fails
-
extractImages
public static List<BufferedImage> extractImages(File file) throws IOException
Extracts images from a PDF document.- Parameters:
file
- the file to extract the images from- Returns:
- the list of extracted images
- Throws:
IOException
- if extraction fails
-
extractImages
public static List<BufferedImage> extractImages(byte[] data) throws IOException
Extracts images from a PDF document.- Parameters:
data
- the PDF data to extract the images from- Returns:
- the list of extracted images
- Throws:
IOException
- if extraction fails
-
-