Example usage for com.lowagie.text.pdf AcroFields setGenerateAppearances

List of usage examples for com.lowagie.text.pdf AcroFields setGenerateAppearances

Introduction

In this page you can find the example usage for com.lowagie.text.pdf AcroFields setGenerateAppearances.

Prototype

public void setGenerateAppearances(boolean generateAppearances) 

Source Link

Document

Sets the option to generate appearances.

Usage

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

License:Open Source License

/**
 * /*from  w  w  w .  j av  a  2 s . c o 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;

}