10-02 05:36:39.589: E/dalvikvm(2570): Could not find class 'org.bouncycastle.cms.CMSEnvelopedData',
referenced from method com.itextpdf.text.pdf.PdfReader.readDecryptedDocObj
The logcat shows this kind of error, I’ve been googling around and still can’t find the solution.
here is the source code:
MainActivity.java
import java.io.FileOutputStream;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
GenerarPDF();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void GenerarPDF()throws Exception{
Document document = new Document();
String file = Environment.getExternalStorageDirectory().getPath() + "/Hello.pdf";
PdfWriter.getInstance(document,new FileOutputStream(file));
document.open();
Paragraph p = new Paragraph("Hello PDF");
document.add(p);
document.close();
}
}
here is my manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.samplepdf"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
can anyone point out a solution to this problem?
Seems like you’re not using the offical Android port of iText. The official port doesn’t use BouncyCastle. It uses SpongyCastle to avoid clashes with the old BouncyCastle version that is shipped with Android. Use the official port and the problem will disappear.