[英]How read chunk files and show as pdf in android?
是否可以将pdf文件转换为一些块,然后读取该块并在PdfViewer android中显示该块? 如果可能的话,请指导我该怎么做。
我发现这种将pdf转换成块的方法:
private void getBytesFromFile(File file) throws IOException {
FileInputStream is = new FileInputStream(file); //videorecorder stores video to file
java.nio.channels.FileChannel fc = is.getChannel();
java.nio.ByteBuffer bb = java.nio.ByteBuffer.allocate(10000);
int chunkCount = 0;
byte[] bytes;
while(fc.read(bb) >= 0){
bb.flip();
//save the part of the file into a chunk
bytes = bb.array();
storeByteArrayToFile(bytes, mRecordingFile + "." + chunkCount);//mRecordingFile is the (String)path to file
chunkCount++;
bb.clear();
}
}
private void storeByteArrayToFile(byte[] bytesToSave, String path) throws IOException {
FileOutputStream fOut = new FileOutputStream(path);
try {
fOut.write(bytesToSave);
}
catch (Exception ex) {
Log.e("ERROR", ex.getMessage());
}
finally {
fOut.close();
}
}
我使用AndroidPdfViewer显示pdf,但是如果您知道其他显示pdf的库或方法,请提及。 谢谢。
您可以借助PDF线性化来实现。 基本上,这是PDF的标准功能,其中数据以这种方式组织,以实现按需流内容。 为此,您还需要使用支持线性化的PDF Viewer(例如https://www.pdftron.com/documentation/android/guides/viewer/view-online-pdfs/ )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.