I have been using the PDFNet trial version on Android for developing a cloud based pdf sharing solution at work. I have been following this guide in order to get started: http://blog.pdftron.com/2013/08/09/getting-started-with-android/
I was able to get the PDF library working on my device just fine. The problem seems to be with the Tools library. I followed the instructions in the section "Adding support for Annotations, Text Selection and Form Filling" in the above guide. All projects build fine, but when I load the project onto a device the app tries to load but then says "Unfortunately, Rollout PDFEditor has stopped" and then exits.
Here is my code:
package com.pdftron.android.tutorial.pttest;
import java.io.IOException;
import java.io.InputStream;
import pdftron.Common.PDFNetException;
import pdftron.PDF.PDFDoc;
import pdftron.PDF.PDFNet;
import pdftron.PDF.PDFViewCtrl;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
public class PTTestActivity extends Activity
{
private PDFViewCtrl mPDFViewCtrl;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Initialize the library
try
{
PDFNet.initialize(this, R.raw.pdfnet);
}
catch (PDFNetException e)
{
Log.e("test", "PDFNetException: Line 28");
}
// Inflate the view and get a reference to PDFViewCtrl
setContentView(R.layout.main);
mPDFViewCtrl = (PDFViewCtrl) findViewById(R.id.pdfviewctrl);
mPDFViewCtrl.setToolManager(new pdftron.PDF.Tools.ToolManager(mPDFViewCtrl));
// Load a document
PDFDoc doc = null;
Resources res = getResources();
InputStream is = res.openRawResource(R.raw.sample);
try
{
doc = new PDFDoc(is);
// Or you can use the full path instead
//doc = new PDFDoc("/mnt/sdcard/sample_doc.pdf");
}
catch (PDFNetException e)
{
doc = null;
Log.e("test", "PDFNetException: Line 50", e);
}
catch (IOException e)
{
doc = null;
Log.e("test", "IOException: Line 55", e);
}
try
{
mPDFViewCtrl.setDoc(doc);
}
catch (PDFNetException e)
{
Log.e("test", "PDFNetException: Line 65", e);
}
}
@Override
protected void onPause()
{
// This method simply stops the current ongoing rendering thread, text
// search thread, and tool
super.onPause();
if (mPDFViewCtrl != null)
{
mPDFViewCtrl.pause();
}
}
@Override
protected void onResume()
{
// This method simply starts the rendering thread to ensure the PDF
// content is available for viewing.
super.onResume();
if (mPDFViewCtrl != null)
{
mPDFViewCtrl.resume();
}
}
@Override
protected void onDestroy()
{
// Destroy PDFViewCtrl and clean up memory and used resources.
super.onDestroy();
if (mPDFViewCtrl != null)
{
mPDFViewCtrl.destroy();
}
}
@Override
public void onLowMemory()
{
// Call this method to lower PDFViewCtrl's memory consumption.
super.onLowMemory();
if (mPDFViewCtrl != null)
{
mPDFViewCtrl.purgeMemory();
}
}
}
Here is the log output:
08-05 11:54:08.555: D/ActivityThread(11108): setTargetHeapUtilization:0.25
08-05 11:54:08.555: D/ActivityThread(11108): setTargetHeapIdealFree:8388608
08-05 11:54:08.565: D/ActivityThread(11108): setTargetHeapConcurrentStart:2097152
08-05 11:54:10.157: W/dalvikvm(11108): VFY: unable to resolve static method 963: Lpdftron/PDF/PDFNet;.initialize (Landroid/content/Context;I)V
08-05 11:54:10.157: W/dalvikvm(11108): VFY: unable to resolve exception class 251 (Lpdftron/Common/PDFNetException;)
08-05 11:54:10.157: W/dalvikvm(11108): VFY: unable to find exception handler at addr 0x3c
08-05 11:54:10.157: W/dalvikvm(11108): VFY: rejected Lcom/pdftron/android/tutorial/pttest/PTTestActivity;.onCreate (Landroid/os/Bundle;)V
08-05 11:54:10.157: W/dalvikvm(11108): VFY: rejecting opcode 0x0d at 0x003c
08-05 11:54:10.157: W/dalvikvm(11108): VFY: rejected Lcom/pdftron/android/tutorial/pttest/PTTestActivity;.onCreate (Landroid/os/Bundle;)V
08-05 11:54:10.157: W/dalvikvm(11108): Verifier rejected class Lcom/pdftron/android/tutorial/pttest/PTTestActivity;
08-05 11:54:10.157: W/dalvikvm(11108): Class init failed in newInstance call (Lcom/pdftron/android/tutorial/pttest/PTTestActivity;)
08-05 11:54:10.157: W/dalvikvm(11108): threadid=1: thread exiting with uncaught exception (group=0x41696438)
08-05 11:54:10.177: E/AndroidRuntime(11108): FATAL EXCEPTION: main
08-05 11:54:10.177: E/AndroidRuntime(11108): java.lang.VerifyError: com/pdftron/android/tutorial/pttest/PTTestActivity
08-05 11:54:10.177: E/AndroidRuntime(11108): at java.lang.Class.newInstanceImpl(Native Method)
08-05 11:54:10.177: E/AndroidRuntime(11108): at java.lang.Class.newInstance(Class.java:1319)
08-05 11:54:10.177: E/AndroidRuntime(11108): at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
08-05 11:54:10.177: E/AndroidRuntime(11108): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2025)
08-05 11:54:10.177: E/AndroidRuntime(11108): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
08-05 11:54:10.177: E/AndroidRuntime(11108): at android.app.ActivityThread.access$700(ActivityThread.java:143)
08-05 11:54:10.177: E/AndroidRuntime(11108): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
08-05 11:54:10.177: E/AndroidRuntime(11108): at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 11:54:10.177: E/AndroidRuntime(11108): at android.os.Looper.loop(Looper.java:137)
08-05 11:54:10.177: E/AndroidRuntime(11108): at android.app.ActivityThread.main(ActivityThread.java:4967)
08-05 11:54:10.177: E/AndroidRuntime(11108): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 11:54:10.177: E/AndroidRuntime(11108): at java.lang.reflect.Method.invoke(Method.java:511)
08-05 11:54:10.177: E/AndroidRuntime(11108): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1011)
08-05 11:54:10.177: E/AndroidRuntime(11108): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
08-05 11:54:10.177: E/AndroidRuntime(11108): at dalvik.system.NativeStart.main(Native Method)
And for good measure here is the Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pdftron.android.tutorial.pttest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" />
<application android:icon="@drawable/rollout" android:label="@string/app_name" android:theme="@style/AppTheme" android:hardwareAccelerated="true" >
<activity android:name="PTTestActivity" android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>