I am running an app on google-app-engine.
trying to get txt from pdf-file on google-cloud-storage.
when I run my code locally it succeeds, but when running on appengine it fails with org.pdfbox.exceptions.WrappedIOException
here is my code:
import com.google.cloud.storage.*;
import org.pdfbox.pdfparser.PDFParser;
import org.pdfbox.pdmodel.PDDocument;
import org.pdfbox.util.PDFTextStripper;
public class Download {
public static String perform(String bucket, String file) throws IOException {
byte[] fileByte = download(bucket, file);
String pdfFileTxt = pdf2txt(fileByte);
return pdfFileTxt;
}
public static byte[] download(String bucketName, String fileId) throws IOException {
Storage storage = StorageOptions.getDefaultInstance().getService();
BlobId blobId = BlobId.of(bucketName, fileId);
Blob blob = storage.get(blobId);
return blob.getContent();
}
public static String pdf2txt(byte[] byteArr) throws IOException {
InputStream stream = new ByteArrayInputStream(byteArr);
PDFParser parser = new PDFParser(stream);
parser.parse();
PDDocument pdDoc = new PDDocument(parser.getDocument());
return new PDFTextStripper().getText(pdDoc);
}
}
the code fails on parser.parse();
with org.pdfbox.exceptions.WrappedIOException
- no other message is added :(
the download from storage - actually succeeds. If I log the data I get something like:
%PDF-1.3
%����
7 0 obj
<</Linearized 1/L 7945/O 9/E 3524/N 1/T 7656/H [ 451 137]>>
endobj
13 0 obj
<</DecodeParms<</Columns 4/Predictor 12>>/Filter/FlateDecode/ID[<4DC91A1875A6D707AEC203BB021C93A0><F6C92B368A8A13408457A1D395A37EB9>]/Index[7 21]/Info 6 0 R/Length 52/Prev 7657/Root 8 0 R/Size 28/Type/XRef/W[1 2 1]>>stream
h�bbd``b`� ��H0� 6G ��#�4�,#��Ɲ_ L��
endstream
endobj
startxref
0
%%EOF
... more ...
now is there anyway to overcome this? Maybe use different libraries? Since the code is running on appengine - it's quite difficult to track these errors.