In this link, one of my previous posts, I have explained how to add mupdf library as a module into an Android Studio project. You can either start with this guide or directly continue to this post.
The target file to edit is mupdf.c. This file contains ndk functions in order to be called from java part. We will just add a ndk function to fetch metadata of a pdf file. Because mupdf library has a functionality to provide it, we don't need any further coding.
I am working with mupdf with version: 1.6. When I use the function above, I have get an error. After some debugging, I recognized that the problem is on following line in pdf-xref.c file.
Mupdf is a great library for pdf rendering. It contains many functionalities to perform on pdf files. Beyond all, it can be integrated to mobile platforms. These characteristics easily show why people tend to prefer this library. Even my post about it takes great hits. All these strongly point out that these guys deserve appreciation. Good job!
The target file to edit is mupdf.c. This file contains ndk functions in order to be called from java part. We will just add a ndk function to fetch metadata of a pdf file. Because mupdf library has a functionality to provide it, we don't need any further coding.
JNIEXPORT jobjectArray JNICALL
JNI_FN(MuPDFCore_metadataInternal)(JNIEnv * env, jobject thiz)
{
char info[64];
globals *glo = get_globals(env, thiz);
jobjectArray arr;
jclass stringClass;
const int nkeys = 4;
const char *keys[nkeys];
int i;
keys[0] = "Title";
keys[1] = "Author";
keys[2] = "Subject";
keys[3] = "Keywords";
stringClass = (*env)->FindClass(env, "java/lang/String");
arr = (*env)->NewObjectArray(env, nkeys, stringClass, NULL);
LOGI("Getting metadata");
for(i=0; idoc, FZ_META_INFO, info, sizeof(info));
LOGI("%s : %s", keys[i], info);
jstring s = (*env)->NewStringUTF(env, info);
if (s != NULL) {
(*env)->SetObjectArrayElement(env, arr, i, s);
}
(*env)->DeleteLocalRef(env, s);
}
return arr;
}
This ndk function returns a string array which contains metadata information, respectively to keys in keys array. If there is no such info for a key, it returns an empty string. As seen, just 4 of keys are retrieved. There are more in pdf, you can use them if you want too:Further explanation, refer to pdf reference guide.
- Title
- Author
- Subject
- Keywords
- Creator
- Producer
- CreationDate
- ModDate
- Trapped
I am working with mupdf with version: 1.6. When I use the function above, I have get an error. After some debugging, I recognized that the problem is on following line in pdf-xref.c file.
info = pdf_dict_gets(info, *(char **)ptr);
ptr is a void array and passed as parameter to the function. What I have passed in ndk function above is a char array. It works well until this line, but here it results a fatal error:
(Fatal signal 11 (SIGSEGV), code 1, fault addr 0x6c746954 in tid 29833)
I have done following fix on same line:
info = pdf_dict_gets(info, (char *)ptr);
Then, the problem has been solved and this functionality has begun to work smoothly.Mupdf is a great library for pdf rendering. It contains many functionalities to perform on pdf files. Beyond all, it can be integrated to mobile platforms. These characteristics easily show why people tend to prefer this library. Even my post about it takes great hits. All these strongly point out that these guys deserve appreciation. Good job!
Really Great Job...!!!
ReplyDeleteWhen i try copy and pasted into mupdf.c & compiling. it says FZ_META_INFO undeclared. please help me to fix this what shall i do for this.
If you're looking for cutting-edge Android app development services, look no further than Hoff & Mazor! As a top Android app development company in USA, we specialize in building high-performance, user-friendly, and scalable mobile solutions tailored to your business needs. Whether you're a startup or an enterprise, our expert team ensures seamless functionality, innovative design, and top-tier security. Transform your app idea into reality with Hoff & Mazor—where innovation meets excellence!
ReplyDeleteEffective book marketing is key to reaching the right audience and maximizing your book’s success. From strategic promotions to targeted campaigns, a professional approach can make all the difference. Elevate your book’s visibility and boost sales with expert marketing strategies. Ottenheimer Publishers provides comprehensive solutions to ensure your book gets the recognition it deserves.
ReplyDeleteAndroid's MuPDF library facilitates metadata extraction from PDFs to make document management smoother. Data processing is a crucial aspect of many fields. In the same way, researching procurement dissertation topics enables students to examine supply chain tactics, contract management, and purchasing trends and make more effective business operation decisions.
ReplyDelete