I am using PDFViewer.jar to read a pdf via my app.
The app doesn't succeed to read the pdf and I am getting this exception:
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)
Code:
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());
}
The path i am getting:
12-10 10:03:27.550: E/ObjActivity(16090): path =/data/data/com.proxycensus.mysharesUK/files/05bf2f15-5b08-4014-882a-c0157faa79b9-myshares-doc.pdf
I can't access the jar so i can check which line is causing the trouble. Can any one help me? Did anyone face the same issue? Thanks
Wrong path for the pdf file. Just debug