我搜索将pdf文件转换为android中的图像,itry with itextpdf-5.3.1.jar
但我的申请中有例外。我在libs文件夹中找到了库。
是我的代码
package com.example.zakiexemple;
import java.io.File;
import java.io.FileOutputStream;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import com.itextpdf.text.pdf.PRStream;
import com.itextpdf.text.pdf.PdfName;
import com.itextpdf.text.pdf.PdfObject;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStream;
public class MainActivity extends Activity {
PdfReader reader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bt = (Button) findViewById(R.id.Button);
//final WebView wb = (WebView) findViewById(R.id.webView1);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
File file = new File("/sdcard/003_overview.pdf");
try{
reader = new PdfReader(file.getAbsolutePath());
for (int i = 0; i < reader.getXrefSize(); i++) {
PdfObject pdfobj= reader.getPdfObject(i);
if (pdfobj == null || !pdfobj.isStream()) {
continue;
}
PdfStream stream = (PdfStream) pdfobj;
PdfObject pdfsubtype = stream.get(PdfName.SUBTYPE);
if (pdfsubtype != null && pdfsubtype.toString().equals(PdfName.IMAGE.toString())) {
byte[] img = PdfReader.getStreamBytesRaw((PRStream) stream);
FileOutputStream out = new FileOutputStream(new
File(file.getParentFile(),String.format("%1$05d", i) + ".jpg"));
out.write(img); out.flush(); out.close();
Toast.makeText(getBaseContext(), "howa hadak", Toast.LENGTH_SHORT).show();
}
}
}
catch (Exception e) { }
}
}) ;
}
}
并记录日志错误
03-15 08:12:35.835: E/dalvikvm(937): Could not find class 'org.bouncycastle.cert.X509CertificateHolder', referenced from method com.itextpdf.text.pdf.PdfReader.readDecryptedDocObj
03-15 08:12:35.835: W/dalvikvm(937): VFY: unable to resolve new-instance 1533 (Lorg/bouncycastle/cert/X509CertificateHolder;) in Lcom/itextpdf/text/pdf/PdfReader;
03-15 08:12:35.835: D/dalvikvm(937): VFY: replacing opcode 0x22 at 0x030e
03-15 08:12:35.946: D/dalvikvm(937): DexOpt: unable to opt direct call 0x318a at 0x318 in Lcom/itextpdf/text/pdf/PdfReader;.readDecryptedDocObj
03-15 08:12:35.946: D/dalvikvm(937): DexOpt: unable to opt direct call 0x31a5 at 0x33d in Lcom/itextpdf/text/pdf/PdfReader;.readDecryptedDocObj
03-15 08:12:36.505: D/dalvikvm(937): GC_CONCURRENT freed 743K, 14% free 5345K/6212K, paused 71ms+85ms, total 216ms
我认为我没有适合Android的好的itext库。
你能给出好的联系。
答案 0 :(得分:2)
在大多数情况下,iText无法在Android上直接使用。我们已经制作了一个具有Android和App Engine特定更改的端口。其中一个变化是使用SpongyCastle而不是BouncyCastle。
您可以在此处下载试用版:http://demo.itextsupport.com/newslicense/