我正在使用PDFViewer.jar通过我的应用程序阅读pdf。
应用程序无法读取pdf,我收到此异常:
12-10 09:47:25.700: W/System.err(15665): java.io.IOException: This may not be a PDF File
12-10 09:47:25.710: W/System.err(15665): at com.sun.pdfview.PDFFile.parseFile(PDFFile.java:1395)
12-10 09:47:25.710: W/System.err(15665): at com.sun.pdfview.PDFFile.<init>(PDFFile.java:140)
12-10 09:47:25.710: W/System.err(15665): at com.sun.pdfview.PDFFile.<init>(PDFFile.java:116)
12-10 09:47:25.710: W/System.err(15665): at com.proxycensus.mysharesUK.PdfViewerActivity.openFile(PdfViewerActivity.java:851)
12-10 09:47:25.710: W/System.err(15665): at com.proxycensus.mysharesUK.PdfViewerActivity.parsePDF(PdfViewerActivity.java:815)
12-10 09:47:25.710: W/System.err(15665): at com.proxycensus.mysharesUK.PdfViewerActivity.setContent(PdfViewerActivity.java:217)
12-10 09:47:25.710: W/System.err(15665): at com.proxycensus.mysharesUK.PdfViewerActivity.onCreate(PdfViewerActivity.java:208)
12-10 09:47:25.710: W/System.err(15665): at com.proxycensus.mysharesUK.ObjActivity.onCreate(ObjActivity.java:23)
12-10 09:47:25.710: W/System.err(15665): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
12-10 09:47:25.710: W/System.err(15665): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1782)
12-10 09:47:25.710: W/System.err(15665): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1834)
12-10 09:47:25.710: W/System.err(15665): at android.app.ActivityThread.access$500(ActivityThread.java:122)
12-10 09:47:25.710: W/System.err(15665): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1027)
12-10 09:47:25.710: W/System.err(15665): at android.os.Handler.dispatchMessage(Handler.java:99)
12-10 09:47:25.710: W/System.err(15665): at android.os.Looper.loop(Looper.java:132)
12-10 09:47:25.710: W/System.err(15665): at android.app.ActivityThread.main(ActivityThread.java:4126)
12-10 09:47:25.710: W/System.err(15665): at java.lang.reflect.Method.invokeNative(Native Method)
12-10 09:47:25.710: W/System.err(15665): at java.lang.reflect.Method.invoke(Method.java:491)
12-10 09:47:25.710: W/System.err(15665): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
12-10 09:47:25.710: W/System.err(15665): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
12-10 09:47:25.710: W/System.err(15665): at dalvik.system.NativeStart.main(Native Method)
代码:
public void openFile(File file, String password) throws IOException {
// first open the file for random access
RandomAccessFile raf = new RandomAccessFile(file, "r");
// extract a file channel
FileChannel channel = raf.getChannel();
// now memory-map a byte-buffer
ByteBuffer bb =
ByteBuffer.NEW(channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()));
// create a PDFFile from the data
if (password == null)
mPdfFile = new PDFFile(bb);
else
mPdfFile = new PDFFile(bb, new PDFPassword(password));
mGraphView.showText("CLHed:" + mPdfFile.getNumPages());
}
我得到的路径:
12-10 10:03:27.550: E/ObjActivity(16090): path =/data/data/com.proxycensus.mysharesUK/files/05bf2f15-5b08-4014-882a-c0157faa79b9-myshares-doc.pdf
我无法访问jar,所以我可以检查哪一行导致了问题。谁能帮我?有没有人面临同样的问题?感谢
答案 0 :(得分:0)
pdf文件的路径错误。只需调试