Example usage for com.itextpdf.text PageSize LETTER

List of usage examples for com.itextpdf.text PageSize LETTER

Introduction

In this page you can find the example usage for com.itextpdf.text PageSize LETTER.

Prototype

Rectangle LETTER

To view the source code for com.itextpdf.text PageSize LETTER.

Click Source Link

Document

This is the letter format

Usage

From source file:gov.utah.dts.det.ccl.actions.trackingrecordscreening.letters.reports.MultiStateOffenderLetterFC.java

private static void writePdf(TrackingRecordScreeningLetter screeningLetter, OutputStream ba,
        HttpServletRequest request) throws DocumentException, BadElementException, IOException {
    Document document = null;//from   w w  w  . j  a v  a2  s .  c o  m
    Paragraph paragraph = null;
    ListItem item = null;
    document = new Document(PageSize.LETTER, 50, 50, 125, 0);
    PdfWriter writer = PdfWriter.getInstance(document, ba);
    StringBuilder sb = null;
    SimpleDateFormat df = new SimpleDateFormat("MMMM d, yyyy");

    document.open();

    LetterheadStamper.stampLetter(writer, request);

    paragraph = getParagraph(10.0f);
    paragraph.add(new Phrase("MSO FC", smallfont));
    paragraph.setIndentationLeft(415);
    document.add(paragraph);
    paragraph.clear();
    paragraph.add(new Phrase("Rev 3/12", smallfont));
    paragraph.setSpacingAfter(50);
    document.add(paragraph);

    // Add report date
    paragraph = getParagraph();
    paragraph.add(new Phrase(df.format(screeningLetter.getLetterDate()), mediumfont));
    paragraph.setIndentationLeft(350);
    document.add(paragraph);

    // Add applicant name and address information
    paragraph = getParagraph();
    paragraph.add(new Phrase(screeningLetter.getTrackingRecordScreening().getFirstAndLastName().toUpperCase(),
            mediumfont));
    paragraph.setSpacingBefore(5);
    document.add(paragraph);
    if (StringUtils.isNotBlank(screeningLetter.getAddress().getAddressOne())) {
        paragraph = getParagraph();
        paragraph.add(new Phrase(screeningLetter.getAddress().getAddressOne().toUpperCase(), mediumfont));
        document.add(paragraph);
    }
    if (StringUtils.isNotBlank(screeningLetter.getAddress().getAddressTwo())) {
        // Add facility location address two
        paragraph = getParagraph();
        paragraph.add(new Phrase(screeningLetter.getAddress().getAddressTwo().toUpperCase(), mediumfont));
        document.add(paragraph);
    }
    if (StringUtils.isNotBlank(screeningLetter.getAddress().getCityStateZip())) {
        paragraph = getParagraph();
        paragraph.add(new Phrase(screeningLetter.getAddress().getCityStateZip().toUpperCase(), mediumfont));
        document.add(paragraph);
    }

    // Add subject information
    paragraph = getParagraph();
    paragraph.add(new Phrase("RE: Notice of additional Criminal Background Screening information needed:",
            mediumfont));
    paragraph.setSpacingBefore(10);
    document.add(paragraph);

    // Add Screening Person's Name/ID
    paragraph = getParagraph(16.0f);
    paragraph.add(new Phrase(screeningLetter.getTrackingRecordScreening().getFirstAndLastName() + " ("
            + screeningLetter.getTrackingRecordScreening().getPersonIdentifier() + ")", mediumfont));
    // Indent this line to line up with 'Notice' in subject line
    paragraph.setIndentationLeft(22);
    document.add(paragraph);

    // Add salutation
    paragraph = getParagraph();
    paragraph.add(new Phrase("Dear " + screeningLetter.getTrackingRecordScreening().getFirstAndLastName() + ":",
            mediumfont));
    paragraph.setSpacingBefore(18);
    document.add(paragraph);

    // Start letter detail
    sb = new StringBuilder();
    sb.append(
            "As a follow-up to the request for background screening by the Department of Human Services, Office of Licensing, ");
    sb.append("this is to notify you that additional criminal background screening information is needed.");
    paragraph = getParagraph();
    paragraph.add(new Phrase(sb.toString(), mediumfont));
    paragraph.setSpacingBefore(10);
    document.add(paragraph);

    paragraph = getParagraph();
    paragraph.add(new Phrase(
            "Enclosed are two fingerprint cards for you to provide complete, accurate and legible identifying information. ",
            mediumfont));
    paragraph.add(new Phrase("Return the completed fingerprint cards with a $36.50 fee in the form of a ",
            mediumfont));
    paragraph.add(new Phrase("cashier's check or money order ", mediumfontI));
    paragraph.add(new Phrase("(no personal checks) payable to the ", mediumfont));
    paragraph.add(new Phrase("Department of Human Resources, ", mediumfontI));
    paragraph.add(new Phrase(
            "to the Office of Licensing within 15 calendar days of your receipt of this notice.", mediumfont));
    paragraph.setSpacingBefore(10);
    paragraph.setSpacingAfter(10);
    document.add(paragraph);

    // Add the fingerprint card procedures as an indented bullet list
    List procedure = new List(false, 10);
    procedure.setIndentationLeft(10);
    item = getListItem();
    item.add(new Phrase(
            "Prints should be taken by a local law enforcement office, or an agency approved by law enforcement.",
            mediumfont));
    procedure.add(item);
    item = getListItem();
    item.add(new Phrase("The FBI will reject a card with any highlighting.", mediumfont));
    procedure.add(item);
    item = getListItem();
    item.add(new Phrase(
            "Use only these cards showing identification from the Office of Licensing. We will be glad to give you replacement cards if requested.",
            mediumfont));
    procedure.add(item);
    item = getListItem();
    procedure.add(new Phrase(
            "If mailing the cards back to us, return by regular mail (please do not fold the cards).",
            mediumfont));
    procedure.add(item);
    item = getListItem();
    item.add(new Phrase(
            "Fingerprint cards must be completely filled out or they will be returned for completion.",
            mediumfont));
    procedure.add(item);
    document.add(procedure);

    sb = new StringBuilder();
    sb.append(
            "Failure to return the completed fingerprint cards and fee within 15 calendar days will result in your background screening ");
    sb.append(
            "application being denied, and you will not be eligible to be associated with the licensed program in any capacity ");
    sb.append(
            "or will not be eligible to proceed with foster care or adoption until all clearance procedures are completed.");
    paragraph = getParagraph();
    paragraph.add(new Phrase(sb.toString(), mediumfont));
    paragraph.setSpacingBefore(10);
    document.add(paragraph);

    sb = new StringBuilder();
    sb.append(
            "Please allow up to 12 weeks for the completion of the clearance process. For assistance or inquiries, you can contact the Office of Licensing ");
    sb.append("at (801) 538-4242.");
    paragraph = getParagraph();
    paragraph.add(new Phrase(sb.toString(), mediumfont));
    paragraph.setSpacingBefore(10);
    document.add(paragraph);

    paragraph = getParagraph();
    paragraph.add(new Phrase("Sincerely,", mediumfont));
    paragraph.setSpacingBefore(10);
    document.add(paragraph);

    paragraph = getParagraph();
    paragraph.add(new Phrase(screeningLetter.getCreatedBy().getFirstAndLastName(), mediumfont));
    paragraph.setSpacingBefore(25);
    document.add(paragraph);

    paragraph = getParagraph();
    paragraph.add(new Phrase("Background Screening Unit", mediumfont));
    document.add(paragraph);

    if (screeningLetter.getTrackingRecordScreening() != null
            && screeningLetter.getTrackingRecordScreening().getFacility() != null
            && screeningLetter.getTrackingRecordScreening().getFacility().getLicensingSpecialist() != null
            && StringUtils.isNotBlank(screeningLetter.getTrackingRecordScreening().getFacility()
                    .getLicensingSpecialist().getIntials())) {
        paragraph = getParagraph();
        paragraph.add(new Phrase("CC: " + screeningLetter.getTrackingRecordScreening().getFacility()
                .getLicensingSpecialist().getIntials(), mediumfont));
        paragraph.setSpacingBefore(10);
        document.add(paragraph);
    }

    document.close();
}

