Example usage for com.lowagie.text.pdf PdfName TU

List of usage examples for com.lowagie.text.pdf PdfName TU

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfName TU.

Prototype

PdfName TU

To view the source code for com.lowagie.text.pdf PdfName TU.

Click Source Link

Document

A name

Usage

From source file:es.gob.afirma.signers.pades.ltv.PdfDocumentSecurityStore.java

License:Open Source License

/** Constructor para inicializar la clase con una estructura DSS ya creada.
 * @param dss Diccionario DSS/*from  w  ww . j  a v  a2  s  . co m*/
 * @throws IOException En caso de errores de entrada / salida */
PdfDocumentSecurityStore(final PdfDictionary dss) throws IOException {
    int i = 0;
    PdfArray arrayCerts = dss.getAsArray(new PdfName(PDF_NAME_CERTS));
    if (arrayCerts != null) {
        for (final Iterator<PdfObject> iterator = arrayCerts.listIterator(); iterator.hasNext();) {
            final PdfIndirectReference reference = (PdfIndirectReference) iterator.next();
            this.certificates.put(Integer.valueOf(i),
                    getContentBytesFromContentObject(PdfReader.getPdfObject(reference)));
            i++;
        }

    }
    PdfArray arrayOcsps = dss.getAsArray(new PdfName(PDF_NAME_OCSPS));
    if (arrayOcsps != null) {
        i = 0;
        for (final Iterator<PdfObject> iterator = arrayOcsps.listIterator(); iterator.hasNext();) {
            final PdfIndirectReference reference = (PdfIndirectReference) iterator.next();
            this.ocsps.put(Integer.valueOf(i),
                    getContentBytesFromContentObject(PdfReader.getPdfObject(reference)));
            i++;
        }

    }
    PdfArray arrayCrls = dss.getAsArray(new PdfName(PDF_NAME_CRLS));
    if (arrayCrls != null) {
        i = 0;
        for (final Iterator<PdfObject> iterator = arrayCrls.listIterator(); iterator.hasNext();) {
            final PdfIndirectReference reference = (PdfIndirectReference) iterator.next();
            this.crls.put(Integer.valueOf(i),
                    getContentBytesFromContentObject(PdfReader.getPdfObject(reference)));
            i++;
        }

    }
    final PdfDictionary vri = dss.getAsDict(new PdfName(PDF_NAME_VRI));
    if (vri != null) {
        PdfName key;
        ValidationInformation val;
        for (final Iterator<PdfName> iterator = vri.getKeys().iterator(); iterator.hasNext(); this.signatures
                .put(key.toString().substring(1), val)) {
            key = iterator.next();
            final PdfDictionary vriEntry = vri.getAsDict(key);
            arrayCerts = vriEntry.getAsArray(new PdfName(PDF_NAME_CERT));
            int certId[];
            if (arrayCerts != null) {
                certId = new int[arrayCerts.size()];
                for (i = 0; i < arrayCerts.size(); i++) {
                    final PdfIndirectReference reference = (PdfIndirectReference) arrayCerts.getPdfObject(i);
                    final byte referenceBytes[] = getContentBytesFromContentObject(
                            PdfReader.getPdfObject(reference));
                    final Iterator<Integer> iteratorKeys = this.certificates.keySet().iterator();
                    do {
                        if (!iteratorKeys.hasNext()) {
                            break;
                        }
                        final int index = iteratorKeys.next().intValue();
                        if (Arrays.equals(referenceBytes, this.certificates.get(Integer.valueOf(index)))) {
                            certId[i] = index;
                        }
                    } while (true);
                }

            } else {
                certId = new int[0];
            }
            arrayOcsps = vriEntry.getAsArray(new PdfName(PDF_NAME_OCSP));
            int ocspId[];
            if (arrayOcsps != null) {
                ocspId = new int[arrayOcsps.size()];
                i = 0;
                for (final Iterator<PdfObject> iteratorOcsps = arrayOcsps.listIterator(); iteratorOcsps
                        .hasNext();) {
                    final PdfIndirectReference reference = (PdfIndirectReference) iteratorOcsps.next();
                    final byte referenceBytes[] = getContentBytesFromContentObject(
                            PdfReader.getPdfObject(reference));
                    final Iterator<Integer> iteratorKeys = this.ocsps.keySet().iterator();
                    do {
                        if (!iteratorKeys.hasNext()) {
                            break;
                        }
                        final int index = iteratorKeys.next().intValue();
                        if (Arrays.equals(referenceBytes, this.ocsps.get(Integer.valueOf(index)))) {
                            ocspId[i] = index;
                        }
                    } while (true);
                    i++;
                }

            } else {
                ocspId = new int[0];
            }
            arrayCrls = vriEntry.getAsArray(new PdfName(PDF_NAME_CRL));
            int crlId[];
            if (arrayCrls != null) {
                crlId = new int[arrayCrls.size()];
                i = 0;
                for (final Iterator<PdfObject> iteratorCRLs = arrayCrls.listIterator(); iteratorCRLs
                        .hasNext();) {
                    final PdfIndirectReference reference = (PdfIndirectReference) iteratorCRLs.next();
                    final byte referenceBytes[] = getContentBytesFromContentObject(
                            PdfReader.getPdfObject(reference));
                    final Iterator<Integer> iteratorKeys = this.crls.keySet().iterator();
                    do {
                        if (!iteratorKeys.hasNext()) {
                            break;
                        }
                        final int index = iteratorKeys.next().intValue();
                        if (Arrays.equals(referenceBytes, this.crls.get(Integer.valueOf(index)))) {
                            crlId[i] = index;
                        }
                    } while (true);
                    i++;
                }

            } else {
                crlId = new int[0];
            }
            Calendar date = null;
            if (vriEntry.get(PdfName.TU) != null) {
                if (vriEntry.get(PdfName.TU) instanceof PdfDate) {
                    date = PdfDate.decode(((PdfDate) vriEntry.get(PdfName.TU)).getEncoding());
                }
                if (vriEntry.get(PdfName.TU) instanceof PdfString) {
                    date = PdfDate.decode(vriEntry.getAsString(PdfName.TU).getEncoding());
                }
            }
            val = new ValidationInformation(key, certId, ocspId, crlId, date);
        }
    }
}

