向 MuPDF 添加注释 android

Adding annotation to MuPDF android

我已经使用 MuPDF 实现了 pdf lib.I 我在谷歌搜索了一下后试图绘制 pdf 我发现 MuPDFCore.addInkAnnotation(int page, PointF[][] arcs) 会在 pdf 中添加 Ink 注释。当我调用 addInkAnnotation 方法时它崩溃了。 这是我的示例代码,我试图用它来查看在 Pdf 上注释的内容但是没有运气。

PointF[][] p=new PointF[1][1];
PointF [] points=new PointF[2];
points[0]=new PointF(200, 200);
points[1]=new PointF(200, 200);

PointF [] points2=new PointF[2];
points2[0]=new PointF(200, 200);
points2[1]=new PointF(200, 200);

core.addInkAnnotation(2, p);

其中核心是 MuPDFCore 对象。

错误日志。

02-17 20:22:24.610: W/dalvikvm(25082): JNI WARNING: illegal class name 'android.graphics.PointF' (FindClass)
02-17 20:22:24.610: W/dalvikvm(25082):              (should be formed like 'dalvik/system/DexFile')
02-17 20:22:24.610: W/dalvikvm(25082):              or '[Ldalvik/system/DexFile;' or '[[B')
02-17 20:22:24.610: I/dalvikvm(25082): "main" prio=5 tid=1 NATIVE
02-17 20:22:24.610: I/dalvikvm(25082):   | group="main" sCount=0 dsCount=0 obj=0x411af508 self=0x41194208
02-17 20:22:24.610: I/dalvikvm(25082):   | sysTid=25082 nice=0 sched=0/0 cgrp=apps handle=1075171120
02-17 20:22:24.610: I/dalvikvm(25082):   | schedstat=( 2908935486 1958496146 7720 ) utm=232 stm=57 core=1
02-17 20:22:24.626: I/dalvikvm(25082):   #00  pc 00001260  /system/lib/libcorkscrew.so (unwind_backtrace_thread+27)
02-17 20:22:24.626: I/dalvikvm(25082):   #01  pc 0005f944  /system/lib/libdvm.so (dvmDumpNativeStack(DebugOutputTarget const*, int)+35)
02-17 20:22:24.626: I/dalvikvm(25082):   #02  pc 000537ec  /system/lib/libdvm.so (dvmDumpThreadEx(DebugOutputTarget const*, Thread*, bool)+303)
02-17 20:22:24.626: I/dalvikvm(25082):   #03  pc 00053886  /system/lib/libdvm.so (dvmDumpThread(Thread*, bool)+25)
02-17 20:22:24.626: I/dalvikvm(25082):   #04  pc 00038e42  /system/lib/libdvm.so
02-17 20:22:24.626: I/dalvikvm(25082):   #05  pc 00041b3e  /system/lib/libdvm.so
02-17 20:22:24.626: I/dalvikvm(25082):   #06  pc 000252f4  /data/data/com.example.pdf/lib/libmupdf.so (Java_com_artifex_mupdfdemo_MuPDFCore_addInkAnnotationInternal+355)
02-17 20:22:24.626: I/dalvikvm(25082):   #07  pc 0001deb0  /system/lib/libdvm.so (dvmPlatformInvoke+112)
02-17 20:22:24.626: I/dalvikvm(25082):   #08  pc 0004d102  /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+393)
02-17 20:22:24.626: I/dalvikvm(25082):   #09  pc 0004f21c  /system/lib/libdvm.so (dvmResolveNativeMethod(unsigned int const*, JValue*, Method const*, Thread*)+171)
02-17 20:22:24.626: I/dalvikvm(25082):   #10  pc 000272e0  /system/lib/libdvm.so
02-17 20:22:24.626: I/dalvikvm(25082):   #11  pc 0002bbe8  /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+180)
02-17 20:22:24.626: I/dalvikvm(25082):   #12  pc 0005fb36  /system/lib/libdvm.so (dvmInvokeMethod(Object*, Method const*, ArrayObject*, ArrayObject*, ClassObject*, bool)+373)
02-17 20:22:24.626: I/dalvikvm(25082):   #13  pc 000670e4  /system/lib/libdvm.so
02-17 20:22:24.626: I/dalvikvm(25082):   #14  pc 000272e0  /system/lib/libdvm.so
02-17 20:22:24.626: I/dalvikvm(25082):   #15  pc 0002bbe8  /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+180)
02-17 20:22:24.626: I/dalvikvm(25082):   #16  pc 0005f870  /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+271)
02-17 20:22:24.626: I/dalvikvm(25082):   #17  pc 000496f2  /system/lib/libdvm.so
02-17 20:22:24.626: I/dalvikvm(25082):   #18  pc 0004857e  /system/lib/libandroid_runtime.so
02-17 20:22:24.626: I/dalvikvm(25082):   #19  pc 00049696  /system/lib/libandroid_runtime.so (android::AndroidRuntime::start(char const*, char const*)+389)
02-17 20:22:24.626: I/dalvikvm(25082):   #20  pc 00000dce  /system/bin/app_process
02-17 20:22:24.626: I/dalvikvm(25082):   #21  pc 00017040  /system/lib/libc.so (__libc_init+35)
02-17 20:22:24.626: I/dalvikvm(25082):   at com.artifex.mupdfdemo.MuPDFCore.addInkAnnotationInternal(Native Method)
02-17 20:22:24.626: I/dalvikvm(25082):   at com.artifex.mupdfdemo.MuPDFCore.addInkAnnotation(MuPDFCore.java:296)

我认为应该是:

PointF[][] p=new PointF[2][];
PointF [] points=new PointF[2];
points[0]=new PointF(200, 200);
points[1]=new PointF(200, 200);

PointF [] points2=new PointF[2];
points2[0]=new PointF(200, 200);
points2[1]=new PointF(200, 200);

p[0] = points;
p[1] = points2;

core.addInkAnnotation(0, p);

第一个 new 应该只指定外部数组的长度,而不是内部数组的长度 - 它应该是长度 2,因为你指定了 2 个弧。

您忽略了将外部数组元素设置为内部数组。

addInkAnnotation 的第一个参数是页码,因此 0 更有可能是您想要进行测试的。

根据您对库执行其他调用的方式,您可能需要通过 AsyncTask 进行 addInkAnnotation 调用。