From source file:gov.utah.dts.det.ccl.actions.trackingrecordscreening.letters.reports.MultiStateOffenderLetterTX.java

private static void writePdf(TrackingRecordScreeningLetter screeningLetter, OutputStream ba,
        HttpServletRequest request) throws DocumentException, BadElementException, IOException {
    Document document = null;//from   www  . jav  a 2  s  .  c  o  m
    Paragraph paragraph = null;
    ListItem item = null;
    document = new Document(PageSize.LETTER, 50, 50, 125, 0);
    PdfWriter writer = PdfWriter.getInstance(document, ba);
    StringBuilder sb = null;
    SimpleDateFormat df = new SimpleDateFormat("MMMM d, yyyy");

    document.open();

    LetterheadStamper.stampLetter(writer, request);

    paragraph = getParagraph(10.0f);
    paragraph.add(new Phrase("MSO TX", smallfont));
    paragraph.setIndentationLeft(415);
    document.add(paragraph);
    paragraph.clear();
    paragraph.add(new Phrase("Rev 3/12", smallfont));
    paragraph.setSpacingAfter(50);
    document.add(paragraph);

    // Add report date
    paragraph = getParagraph();
    paragraph.add(new Phrase(df.format(screeningLetter.getLetterDate()), mediumfont));
    paragraph.setIndentationLeft(350);
    document.add(paragraph);

    // Add facility name and address information
    paragraph = getParagraph();
    paragraph.add(new Phrase(screeningLetter.getTrackingRecordScreening().getFacility().getName().toUpperCase(),
            mediumfont));
    paragraph.setSpacingBefore(5);
    document.add(paragraph);
    if (screeningLetter.getTrackingRecordScreening().getFacility().getCbsAddress() != null) {
        if (StringUtils.isNotBlank(
                screeningLetter.getTrackingRecordScreening().getFacility().getCbsAddress().getAddressOne())) {
            paragraph = getParagraph();
            paragraph.add(new Phrase(screeningLetter.getTrackingRecordScreening().getFacility().getCbsAddress()
                    .getAddressOne().toUpperCase(), mediumfont));
            document.add(paragraph);
        }
        if (StringUtils.isNotBlank(
                screeningLetter.getTrackingRecordScreening().getFacility().getCbsAddress().getAddressTwo())) {
            // Add facility location address two
            paragraph = getParagraph();
            paragraph.add(new Phrase(screeningLetter.getTrackingRecordScreening().getFacility().getCbsAddress()
                    .getAddressTwo().toUpperCase(), mediumfont));
            document.add(paragraph);
        }
        if (StringUtils.isNotBlank(
                screeningLetter.getTrackingRecordScreening().getFacility().getCbsAddress().getCityStateZip())) {
            paragraph = getParagraph();
            paragraph.add(new Phrase(screeningLetter.getTrackingRecordScreening().getFacility().getCbsAddress()
                    .getCityStateZip().toUpperCase(), mediumfont));
            document.add(paragraph);
        }
    }

    // Add subject information
    paragraph = getParagraph();
    paragraph.add(new Phrase("RE: Notice of additional Criminal Background Screening information needed:",
            mediumfont));
    paragraph.setSpacingBefore(10);
    document.add(paragraph);

    // Add Screening Person's Name/ID
    sb = new StringBuilder();
    paragraph = getParagraph(16.0f);
    paragraph.add(new Phrase(screeningLetter.getTrackingRecordScreening().getFirstAndLastName() + " ("
            + screeningLetter.getTrackingRecordScreening().getPersonIdentifier() + ")", mediumfont));
    // Indent this line to line up with 'Notice' in subject line
    paragraph.setIndentationLeft(22);
    document.add(paragraph);

    // Add salutation
    paragraph = getParagraph();
    paragraph.add(new Phrase("Dear Director:", mediumfont));
    paragraph.setSpacingBefore(18);
    document.add(paragraph);

    // Start letter detail
    sb = new StringBuilder();
    sb.append(
            "As a follow-up to the request for background screening by the Department of Human Services, Office of Licensing, ");
    sb.append("this is to notify you that additional criminal background screening information is needed.");
    paragraph = getParagraph();
    paragraph.add(new Phrase(sb.toString(), mediumfont));
    paragraph.setSpacingBefore(10);
    document.add(paragraph);

    paragraph = getParagraph();
    paragraph.add(new Phrase(
            "Enclosed are two fingerprint cards for the applicant to provide complete, accurate and legible identifying information. ",
            mediumfont));
    paragraph.add(new Phrase("Return the completed fingerprint cards with a $36.50 fee in the form of a ",
            mediumfont));
    paragraph.add(new Phrase("cashier's check or money order ", mediumfontI));
    paragraph.add(new Phrase("(no personal checks) payable to the ", mediumfont));
    paragraph.add(new Phrase("Department of Human Resources, ", mediumfontI));
    paragraph.add(new Phrase(
            "to the Office of Licensing within 15 calendar days of your receipt of this notice. Do not put multiple fingerprints ",
            mediumfont));
    paragraph.add(new Phrase("with one payment, unless for a couple with the same last name.", mediumfont));
    paragraph.setSpacingBefore(10);
    paragraph.setSpacingAfter(10);
    document.add(paragraph);

    // Add the fingerprint card procedures as an indented bullet list
    List procedure = new List(false, 10);
    procedure.setIndentationLeft(22);
    item = getListItem();
    item.add(new Phrase(
            "Prints should be taken by a local law enforcement office, or an agency approved by law enforcement.",
            mediumfont));
    procedure.add(item);
    item = getListItem();
    item.add(new Phrase("The FBI will reject a card with any highlighting.", mediumfont));
    procedure.add(item);
    item = getListItem();
    item.add(new Phrase(
            "Use only these cards showing identification from the Office of Licensing. We will be glad to give you replacement cards if requested.",
            mediumfont));
    procedure.add(item);
    item = getListItem();
    item.add(new Phrase(
            "If mailing the cards back to us, return by regular mail (please do not fold the cards).",
            mediumfont));
    procedure.add(item);
    item = getListItem();
    item.add(new Phrase(
            "Fingerprint cards must be completely filled out or they will be returned for completion.",
            mediumfont));
    procedure.add(item);
    document.add(procedure);

    sb = new StringBuilder();
    sb.append(
            "Failure to return the completed fingerprint cards and fee within 15 calendar days will result in the background screening ");
    sb.append(
            "application being denied, and the applicant will not be eligible to be associated with the licensed program in any capacity ");
    sb.append(
            "or will not be eligible to proceed with foster care or adoption until all clearance procedures are completed.");
    paragraph = getParagraph();
    paragraph.add(new Phrase(sb.toString(), mediumfont));
    paragraph.setSpacingBefore(10);
    document.add(paragraph);

    sb = new StringBuilder();
    sb.append(
            "Please allow up to 12 weeks for the completion of the clearance process. For assistance or inquiries, please contact the Office of Licensing ");
    sb.append("at (801) 538-4242.");
    paragraph = getParagraph();
    paragraph.add(new Phrase(sb.toString(), mediumfont));
    paragraph.setSpacingBefore(10);
    document.add(paragraph);

    paragraph = new Paragraph();
    paragraph.add(new Phrase("Sincerely,", mediumfont));
    paragraph.setSpacingBefore(10);
    document.add(paragraph);

    paragraph = new Paragraph();
    paragraph.add(new Phrase(screeningLetter.getCreatedBy().getFirstAndLastName(), mediumfont));
    paragraph.setSpacingBefore(25);
    document.add(paragraph);

    paragraph = new Paragraph();
    paragraph.add(new Phrase("Background Screening Unit", mediumfont));
    document.add(paragraph);

    document.close();
}

