Search in sources :

Example 1 with PDFParser

use of com.tom_roush.pdfbox.pdfparser.PDFParser in project PdfBox-Android by TomRoush.

the class PDDocument method load.

/**
 * Parses a PDF.
 *
 * @param input byte array that contains the document.
 * @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 input stream and PDF streams
 *
 * @return loaded document
 *
 * @throws InvalidPasswordException If the password is incorrect.
 * @throws IOException In case of a reading or parsing error.
 */
public static PDDocument load(byte[] input, String password, InputStream keyStore, String alias, MemoryUsageSetting memUsageSetting) throws IOException {
    ScratchFile scratchFile = new ScratchFile(memUsageSetting);
    RandomAccessRead source = new RandomAccessBuffer(input);
    PDFParser parser = new PDFParser(source, password, keyStore, alias, scratchFile);
    parser.parse();
    return parser.getPDDocument();
}
Also used : RandomAccessRead(com.tom_roush.pdfbox.io.RandomAccessRead) RandomAccessBuffer(com.tom_roush.pdfbox.io.RandomAccessBuffer) ScratchFile(com.tom_roush.pdfbox.io.ScratchFile) PDFParser(com.tom_roush.pdfbox.pdfparser.PDFParser)

Example 2 with PDFParser

use of com.tom_roush.pdfbox.pdfparser.PDFParser in project PdfBox-Android by TomRoush.

the class SignatureOptions method initFromRandomAccessRead.

private void initFromRandomAccessRead(RandomAccessRead rar) throws IOException {
    pdfSource = rar;
    PDFParser parser = new PDFParser(pdfSource);
    parser.parse();
    visualSignature = parser.getDocument();
}
Also used : PDFParser(com.tom_roush.pdfbox.pdfparser.PDFParser)

Example 3 with PDFParser

use of com.tom_roush.pdfbox.pdfparser.PDFParser in project PdfBox-Android by TomRoush.

the class PDDocument method load.

/**
 * Parses a PDF. Depending on the memory settings parameter the given input stream is either
 * copied to memory or to a temporary file to enable random access to the pdf.
 *
 * @param input stream that contains the document. Don't forget to close it after loading.
 * @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 input stream and PDF streams
 *
 * @return loaded document
 *
 * @throws InvalidPasswordException If the password is incorrect.
 * @throws IOException In case of a reading or parsing error.
 */
public static PDDocument load(InputStream input, String password, InputStream keyStore, String alias, MemoryUsageSetting memUsageSetting) throws IOException {
    ScratchFile scratchFile = new ScratchFile(memUsageSetting);
    try {
        RandomAccessRead source = scratchFile.createBuffer(input);
        PDFParser parser = new PDFParser(source, password, keyStore, alias, scratchFile);
        parser.parse();
        return parser.getPDDocument();
    } catch (IOException ioe) {
        IOUtils.closeQuietly(scratchFile);
        throw ioe;
    }
}
Also used : RandomAccessRead(com.tom_roush.pdfbox.io.RandomAccessRead) ScratchFile(com.tom_roush.pdfbox.io.ScratchFile) PDFParser(com.tom_roush.pdfbox.pdfparser.PDFParser) IOException(java.io.IOException)

Example 4 with PDFParser

use of com.tom_roush.pdfbox.pdfparser.PDFParser in project PdfBox-Android by TomRoush.

the class PDDocument method load.

private static PDDocument load(RandomAccessBufferedFileInputStream raFile, String password, InputStream keyStore, String alias, MemoryUsageSetting memUsageSetting) throws IOException {
    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;
    }
}
Also used : ScratchFile(com.tom_roush.pdfbox.io.ScratchFile) PDFParser(com.tom_roush.pdfbox.pdfparser.PDFParser) IOException(java.io.IOException)

Aggregations

PDFParser (com.tom_roush.pdfbox.pdfparser.PDFParser)4 ScratchFile (com.tom_roush.pdfbox.io.ScratchFile)3 RandomAccessRead (com.tom_roush.pdfbox.io.RandomAccessRead)2 IOException (java.io.IOException)2 RandomAccessBuffer (com.tom_roush.pdfbox.io.RandomAccessBuffer)1