我已经使用MuPDF lib实现了pdf。我在谷歌搜索了一下我发现MuPDFCore.addInkAnnotation(int page, PointF[][] arcs)会将Ink注释添加到pdf后试图绘制pdf。当我调用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);


其中core是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);


第一个新字符串应仅指定外部数组的长度,而不是内部数组的长度-且其长度应为2,请参见要指定2个圆弧。

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

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

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

关于android - 向MuPDF android添加注释,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28564204/

10-10 19:31