1

我有一个问题,因为我有一个应用程序正在用 itexg(5.5.0) 填写表格,现在它不起作用;我已经尝试使用其他两个库更新到最新版本 5.5.1。旧版本我有这个错误:

05-30 12:57:56.554: E/dalvikvm(8633): Could not find class 'org.spongycastle.cert.X509CertificateHolder', referenced from method com.itextpdf.text.pdf.PdfReader.readDecryptedDocObj

使用最新版本:生成了 pdf,但它没有填写表格,我有不同的消息:

enter code here

05-30 13:11:10.765: I/dalvikvm(9599): Failed resolving Lorg/spongycastle/cms/RecipientId; interface 4453 'Lorg/spongycastle/util/Selector;'
05-30 13:11:10.765: W/dalvikvm(9599): Link of class 'Lorg/spongycastle/cms/RecipientId;' failed
05-30 13:11:10.765: W/dalvikvm(9599): VFY: unable to find class referenced in signature (Lorg/spongycastle/cms/RecipientId;)
05-30 13:11:10.765: I/dalvikvm(9599): Failed resolving Lorg/spongycastle/cms/RecipientId; interface 4453 'Lorg/spongycastle/util/Selector;'
05-30 13:11:10.765: W/dalvikvm(9599): Link of class 'Lorg/spongycastle/cms/RecipientId;' failed
05-30 13:11:10.765: I/dalvikvm(9599): Could not find method org.spongycastle.cms.RecipientId.match, referenced from method com.itextpdf.text.pdf.PdfReader.readDecryptedDocObj
05-30 13:11:10.765: W/dalvikvm(9599): VFY: unable to resolve virtual method 29020: Lorg/spongycastle/cms/RecipientId;.match (Ljava/lang/Object;)Z
05-30 13:11:10.765: I/dalvikvm(9599): Failed resolving Lorg/spongycastle/cms/RecipientId; interface 4453 'Lorg/spongycastle/util/Selector;'
05-30 13:11:10.765: W/dalvikvm(9599): Link of class 'Lorg/spongycastle/cms/RecipientId;' failed
05-30 13:11:10.765: W/dalvikvm(9599): VFY: unable to find class referenced in signature (Lorg/spongycastle/cms/RecipientId;)
05-30 13:11:10.765: I/dalvikvm(9599): Failed resolving Lorg/spongycastle/cms/RecipientId; interface 4453 'Lorg/spongycastle/util/Selector;'
05-30 13:11:10.765: W/dalvikvm(9599): Link of class 'Lorg/spongycastle/cms/RecipientId;' failed
05-30 13:11:10.765: W/dalvikvm(9599): VFY: unable to find class referenced in signature (Lorg/spongycastle/cms/RecipientId;)
05-30 13:11:10.765: I/dalvikvm(9599): Failed resolving Lorg/spongycastle/cms/RecipientId; interface 4453 'Lorg/spongycastle/util/Selector;'
05-30 13:11:10.765: W/dalvikvm(9599): Link of class 'Lorg/spongycastle/cms/RecipientId;' failed
05-30 13:11:10.765: W/dalvikvm(9599): VFY: unable to find class referenced in signature (Lorg/spongycastle/cms/RecipientId;)
05-30 13:11:10.773: I/dalvikvm(9599): Failed resolving Lorg/spongycastle/cms/RecipientId; interface 4453 'Lorg/spongycastle/util/Selector;'
05-30 13:11:10.773: W/dalvikvm(9599): Link of class 'Lorg/spongycastle/cms/RecipientId;' failed
05-30 13:11:10.773: W/dalvikvm(9599): VFY: unable to find class referenced in signature (Lorg/spongycastle/cms/RecipientId;)
05-30 13:11:10.773: I/dalvikvm(9599): Failed resolving Lorg/spongycastle/cms/RecipientId; interface 4453 'Lorg/spongycastle/util/Selector;'
05-30 13:11:10.773: W/dalvikvm(9599): Link of class 'Lorg/spongycastle/cms/RecipientId;' failed
05-30 13:11:10.773: W/dalvikvm(9599): VFY: unable to find class referenced in signature (Lorg/spongycastle/cms/RecipientId;)
05-30 13:11:10.773: I/dalvikvm(9599): Failed resolving Lorg/spongycastle/cms/RecipientId; interface 4453 'Lorg/spongycastle/util/Selector;'
05-30 13:11:10.773: W/dalvikvm(9599): Link of class 'Lorg/spongycastle/cms/RecipientId;' failed
05-30 13:11:10.773: W/dalvikvm(9599): VFY: unable to find class referenced in signature (Lorg/spongycastle/cms/RecipientId;)
05-30 13:11:10.773: I/dalvikvm(9599): Failed resolving Lorg/spongycastle/cms/RecipientId; interface 4453 'Lorg/spongycastle/util/Selector;'
05-30 13:11:10.773: W/dalvikvm(9599): Link of class 'Lorg/spongycastle/cms/RecipientId;' failed
05-30 13:11:10.781: W/dalvikvm(9599): VFY: unable to find class referenced in signature (Lorg/spongycastle/cms/RecipientId;)

