1

I have a problem beacuse I had an app that it was filling a form with itexg(5.5.0) and now Itdoesn´t work; I have tried update to the last version 5.5.1 with the other two librerys. Well with the old version I had this error:

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

With the lasted version: the pdf was generated but It doesn't fill the form and I have diferenet messages:

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;)

MainActivity

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;
    }
}
Andy G
  • 19,232
  • 5
  • 47
  • 69
  • 1
    iTextG has a dependency on SpongyCastle. Did you include the correct version of SpongyCastle in your APK? – Bruno Lowagie May 30 '14 at 14:24
  • I have included the two diferents librarys that it told on web page. Will Ihave to included a spongycastle to?where can I donwload a spongecastle for android? Thanks – user3690964 May 31 '14 at 11:31
  • http://stackoverflow.com/questions/6898801/how-to-include-the-spongy-castle-jar-in-android – Bruno Lowagie May 31 '14 at 11:36
  • By the way: which web page are you referring to? I just checked and I see that SpongyCastle is listed as required: http://itextpdf.com/product/itextg – Bruno Lowagie May 31 '14 at 11:37
  • I have included this two diferents librarys : scprov-jdk15on and scpkix-jdk15o with the lasted version I think and I haven't the warnings now but I can't fill the form because it doesn't know the fields. In may case when made the inicializate of acrofields it doesn't find any field – user3690964 May 31 '14 at 11:51
  • Those are completely different questions: (1) does your PDF have fields? (2) Are those fields AcroFields or XFA fields? (3) If AcroFields: how come you don't know the names of the fields? **Also important:** please use proper language. *May* is a month, which is not the same as *my*, but more importantly *when made the inicializate of acrofields* doesn't make any sense. Can you explain in code what you mean by that? – Bruno Lowagie May 31 '14 at 11:54
  • Yes the pdf has fields. It's the same document that i filled with the previous version. In my case is a easy doccument becasue it's a prototipe of function for oteher app. the pdf has 3 diferents fields Name, Surname and Date(all fields are in spanish); the pdf was made with acrobat pro and it has a form fields. – user3690964 May 31 '14 at 12:10
  • The question remains: AcroForm technology or XFA technology? Also: your comments are no longer related to your original question which was about `Could not find class 'org.spongycastle.cert.X509CertificateHolder'`. Create a new question and avoid using the words "doesn't work". Tell people what the desired output is and what you got instead: http://lowagie.com/doesntwork – Bruno Lowagie May 31 '14 at 12:12
  • It's an AcroFrom technology. Thanks for your help and I will open other question about it. – user3690964 May 31 '14 at 12:25

1 Answers1

2

I fixed this issue. By importing all 4 jar.

  1. core (jar) - Core lightweight API
  2. prov (jar) - JCE provider (requires core)
  3. pkix (jar) - PKIX, CMS, EAC, TSP, PKCS, OCSP, CMP, and CRMF APIs (requires prov)
  4. pg (jar) - OpenPGP API (requires prov)

For details please find http://rtyley.github.io/spongycastle/#downloads

Damon Song
  • 374
  • 2
  • 4