From source file:GUI.FacturasUsuariosGUI.java

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    try {//from  w w  w .  j a va  2  s .c om
        int fila = listarFacturas.getSelectedRow();
        if (fila != -1) {
            String cedula = (String) modeloFacturas.getValueAt(fila, 1);
            String numeroFactura = (String) modeloFacturas.getValueAt(fila, 0);

            SimpleDateFormat fecha = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            Usuario u = us.recuperarUsuario(cedula);
            LinkedList<Factura> f = fs.recuperarFacturas(cedula);

            com.itextpdf.text.Document document = new com.itextpdf.text.Document(PageSize.LETTER, 50, 50, 50,
                    50);
            Image imagen, publicidad;
            imagen = Image.getInstance("src//IMG//logohd.png");
            imagen.setAlignment(Element.ALIGN_CENTER);
            imagen.scalePercent(60f);

            //publicidad
            //            publicidad = Image.getInstance("LOGO.png");
            //            publicidad.setAlignment(Element.ALIGN_CENTER);
            //            publicidad.scalePercent(40f);
            //            Document doc = new Document();
            //            PdfWriter
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("factura.pdf"));
            document.open();
            document.add(imagen);
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.add(new Paragraph(
                    "|                                                   FACTURAS PARQUEADERO                                                   |"));
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.add(new Paragraph("RUC: 0102030405067 "));
            document.add(new Paragraph("Numero Fact: 00000" + numeroFactura));
            document.add(new Paragraph("Cliente : " + u.getNombre() + " " + u.getApellido()));
            document.add(new Paragraph("N de cdula : " + u.getCedula()));
            document.add(
                    new Paragraph("Fecha : " + new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date())));
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.add(new Paragraph("Placas : " + u.getVehiculo().getPlaca()));
            document.add(new Paragraph("Marca : " + u.getVehiculo().getMarca()));
            document.add(new Paragraph("Modelo : " + u.getVehiculo().getModelo()));
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.add(new Paragraph(
                    "| N |    FECHA Y HORA DE ENTRADA    |    FECHA Y HORA DE SALIDA    |      TIEMPO       |"));
            for (int i = 0; i < f.get(fila).getListaDetalleFacturas().size(); i++) {
                document.add(new Paragraph("|  " + (i + 1) + "  |             "
                        + fecha.format(f.get(fila).getListaDetalleFacturas().get(i).getFechaHoraEntrada())
                        + "             |            "
                        + fecha.format(f.get(fila).getListaDetalleFacturas().get(i).getFechaHoraSalida())
                        + "          |      " + f.get(fila).getListaDetalleFacturas().get(i).getTiempo()
                        + "      |"));
            }
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.add(new Paragraph("              Subtotal : " + f.get(fila).getSubtotal()));
            document.add(new Paragraph("              Iva : " + f.get(fila).getIva()));
            document.add(new Paragraph("              Total : " + f.get(fila).getTotal()));
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.close();
            File path = new File("factura.pdf");
            Desktop.getDesktop().open(path);
            this.setVisible(false);
            new ParqueaderoMAINGUI().setVisible(true);
        } else {
            JOptionPane.showMessageDialog(this, "Para generar un pdf debe seleccionar alguna factura");
        }
    } catch (Exception e) {
    }
}

