I'm retrieving a PDF in the form of a byte array from the internet. Once I recieve it, I've been able to convert it to a File using this method:
File dir = Environment.getExternalStorageDirectory();
File assist = new File(Environment.getExternalStorageDirectory() + "/Sample.pdf");
try {
InputStream fis = new FileInputStream(assist);
long length = assist.length();
if (length > Integer.MAX_VALUE) {
Log.e("Print error", "Too large");
}
byte[] bytes = new byte[(int) length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = fis.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}
return new File(dir, "mydemo.pdf");
} catch (IOException e) {
e.printStackTrace();
return null;
}
Now that I have the file, what do I do? On the official dev site: https://developer.android.com/training/printing/custom-docs.html it doesn't give specific information for this, doesn't the Print Manager have a method to handle this for us when I give it a File
? Or do I have to manually create an adapter? If so, how would I get the page count (which I read is obligatory) and what would I do in onWrite()
?