From source file:org.opensignature.opensignpdf.PDFSigner.java

License:Open Source License

/**
 * /*w ww .j a  v a  2 s .  co m*/
 * @param pdfFile
 * @return
 * @throws IOException
 * @throws DocumentException
 * @throws FileNotFoundException
 */
private PdfReader createPDFReader(File pdfFile) throws IOException, DocumentException, FileNotFoundException {

    logger.info("[createPDFReader.in]:: " + Arrays.asList(new Object[] { pdfFile }));

    PdfReader reader;

    if ("true".equals(openOfficeSelected)) {
        String fileName = pdfFile.getPath();
        String tempFileName = fileName + ".temp";
        PdfReader documentPDF = new PdfReader(fileName);

        PdfStamperOSP stamperTemp = new PdfStamperOSP(documentPDF, new FileOutputStream(tempFileName));
        AcroFields af = stamperTemp.getAcroFields();
        af.setGenerateAppearances(true);
        PdfDictionary acro = (PdfDictionary) PdfReader
                .getPdfObject(documentPDF.getCatalog().get(PdfName.ACROFORM));
        acro.remove(PdfName.DR);
        HashMap fields = af.getFields();
        String key;
        for (Iterator it = fields.keySet().iterator(); it.hasNext();) {
            key = (String) it.next();
            int a = af.getFieldType(key);
            if (a == 4) {
                ArrayList widgets = af.getFieldItem(key).widgets;
                PdfDictionary widget = (PdfDictionary) widgets.get(0);
                widget.put(PdfName.FT, new PdfName("Sig"));
                widget.remove(PdfName.V);
                widget.remove(PdfName.DV);
                widget.remove(PdfName.TU);
                widget.remove(PdfName.FF);
                widget.remove(PdfName.DA);
                widget.remove(PdfName.DR);
                widget.remove(PdfName.AP);
            }
        }

        stamperTemp.close();
        documentPDF.close();
        reader = new PdfReader(pdfFile.getPath() + ".temp");

    } else {
        reader = new PdfReader(pdfFile.getPath());

    }

    logger.info("[createPDFReader.retorna]:: ");
    return reader;

}