Search in sources :

Example 1 with RandomAccessBufferedFileInputStream

use of org.apache.pdfbox.io.RandomAccessBufferedFileInputStream in project pdfbox by apache.

the class PDDocument method load.

/**
 * Parses a PDF.
 *
 * @param file file to be loaded
 * @param password password to be used for decryption
 * @param keyStore key store to be used for decryption when using public key security
 * @param alias alias to be used for decryption when using public key security
 * @param memUsageSetting defines how memory is used for buffering PDF streams
 *
 * @return loaded document
 *
 * @throws IOException in case of a file reading or parsing error
 */
public static PDDocument load(File file, String password, InputStream keyStore, String alias, MemoryUsageSetting memUsageSetting) throws IOException {
    RandomAccessBufferedFileInputStream raFile = new RandomAccessBufferedFileInputStream(file);
    try {
        ScratchFile scratchFile = new ScratchFile(memUsageSetting);
        try {
            PDFParser parser = new PDFParser(raFile, password, keyStore, alias, scratchFile);
            parser.parse();
            return parser.getPDDocument();
        } catch (IOException ioe) {
            IOUtils.closeQuietly(scratchFile);
            throw ioe;
        }
    } catch (IOException ioe) {
        IOUtils.closeQuietly(raFile);
        throw ioe;
    }
}
Also used : ScratchFile(org.apache.pdfbox.io.ScratchFile) PDFParser(org.apache.pdfbox.pdfparser.PDFParser) IOException(java.io.IOException) RandomAccessBufferedFileInputStream(org.apache.pdfbox.io.RandomAccessBufferedFileInputStream)

Aggregations

IOException (java.io.IOException)1 RandomAccessBufferedFileInputStream (org.apache.pdfbox.io.RandomAccessBufferedFileInputStream)1 ScratchFile (org.apache.pdfbox.io.ScratchFile)1 PDFParser (org.apache.pdfbox.pdfparser.PDFParser)1