From source file:GUI.Framenewventa.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

    if (jLabel17.getText().toString().equals("-")) {
        JOptionPane.showMessageDialog(rootPane, "DEBE SELECCIONAR UN CLIENTE");
    } else {//from ww  w  .  j a v  a  2  s  .  c  o  m

        try {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            funciones f = new funciones();
            String dia = (Calendar.getInstance().getTime().getDate() < 10)
                    ? "0" + Calendar.getInstance().getTime().getDate()
                    : Calendar.getInstance().getTime().getDate() + "";
            String mes = f.get_mesMay((Calendar.getInstance().getTime().getMonth() + 1));
            String anio = (Calendar.getInstance().getTime().getYear() + 1900) + "";

            String nombre = "COTIZACION TIENDA ULTIMO ROUND";
            String rut_socio = "";
            int mon = 0;
            String arch = Calendar.getInstance().getTimeInMillis() + "_" + nombre + ".pdf";
            DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
            Date date = new Date();
            String stringToEncrypt = nombre.trim() + dateFormat.format(date);

            int encryptedString = stringToEncrypt.trim().hashCode();
            String aRemplazar = Integer.toString(encryptedString);
            String remplazado = aRemplazar.replace("-", "");

            String url = f.getRutaCotizacion() + arch;
            FileOutputStream archivo = new FileOutputStream(url);

            int deuda = Integer.parseInt("1");

            String palabra = f.Convertir(deuda + "", false);

            palabra = palabra.substring(0, palabra.length() - 2);
            if (palabra.split(" ")[palabra.split(" ").length - 1].equals("millones")
                    | palabra.split(" ")[palabra.split(" ").length - 1].equals("milln")) {
                palabra = palabra + "de pesos";
            } else {
                palabra = palabra + "pesos";
            }

            Document documento = new Document(PageSize.LETTER);
            PdfWriter.getInstance(documento, archivo);
            documento.open();
            try {
                Image im = Image.getInstance(f.getRutaCotizacion() + "headerword.png");
                im.setAlignment(Image.ALIGN_CENTER);
                im.scaleToFit(600, 400);
                documento.add(im);
            } catch (Exception e) {
                setCursor(Cursor.getDefaultCursor());

                JOptionPane.showConfirmDialog(null, "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL ENCABEZADO.",
                        "ERROR", JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);

            }

            int linea = 0;
            Font fuente = new Font();
            fuente.setStyle(Font.UNDERLINE | Font.BOLD);
            fuente.setSize(11);
            fuente.setColor(BaseColor.BLACK);
            documento.add(new Paragraph(" "));
            Paragraph fecha = new Paragraph(dia + " de " + mes.toLowerCase() + " de " + anio + "\n",
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            fecha.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(fecha);
            Paragraph obp = new Paragraph("ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            obp.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(obp);
            Paragraph codigo = new Paragraph("COD." + remplazado,
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            codigo.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(codigo);
            Paragraph space = new Paragraph("\n",
                    FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK));
            space.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(space);
            Paragraph origen = new Paragraph("ESTIMADO CLIENTE: " + jLabel13.getText() + "\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            origen.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(origen);
            Paragraph origen2 = new Paragraph("EMAIL: " + jLabel15.getText() + "\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            origen2.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(origen2);
            Paragraph a = new Paragraph(nombre,
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            a.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(a);
            Paragraph rut = new Paragraph(rut_socio,
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            rut.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(rut);
            Paragraph ref = new Paragraph("REF:COTIZACION POR PRODUCTOS TIENDA ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK));
            ref.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(ref);

            documento.add(space);
            int numerocheque = 0;
            int montofinal = 0;
            String montostring = "";
            String detalle = "";
            String monto = jLabel22.getText();

            String montoaux = monto.replace(".", "");

            deuda = Integer.parseInt(montoaux);

            palabra = f.Convertir(deuda + "", false);
            System.out.println(palabra);
            palabra = palabra.replaceAll("0", "");
            System.out.println(palabra);
            Paragraph e = new Paragraph(
                    "Junto con saludarlo, adjunto la cotizacin detallada de los siguientes productos"
                            + " por el monto de $" + monto + ".- ( " + palabra
                            + "pesos IVA INCLUIDO) ,segn detalle:\n\n",
                    FontFactory.getFont("times new roman", 11, Font.NORMAL, BaseColor.BLACK));
            e.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(e);
            documento.add(new Paragraph(" "));
            // ACA DEBE IR LA TABLA
            //special font sizes
            Font bfBold10 = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD, new BaseColor(0, 0, 0));
            Font bf10 = new Font(Font.FontFamily.TIMES_ROMAN, 10);
            //specify column widths

            //create PDF table with the given widths

            documento.add(new Paragraph(" "));
            float[] colsWidth = { 1.5f, 1.5f, 1.5f, 1.5f, 1.5f };
            PdfPTable tabla = new PdfPTable(5);
            tabla.setWidths(colsWidth);
            String[] titulos = { "PRODUCTO", "VALOR PRODUCTO", "TIPO", "MARCA", "TALLA" };

            tabla.setWidthPercentage(100);
            PdfPCell celda;
            for (int k = 0; k < titulos.length; k++) {
                celda = new PdfPCell(new Paragraph(titulos[k],
                        FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
            }
            int var = 0;
            int w = 0;
            for (w = 0; w < jTable1.getRowCount(); w++) {
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 1).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 7).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 4).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 3).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 2).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);

            }
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("MONTO NETO",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph(monto,
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("IVA TOTAL",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            double iva2 = Float.parseFloat(monto) * (0.19);
            iva2 = Math.round(iva2);

            celda = new PdfPCell(new Paragraph(Double.toString(iva2),
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("VALOR TOTAL",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            int valortotal = Integer.parseInt(monto);
            ;
            celda = new PdfPCell(new Paragraph(Integer.toString(valortotal),
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            documento.add(tabla);
            //FOOOTER
            documento.add(space);
            Paragraph despido = new Paragraph("Quedando a vuestra disposicin, saluda atentamente a Ud.,\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            despido.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(despido);
            documento.add(space);

            Paragraph firma2 = new Paragraph("TIENDA ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            firma2.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(firma2);
            documento.add(space);
            documento.add(space);
            documento.add(space);
            Paragraph firma3 = new Paragraph("Cotizacin vlida por siete das\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            firma3.setAlignment(Paragraph.ALIGN_CENTER);
            documento.add(firma3);
            documento.add(space);
            documento.add(space);
            try {
                Image im = Image.getInstance(f.getRutaCotizacion() + "footerword.png");
                im.setAlignment(Image.ALIGN_CENTER);
                im.scaleToFit(600, 500);
                documento.add(im);
            } catch (Exception ex) {
                setCursor(Cursor.getDefaultCursor());

                JOptionPane.showConfirmDialog(null,
                        "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL PIE DE PAGINA.", "ERROR",
                        JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);

            }
            documento.close();

            setCursor(Cursor.getDefaultCursor());

            JOptionPane.showConfirmDialog(null, "REALIZADO CORRECTAMENTE", "INFORMACIN",
                    JOptionPane.PLAIN_MESSAGE, JOptionPane.INFORMATION_MESSAGE);
        } catch (Exception ex) {
            setCursor(Cursor.getDefaultCursor());

            JOptionPane.showConfirmDialog(null, "ERROR" + ex.getMessage(), "ERROR", JOptionPane.PLAIN_MESSAGE,
                    JOptionPane.ERROR_MESSAGE);
        }

    }

}

From source file:GUI.frameNewVentaKit.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

    if (jLabel17.getText().toString().equals("-")) {
        JOptionPane.showMessageDialog(rootPane, "DEBE SELECCIONAR UN CLIENTE");
    } else {/* w w  w .  j a v  a2s. c o  m*/

        try {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            funciones f = new funciones();
            String dia = (Calendar.getInstance().getTime().getDate() < 10)
                    ? "0" + Calendar.getInstance().getTime().getDate()
                    : Calendar.getInstance().getTime().getDate() + "";
            String mes = f.get_mesMay((Calendar.getInstance().getTime().getMonth() + 1));
            String anio = (Calendar.getInstance().getTime().getYear() + 1900) + "";

            String nombre = "COTIZACION TIENDA ULTIMO ROUND";
            String rut_socio = "";
            int mon = 0;
            String arch = Calendar.getInstance().getTimeInMillis() + "_" + nombre + ".pdf";
            DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
            Date date = new Date();
            String stringToEncrypt = nombre.trim() + dateFormat.format(date);

            int encryptedString = stringToEncrypt.trim().hashCode();
            String aRemplazar = Integer.toString(encryptedString);
            String remplazado = aRemplazar.replace("-", "");

            String url = f.getRutaCotizacion() + arch;
            FileOutputStream archivo = new FileOutputStream(url);

            int deuda = Integer.parseInt("1");

            String palabra = f.Convertir(deuda + "", false);

            palabra = palabra.substring(0, palabra.length() - 2);
            if (palabra.split(" ")[palabra.split(" ").length - 1].equals("millones")
                    | palabra.split(" ")[palabra.split(" ").length - 1].equals("milln")) {
                palabra = palabra + "de pesos";
            } else {
                palabra = palabra + "pesos";
            }

            Document documento = new Document(PageSize.LETTER);
            PdfWriter.getInstance(documento, archivo);
            documento.open();
            try {
                Image im = Image.getInstance(f.getRutaCotizacion() + "headerword.png");
                im.setAlignment(Image.ALIGN_CENTER);
                im.scaleToFit(600, 400);
                documento.add(im);
            } catch (Exception e) {
                setCursor(Cursor.getDefaultCursor());

                JOptionPane.showConfirmDialog(null, "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL ENCABEZADO.",
                        "ERROR", JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);

            }

            int linea = 0;
            Font fuente = new Font();
            fuente.setStyle(Font.UNDERLINE | Font.BOLD);
            fuente.setSize(11);
            fuente.setColor(BaseColor.BLACK);
            documento.add(new Paragraph(" "));
            Paragraph fecha = new Paragraph(dia + " de " + mes.toLowerCase() + " de " + anio + "\n",
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            fecha.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(fecha);
            Paragraph obp = new Paragraph("ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            obp.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(obp);
            Paragraph codigo = new Paragraph("COD." + remplazado,
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            codigo.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(codigo);
            Paragraph space = new Paragraph("\n",
                    FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK));
            space.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(space);
            Paragraph origen = new Paragraph("ESTIMADO CLIENTE: " + jLabel13.getText() + "\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            origen.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(origen);
            Paragraph origen2 = new Paragraph("EMAIL: " + jLabel15.getText() + "\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            origen2.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(origen2);
            Paragraph a = new Paragraph(nombre,
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            a.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(a);
            Paragraph rut = new Paragraph(rut_socio,
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            rut.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(rut);
            Paragraph ref = new Paragraph("REF:COTIZACION POR PRODUCTOS TIENDA ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK));
            ref.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(ref);

            documento.add(space);
            int numerocheque = 0;
            int montofinal = 0;
            String montostring = "";
            String detalle = "";
            String monto = jLabel22.getText();

            String montoaux = monto.replace(".", "");

            deuda = Integer.parseInt(montoaux);

            palabra = f.Convertir(deuda + "", false);
            System.out.println(palabra);
            palabra = palabra.replaceAll("0", "");
            System.out.println(palabra);
            Paragraph e = new Paragraph(
                    "Junto con saludarlo, adjunto la cotizacin detallada de los siguientes productos"
                            + " por el monto de $" + monto + ".- ( " + palabra
                            + "pesos IVA INCLUIDO) ,segn detalle:\n\n",
                    FontFactory.getFont("times new roman", 11, Font.NORMAL, BaseColor.BLACK));
            e.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(e);
            documento.add(new Paragraph(" "));
            // ACA DEBE IR LA TABLA
            //special font sizes
            Font bfBold10 = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD, new BaseColor(0, 0, 0));
            Font bf10 = new Font(Font.FontFamily.TIMES_ROMAN, 10);
            //specify column widths

            //create PDF table with the given widths

            documento.add(new Paragraph(" "));
            float[] colsWidth = { 1.5f, 1.5f, 1.5f, 1.5f, 1.5f };
            PdfPTable tabla = new PdfPTable(5);
            tabla.setWidths(colsWidth);
            String[] titulos = { "PRODUCTO", "VALOR PRODUCTO", "TIPO", "MARCA", "TALLA" };

            tabla.setWidthPercentage(100);
            PdfPCell celda;
            for (int k = 0; k < titulos.length; k++) {
                celda = new PdfPCell(new Paragraph(titulos[k],
                        FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
            }
            int var = 0;
            int w = 0;
            for (w = 0; w < jTable1.getRowCount(); w++) {
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 1).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 7).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 4).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 3).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 2).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);

            }
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("MONTO NETO",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph(monto,
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("IVA TOTAL",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            double iva2 = Float.parseFloat(monto) * (0.19);
            iva2 = Math.round(iva2);

            celda = new PdfPCell(new Paragraph(Double.toString(iva2),
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("VALOR TOTAL",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            int valortotal = Integer.parseInt(monto);

            celda = new PdfPCell(new Paragraph(Integer.toString(valortotal),
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            documento.add(tabla);
            //FOOOTER
            documento.add(space);
            Paragraph despido = new Paragraph("Quedando a vuestra disposicin, saluda atentamente a Ud.,\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            despido.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(despido);
            documento.add(space);

            Paragraph firma2 = new Paragraph("TIENDA ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            firma2.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(firma2);
            documento.add(space);
            documento.add(space);
            documento.add(space);
            Paragraph firma3 = new Paragraph("Cotizacin vlida por siete das\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            firma3.setAlignment(Paragraph.ALIGN_CENTER);
            documento.add(firma3);
            documento.add(space);
            documento.add(space);
            try {
                Image im = Image.getInstance(f.getRutaCotizacion() + "footerword.png");
                im.setAlignment(Image.ALIGN_CENTER);
                im.scaleToFit(600, 500);
                documento.add(im);
            } catch (Exception ex) {
                setCursor(Cursor.getDefaultCursor());

                JOptionPane.showConfirmDialog(null,
                        "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL PIE DE PAGINA.", "ERROR",
                        JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);

            }
            documento.close();

            setCursor(Cursor.getDefaultCursor());

            JOptionPane.showConfirmDialog(null, "REALIZADO CORRECTAMENTE", "INFORMACIN",
                    JOptionPane.PLAIN_MESSAGE, JOptionPane.INFORMATION_MESSAGE);
        } catch (Exception ex) {
            setCursor(Cursor.getDefaultCursor());

            JOptionPane.showConfirmDialog(null, "ERROR" + ex.getMessage(), "ERROR", JOptionPane.PLAIN_MESSAGE,
                    JOptionPane.ERROR_MESSAGE);
        }

    }

}

From source file:info.longnetpro.examples.PdfLibExamples.java

public static void generatePdf()
        throws DocumentException, URISyntaxException, MalformedURLException, IOException {
    String licFile = getLicenseFilePath();
    loadLicenseFile(licFile);//from  w  w w.j a v a  2 s  .co  m

    String dest = getTargetFilePath();
    Document doc = new Document();
    PdfWriter.getInstance(doc, new FileOutputStream(dest));
    Rectangle pageSize = PageSize.LETTER;
    Rectangle rect = new Rectangle(0f, 0f, 50f, 100f);
    rect.setBorder(15);
    rect.setBorderColor(BaseColor.RED);
    rect.setBorderWidth(.5f);
    rect.setBackgroundColor(BaseColor.BLUE);
    doc.setPageSize(pageSize);
    doc.open();

    Page page = new Page(pageSize.getWidth(), pageSize.getHeight());
    ContentBox rpage = page.margin(new Float[] { 10f, 50f, 10f, 50f });

    for (Anchor anchor : Anchor.values()) {
        ContentBox box = new ContentBox(50f, 100f);
        float offx = anchor.equals(Anchor.CENTER) ? -50f : 0f;
        float offy = anchor.equals(Anchor.CENTER) ? -50f : 0f;

        ContentBox rr = anchor.anchorElement(rpage, box, offx, offy);

        if (anchor.equals(Anchor.BOTTOM_LEFT)) {
            float[] dim = box.scaleByPercentage(0.5f);
            //rr = rr.reposition(dim[0], dim[1], Anchor.TOP_RIGHT);
        }

        rect.setLeft(rr.getLeft());
        rect.setBottom(rr.getBottom());
        rect.setRight(rr.getRight());
        rect.setTop(rr.getTop());
        doc.add(rect);
    }
    String imageFile = getImageFilePath();
    Image image = Image.getInstance(imageFile);

    float width = Measurement.dotsToUserUnits(image.getWidth(), 1200);
    float height = Measurement.dotsToUserUnits(image.getHeight(), 1200);

    System.out.println(width + " " + height);

    ContentBox img = Anchor.BOTTOM_LEFT.anchorElement(rpage, width, height);

    image.scaleToFit(width, height);
    image.setAbsolutePosition(img.getLeft(), img.getBottom());

    System.out.println(image.getWidth() + " " + image.getHeight());
    System.out.println(image.getAbsoluteX() + " " + image.getAbsoluteY());

    doc.add(image);
    doc.close();
}

From source file:Inventario.Inventario2.java

public void createDocument(String filename, String extension) throws DocumentException, FileNotFoundException {
        try {/*from   w  w w.j  av  a  2 s .  com*/

            Document document = new Document(PageSize.LETTER, 50, 50, 85, 50);
            document.addAuthor("Inventario");
            document.addTitle("Reporte de Inventario Compra-Venta");

            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
            writer.setInitialLeading(16);
            Rectangle rct = new Rectangle(80, 104, 500, 688);
            writer.setBoxSize("art", rct);
            HeaderFooter event = new HeaderFooter();
            writer.setPageEvent(event);

            document.open();
            Paragraph parrafo2 = new Paragraph("Reportes de Inventario",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.GRAY));
            parrafo2.setAlignment(0);
            document.add(parrafo2);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);
            document.close();
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }

From source file:IPDGES.ConcentForm.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*from ww w  .  j a  v  a2 s  .  c o m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/pdf");

    try {
        //style
        Font typeBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, 1);
        Font type = new Font(Font.FontFamily.TIMES_ROMAN, 10);
        Font title = new Font(Font.FontFamily.TIMES_ROMAN, 15, 1);
        Font subTitle = new Font(Font.FontFamily.TIMES_ROMAN, 13, 1);
        Font subTitle2 = new Font(Font.FontFamily.TIMES_ROMAN, 10, 1);
        float space = (float) 20;

        Document document = new Document();
        document.setPageSize(PageSize.LETTER);
        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();

        //General
        PdfPTable table;
        Paragraph p1;
        Paragraph p2;
        PdfPCell cellRow1;
        PdfPCell cellRow2;

        //row: 1
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "FORMULARIO DE CONSTANCIA DE INFORMACION AL PACIENTE GES", title);
        p1.setAlignment(Element.ALIGN_CENTER);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "(Artculo 24, Ley 19.966)", subTitle2);
        p1.setAlignment(Element.ALIGN_CENTER);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row: 2
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "DATOS DEL PRESTADOR", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "INSTITUCIN (Hospital, Clnica, Consultorio,etc): " + institution, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "DIRECCION: " + address, type);
        p2 = new Paragraph(space, "CIUDAD: " + city, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "NOMBRE PERSONA QUE NOTIFICA: " + personName, type);
        p2 = new Paragraph(space, "RUT: " + rut, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        cellRow2.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row 3
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "ANTECEDENTES DEL PACIENTE", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "NOMBRE: " + patientName, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "RUT: " + patientRut, type);
        p2 = new Paragraph(space, "FONASA: " + patientFonasa, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "ISAPRE: " + patientIsapre, type);
        p2 = new Paragraph(space, "DOMICILIO: " + home, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "COMUNA: " + commune, type);
        p2 = new Paragraph(space, "REGION: " + region, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "N TELFONO FIJO: " + phoneNumber, type);
        p2 = new Paragraph(space, "N TELFONO CELULAR: " + celularNumber, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "DIRECCIN CORREO ELECTRNICO (E-MAIL): " + mail, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);

        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row 4
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "INFORMACIN MDICA", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "CONFIRMACIN DIAGNSTICA GES:", type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, ges, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "(  ) Confirmacin Diagnstica", type);
        p2 = new Paragraph(space, "(  ) Paciente en Tratamiento", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        cellRow2.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        //row 5
        document.add(new Paragraph(space, "CONSTANCIA", subTitle));
        Paragraph text1 = new Paragraph(space,
                "Declaro que, con esta fecha y hora, he tomado conocimiento que tengo derecho a acceder a las Garantas Explcitas en Salud, siempre que la atencin sea otorgada en la red de Prestadores que me corresponde segn Fonasa o Isapre, a la que me encuentro adscrito",
                type);
        text1.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(text1);
        document.add(new Paragraph(space, "IMPORTANTE", subTitle));
        Paragraph text2 = new Paragraph(space,
                "Tenga presente que s no se cumplen las garantas usted puede reclamar ante Fonasa o la Isapre, segn corresponda. Si la respuesta no es satisfactoria, usted puede recurrir en segunda instancia a la Superintendencia de Salud.",
                type);
        text2.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(text2);
        document.add(new Paragraph(space, "FECHA Y HORA DE NOTIFICACIN: " + "-", subTitle));
        document.add(new Paragraph(space, "\n", type));
        document.add(new Paragraph(space, "\n", type));
        document.add(new Paragraph(space, "\n", type));
        //row 6
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "INFORM DIAGNSTICO GES", subTitle);
        p2 = new Paragraph(space, "TOM CONOCIMIENTO", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "(Firma de persona que notifica)", subTitle2);
        p2 = new Paragraph(space, "(Firma o huella digital  representante)", subTitle2);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        //row 7
        document.add(new Paragraph(space,
                "En caso que la persona que tom conocimiento no sea el paciente, identificar.", type));

        //row 8
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Nombre:", type);
        p2 = new Paragraph(space, "R.U.T:", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "N Telfono Celular:", type);
        p2 = new Paragraph(space, "Direccin correo electrnico (e-mail):", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);

        document.close();
    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    }

}

From source file:IPDGES.IPD.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request//from   w  ww . j av a2  s  . co  m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("application/pdf");

    try {
        //style
        Font typeBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, 1);
        Font type = new Font(Font.FontFamily.TIMES_ROMAN, 12);
        Font title = new Font(Font.FontFamily.TIMES_ROMAN, 15, 1);
        Font subTitle = new Font(Font.FontFamily.TIMES_ROMAN, 13, 1);
        Font subTitle2 = new Font(Font.FontFamily.TIMES_ROMAN, 10, 1);
        float space = (float) 20;

        Document document = new Document();
        document.setPageSize(PageSize.LETTER);
        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();

        //General
        PdfPTable table;
        Paragraph p1;
        Paragraph p2;
        PdfPCell cellRow1;
        PdfPCell cellRow2;

        //row: 1
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Informe de Proceso Diagnstico", title);
        p1.setAlignment(Element.ALIGN_CENTER);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 40);
        table.addCell(cellRow1);
        document.add(table);

        //row: 2         
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Fecha: " + dfDateInstance.format(date), type);
        p2 = new Paragraph(space, "Folio: " + numberFolio, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row: 3
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Servicio de Salud: " + healthService, type);
        p2 = new Paragraph(space, "Establecimiento: " + establishment, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthTop(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "Especialidad: " + speciality, type);
        p2 = new Paragraph(space, "Unidad: " + unit, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthBottom(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthBottom(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        document.add(new Paragraph("\n"));
        //row: 4
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Datos del Paciente", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Historia clnica: " + clinicalHistory, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Nombre: " + patientName, type);
        p2 = new Paragraph(space, "Rut: " + Rut, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "Sexo: " + sexo, type);
        p2 = new Paragraph(space, "Fecha de nacimiento: " + dfDateInstance.format(bornDate), type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "Edad: " + age, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row 5
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Datos Clnicos", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthBottom(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "* Slo para caso AUGE", subTitle2);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Problema de salud AUGE:", typeBold);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, augeProblem, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Confirma que el diagnstico pertenece al sistema AUGE? " + "()SI ()NO",
                type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "SubProblema Auge:", typeBold);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, augeSubProblem, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Diagnstico:", typeBold);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, diagnosis, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Fundamentos de diagnstico:", typeBold);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, diagnosticBasics, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Tratamiento e Indicaciones:", typeBold);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, treatment, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space,
                "El tratamiento deber iniciarce a ms tardar el: " + dfDateInstance.format(treatmentInit),
                type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));
        //row: 6
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Datos del Profesional", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Nombre: " + professionalName, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Rut: " + professionalRut, type);
        p2 = new Paragraph(space, "Firma del mdico", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        cellRow2.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));
        document.close();
    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    }

}

From source file:logica.Generar_pdf.java

public void ConvertirPDF(int num, String nombre, String nombre2, String cedula, String cedula2,
        String direccion, String direccion2, String telefono, String telefono2, String sede, String tipo,
        String observacion, int peso, int declaracion_precio, int precio_neto, int precio_seguro,
        int precio_impuesto, int total_envio, String forma_pago, String fecha) throws FileNotFoundException {
    String nombre_pdf = "Factura No " + num + ".pdf";
    System.out.println(nombre_pdf);
    try {/*from   ww w  .  j  av  a2s . c  om*/
        //Creamos documento indicando el tamao y margenes
        Document documento = new Document(PageSize.LETTER, 20, 20, 20, 20);

        //Creamos el PDF y lo instanceamos para poder escribir sobre el
        PdfWriter.getInstance(documento, new FileOutputStream(nombre_pdf)).setInitialLeading(20);

        //Abrimos el documento
        documento.open();
        System.out.println("Documento Abierto");

        //Anexamos el texto a un objeto Pharagraph
        Paragraph parametro = new Paragraph("Factura Envio de Paquete No. " + num,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLD, BaseColor.BLACK));
        parametro.setAlignment(1);
        Paragraph parametro17 = new Paragraph("Fecha: " + fecha,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLD, BaseColor.BLACK));
        parametro17.setAlignment(1);
        Paragraph parametro2 = new Paragraph("Datos Remitente",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD, BaseColor.BLACK));
        Paragraph parametro3 = new Paragraph("Nombre: " + nombre + "        Telefono: " + telefono,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro4 = new Paragraph("Cedula: " + cedula + "        Direccin: " + direccion,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro5 = new Paragraph("Datos Destinatario",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD, BaseColor.BLACK));
        Paragraph parametro6 = new Paragraph("Nombre: " + nombre2 + "        Telefono: " + telefono2,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro7 = new Paragraph("Cedula: " + cedula2 + "        Direccin: " + direccion2,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));

        Paragraph parametro8 = new Paragraph("Datos Envio",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD, BaseColor.BLACK));
        Paragraph parametro9 = new Paragraph("Tipo de Envio: " + tipo + "        Observacin: " + observacion,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro10 = new Paragraph(
                "Peso: " + peso + "        Declaracin precio Envio: " + declaracion_precio,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro11 = new Paragraph("Datos Pago",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD, BaseColor.BLACK));
        Paragraph parametro12 = new Paragraph("Precio de Envio Neto: " + precio_neto,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro13 = new Paragraph("Precio Seguro:  " + precio_seguro,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro14 = new Paragraph("Excedente Impuesto:  " + precio_impuesto,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro15 = new Paragraph("Total Envio:  " + total_envio,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro16 = new Paragraph("Forma de Pago:  " + forma_pago,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));

        //Escribimos sobre el
        documento.add(parametro);
        documento.add(parametro17);
        documento.add(parametro2);
        documento.add(parametro3);
        documento.add(parametro4);
        documento.add(parametro5);
        documento.add(parametro6);
        documento.add(parametro7);
        documento.add(parametro8);
        documento.add(parametro9);
        documento.add(parametro10);
        documento.add(parametro11);
        documento.add(parametro12);
        documento.add(parametro13);
        documento.add(parametro14);
        documento.add(parametro15);
        documento.add(parametro16);

        //Cerrar documento
        documento.close();

        //Mensaje de Exito
        JOptionPane.showMessageDialog(null, "PDF Creado con exito.");

    } catch (DocumentException de) {
        System.out.println("Error...");
    }

}