Example usage for com.itextpdf.text.pdf PdfFormField FF_READ_ONLY

List of usage examples for com.itextpdf.text.pdf PdfFormField FF_READ_ONLY

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfFormField FF_READ_ONLY.

Prototype

int FF_READ_ONLY

To view the source code for com.itextpdf.text.pdf PdfFormField FF_READ_ONLY.

Click Source Link

Usage

From source file:Logica.LogicaReserva.java

private void GenerarDocumento(Reserva nuevaReserva) throws IOException, DocumentException {
    //String dirPath = "C:\\";
    String fileName = "Base reserva.pdf";
    HashMap fieldsWithValues = new HashMap();
    ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
    PdfReader reader = new PdfReader(fileName);
    PdfStamper stamper = new PdfStamper(reader, baosPDF);
    AcroFields form = stamper.getAcroFields();
    HashMap fields = (HashMap) form.getFields();
    Set keys = fields.keySet();/* w w w.  j ava  2s  .co m*/

    //Metodo que retorna map de datos que queremos obtener de objeto para agregar a PDF    
    fieldsWithValues = crearHashMapReserva(nuevaReserva, keys);

    //Iteracion sobre campos de pdf
    Iterator itr = keys.iterator();
    while (itr.hasNext()) {
        String fieldName = (String) itr.next();
        String fieldValue = fieldsWithValues.get(fieldName) != null ? (String) (fieldsWithValues.get(fieldName))
                : "";
        form.setField(fieldName, fieldValue);
        form.setFieldProperty(fieldName, "setfflags", PdfFormField.FF_READ_ONLY, null);

    }
    stamper.setFormFlattening(true);
    stamper.close();
    reader.close();

    //Guardando cambios
    String nombre;
    DateFormat fecha = new SimpleDateFormat("yyyy_MM_dd HH_mm_ss");
    nombre = fecha.format(nuevaReserva.getFechaHasta());
    String nombreydir = "Documentos\\Documento Reserva -" + nombre + "-.pdf";
    OutputStream pdf = new FileOutputStream(nombreydir);
    baosPDF.writeTo(pdf);
    pdf.close();

    Hilo h1 = new Hilo("email", nombreydir, nuevaReserva.getCliente().getCorreo());
    h1.start();

    try {
        File archivo = new File(nombreydir);
        Desktop.getDesktop().open(archivo);
    } catch (IOException ex) {
    }
    //EnvioEmail(nombreydir, nuevaReserva.getCliente().getCorreo());
}