主要活动

package com.example.gnenerarpdf;



import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener{

    private final static String NOMBRE_DIRECTORIO = "MiPdf";
    private final static String NOMBRE_DOCUMENTO = "prueba3.pdf";
    private final static String ETIQUETA_ERROR = "ERROR";
    private final static String INPUTFILE="prototipo.pdf";
    private static String OUTPUTNAME="prototiporelleno.pdf";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Generaremos el documento al hacer click sobre el botón.
        findViewById(R.id.btnGenerar).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        // Creamos el documento.
        //Document documento = new Document();



        try {

            // Creamos el fichero con el nombre que deseemos.
            //File f = crearFichero(NOMBRE_DOCUMENTO);
             PdfReader reader;
             PdfStamper stamper;
            File file=crearFichero(INPUTFILE);

            String ruta=file.getAbsolutePath();         
              reader = new PdfReader(ruta);
              OUTPUTNAME=file.getParentFile()+"/"+"prototiporelleno1.pdf";


              stamper = new PdfStamper(reader, new FileOutputStream (OUTPUTNAME));

              AcroFields form = stamper.getAcroFields();
              form.setField("Nombre", "pepe");
              form.setField("Apellidos", "rodriguez hernandez");
              form.setField("Fecha", "15/05/14");

             stamper.close(); 

             reader.close();

              Toast.makeText(this, "Pdf generated", Toast.LENGTH_LONG).show();


        } catch (IOException e) {

            Log.e(ETIQUETA_ERROR, e.getMessage());

        } catch (com.itextpdf.text.DocumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {

            // Cerramos el documento.

        }

    }

    /**
     * Crea un fichero con el nombre que se le pasa a la función y en la ruta
     * especificada.
     * 
     * @param nombreFichero
     * @return
     * @throws IOException
     */
    public static File crearFichero(String nombreFichero) throws IOException {
        File ruta = getRuta();
        File fichero = null;
        if (ruta != null)
            fichero = new File(ruta, nombreFichero);
        return fichero;
    }

    /**
     * Obtenemos la ruta donde vamos a almacenar el fichero.
     * 
     * @return
     */
    public static File getRuta() {

        // El fichero será almacenado en un directorio dentro del directorio
        // Descargas
        File ruta = null;
        if (Environment.MEDIA_MOUNTED.equals(Environment
                .getExternalStorageState())) {
            ruta = new File(
                    Environment
                            .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
                    NOMBRE_DIRECTORIO);

            if (ruta != null) {
                if (!ruta.mkdirs()) {
                    if (!ruta.exists()) {
                        return null;
                    }
                }
            }
        } else {
        }

        return ruta;
    }
}
4

1 回答 1

2

我解决了这个问题。通过导入所有 4 个 jar。

  1. core (jar) - 核心轻量级 API
  2. prov (jar) - JCE 提供者(需要核心)
  3. pkix (jar) - PKIX、CMS、EAC、TSP、PKCS、OCSP、CMP 和 CRMF API(需要证明)
  4. pg (jar) - OpenPGP API(需要证明)

详情请见 http://rtyley.github.io/spongycastle/#downloads

于 2015-05-15T04:58:58.590 回答