Ejemplo n.º 1
0
  public void generarPDFComprobante(Comprobante c) throws DocumentException, FileNotFoundException {
    Document documento = new Document();

    FileOutputStream archivoPDF;

    Calendar cal;
    cal = Calendar.getInstance();
    cal.setTime(c.getFecha());
    SimpleDateFormat d = new SimpleDateFormat("dd-MM-yyyy");
    String fecha = d.format(c.getFecha());

    String nombre =
        "./impresiones/comprobantes/comp" + c.getClaseLicencia().getNombre() + "_" + fecha + ".PDF";

    archivoPDF = new FileOutputStream(nombre);

    PdfWriter.getInstance(documento, archivoPDF).setInitialLeading(20);

    documento.open();

    PdfPTable tabla = new PdfPTable(2);

    tabla.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    PdfPCell celda1 =
        new PdfPCell(
            new Phrase(
                "Nombre: "
                    + c.getTitular().getIdUsuario().getNombre()
                    + " "
                    + c.getTitular().getIdUsuario().getApellido()));
    celda1.setBorder(Rectangle.LEFT | Rectangle.TOP);

    PdfPCell celda2 = new PdfPCell(new Phrase("Clase: " + c.getClaseLicencia().getNombre()));
    celda2.setBorder(Rectangle.RIGHT | Rectangle.TOP);

    PdfPCell celda3 = new PdfPCell(new Phrase("Monto: $" + c.getMontoAbonado()));
    celda3.setBorder(Rectangle.LEFT | Rectangle.BOTTOM);

    PdfPCell celda4 = new PdfPCell(new Phrase("Fecha: " + fecha));
    celda4.setBorder(Rectangle.RIGHT | Rectangle.BOTTOM);

    tabla.addCell(celda1);
    tabla.addCell(celda2);
    tabla.addCell(celda3);
    tabla.addCell(celda4);

    documento.add(tabla);

    documento.close();
  }