I am trying to save an input stream from a HTTPSUrlConnection to a PDF file stored on the device. It looks like it goes smoothly. However, when I loads the document in PDFView, I receive the following error: PDF is corrupted.
private void saveAsPDF(DataInputStream inputStream, final String filename)
{
try {
FileOutputStream fileOutputStream = context.openFileOutput(filename, Context.MODE_PRIVATE);
fileOutputStream.write(IOUtils.toByteArray(inputStream));
fileOutputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
And here is how I load the pdf document in PDFView:
private void loadPDFData()
{
File file = new File(princhDocument.getPath());
pdfView.fromFile(file).onLoad(new OnLoadCompleteListener() {
@Override
public void loadComplete(int i) {
princhDocument.setNumberOfPages(pdfView.getPageCount());
pdfView.recycle();
}
}).load();
}