[英]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.