0

我搜索将pdf文件转换为android中的图像,尝试使用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 库。

能给个好的链接吗。

4

1 回答 1

2

在大多数情况下,iText 不能直接在 Android 上使用。我们对 Android 和 App Engine 进行了特定更改。其中一项更改是使用 SpongyCastle 代替 BouncyCastle。

您可以在此处下载试用版:http: //demo.itextsupport.com/newslicense/

于 2013-03-15T08:44:12.900 回答