Search in sources :

Example 1 with RandomAccessBuffer

use of org.apache.pdfbox.io.RandomAccessBuffer in project tika by apache.

the class PDFEncodedStringDecoder method decode.

/**
     * This assumes that {@link #shouldDecode(String)} has been called
     * and has returned true.  If you run this on a non-octal encoded string,
     * disaster will happen!
     *
     * @param value
     * @return
     */
String decode(String value) {
    try {
        byte[] bytes = new String("(" + value + ")").getBytes(ISO_8859_1);
        InputStream is = new ByteArrayInputStream(bytes);
        COSStringParser p = new COSStringParser(new RandomAccessBuffer(is));
        String parsed = p.myParseCOSString();
        if (parsed != null) {
            return parsed;
        }
    } catch (IOException e) {
    //oh well, we tried.
    }
    //just return value if something went wrong
    return value;
}
Also used : RandomAccessBuffer(org.apache.pdfbox.io.RandomAccessBuffer) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) COSString(org.apache.pdfbox.cos.COSString) IOException(java.io.IOException)

Example 2 with RandomAccessBuffer

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

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(org.apache.pdfbox.io.RandomAccessRead) RandomAccessBuffer(org.apache.pdfbox.io.RandomAccessBuffer) ScratchFile(org.apache.pdfbox.io.ScratchFile) PDFParser(org.apache.pdfbox.pdfparser.PDFParser)

Aggregations

RandomAccessBuffer (org.apache.pdfbox.io.RandomAccessBuffer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 COSString (org.apache.pdfbox.cos.COSString)1 RandomAccessRead (org.apache.pdfbox.io.RandomAccessRead)1 ScratchFile (org.apache.pdfbox.io.ScratchFile)1 PDFParser (org.apache.pdfbox.pdfparser.PDFParser)1