问题描述
可惜的是,我还没有发现在这一点上的任何文件,所以也许我做错了什么。
Unfortunatelly, I haven't found any documentation on this point, so maybe I do something wrong.
我使用的为Android mupdf样本,我稍微修改MuPDFActivity源$ C $ C是这样的:
I use mupdf sample for android and I have slightly modified the source code of MuPDFActivity this way:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAlertBuilder = new AlertDialog.Builder(this);
if (core == null) {
core = (MuPDFCore)getLastNonConfigurationInstance();
if (savedInstanceState != null && savedInstanceState.containsKey("FileName")) {
mFileName = savedInstanceState.getString("FileName");
}
}
if (core == null) {
Intent intent = getIntent();
byte buffer[] = null;
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
Uri uri = intent.getData();
try {
InputStream inputStream = new FileInputStream(new File(uri.toString()));
int len = inputStream.available();
buffer = new byte[len];
inputStream.read(buffer, 0, len);
inputStream.close();
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
if (buffer != null) {
core = openBuffer(buffer);
} else {
core = openFile(Uri.decode(uri.getEncodedPath()));
}
SearchTaskResult.set(null);
}
活动的openBuffer()方法没有改变:
The activity's openBuffer() method hasn't been changed:
private MuPDFCore openBuffer(byte buffer[]) {
System.out.println("Trying to open byte buffer");
try {
core = new MuPDFCore(this, buffer);
// New file: drop the old outline data
OutlineActivityData.set(null);
} catch (Exception e) {
System.out.println(e);
return null;
}
return core;
}
在我尝试打开任何PDF,应用程序显示了信息提示无法打开文件。这是日志:
After I try to open any pdf, app shows alert with message "Cannot open document". This is logs:
03-21 10:43:14.754 3601-3601/com.artifex.mupdfdemo.debug E/libmupdf﹕ Opening document...
03-21 10:43:14.754 3601-3601/com.artifex.mupdfdemo.debug E/libmupdf﹕ error: No document handlers registered
03-21 10:43:14.754 3601-3601/com.artifex.mupdfdemo.debug E/libmupdf﹕ error: Cannot open memory document
03-21 10:43:14.754 3601-3601/com.artifex.mupdfdemo.debug E/libmupdf﹕ Failed: Cannot open memory document
所以,无论有什么办法来打开PDF文件作为一个字节数组,这是什么呀?
So, whether there is any way to open pdf file as a byte array and what is this way?
推荐答案
我的猜测是,你正在使用一个版本的Android JNI文件mupdf.c比主库文件的版本较旧的。有库API,这需要fz_register_document_handlers(CTX)的变化被称为创建上下文并调用fz_open_document之间。你所看到的第一个错误信息表明,fz_register_document_handlers不被称为
My guess is that you are using a version of the android jni file mupdf.c that is older than the version of the main library files. There was a change in the library API which necessitates fz_register_document_handlers(ctx) being called between creating the context and calling fz_open_document. The first error message you are seeing suggests that fz_register_document_handlers is not being called
这篇关于mupdf:如何打开PDF文件,openBuffer方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!