Example usage for com.itextpdf.text Font Font

List of usage examples for com.itextpdf.text Font Font

Introduction

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

Prototype


public Font(final FontFamily family, final float size, final int style) 

Source Link

Document

Constructs a Font.

Usage

From source file:Modelo.CotizacionDAO.java

public void writePdf(OutputStream outputStream, Cotizacion x, int idcotizacion) throws Exception {

    DateFormat df = new SimpleDateFormat("dd/MM/YYYY");
    Calendar cdos = Calendar.getInstance();
    Date datediamas = new Date();
    Date dateaniomas = new Date();
    cdos.add(Calendar.DATE, 1);/*  ww w . java 2s . c  o  m*/
    datediamas = cdos.getTime();
    String fechadiamas = df.format(datediamas);
    cdos.add(Calendar.YEAR, 1);
    dateaniomas = cdos.getTime();
    String fechavencimiento = df.format(dateaniomas);

    Document document = new Document(PageSize.LETTER, 50, 50, 50, 30);
    Font boldFontTitulo = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD);
    Font boldFontTexto = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD);
    Font FontTexto = new Font(Font.FontFamily.HELVETICA, 10);

    // document.setPageSize(null);
    PdfWriter writer = PdfWriter.getInstance(document, outputStream);

    Image imagen = Image.getInstance("http://54.67.56.185/BSeguros_pa18/img/BSeguroLogo.png");
    //      Image imagen = Image.getInstance("D:\\ALEX\\Bseguros\\web\\img\\Aseguradoras\\BSeguroLogo.png");
    Image imagen2 = Image.getInstance(
            "http://54.67.56.185/BSeguros_pa18/img/Aseguradoras/" + x.getId_aseguradora() + ".png");
    //Image imagen2 = Image.getInstance("D:\\ALEX\\Bseguros\\web\\img\\Aseguradoras\\Mapfre.png");

    document.open();

    PdfContentByte canvas = writer.getDirectContent();
    Rectangle rect = new Rectangle(36, 36, 579, 756);
    rect.setBorder(Rectangle.BOX);
    rect.setBorderWidth(2);
    canvas.rectangle(rect);

    document.addTitle("Cotizacion");
    document.addSubject("Cotizacion");
    document.addKeywords("Cotizacion, seguros");
    document.addAuthor("BSeguro");
    document.addCreator("Bseguro");

    imagen.scaleAbsoluteHeight(30f);
    imagen.setAbsolutePosition(45f, 720f);
    imagen2.scaleAbsoluteHeight(30f);
    imagen2.setAbsolutePosition(450f, 720f);
    document.add(imagen);
    document.add(imagen2);

    Paragraph paragraph2 = new Paragraph("DATOS DE TU POLIZA", boldFontTitulo);
    paragraph2.setAlignment(Element.ALIGN_CENTER);
    document.add(paragraph2);

    //creas una tabla con un ancho de 3 celdas, el salto a la siguiente fila sera automatico
    PdfPTable table = new PdfPTable(3);
    table.getDefaultCell().setBorder(0);
    PdfPCell cell;

    Paragraph saltodelinea = new Paragraph(" ");
    document.add(saltodelinea);

    document.add(new Paragraph(" Datos de tu poliza folio: " + "BC" + x.getId_aseguradora().substring(0, 1)
            + x.getMetododepago().substring(0, 1) + ": 0000" + idcotizacion, boldFontTitulo));
    document.add(new Paragraph(" Vigencia de la poliza del: " + fechadiamas + " al: " + fechavencimiento,
            boldFontTitulo));
    document.add(saltodelinea);

    document.add(new Paragraph(" Datos del Contratante: ", boldFontTitulo));
    //document.add(saltodelinea);

    //agrego otra tabla
    table = new PdfPTable(6);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);
    table.addCell(new Paragraph("Nombre: ", boldFontTexto));
    PdfPCell celdaNombre = new PdfPCell(
            new Paragraph(x.getNombre_contratante() + " " + x.getApellido_paterno(), FontTexto));
    celdaNombre.setColspan(5);
    celdaNombre.setBorder(0);
    table.addCell(celdaNombre);
    table.addCell(new Paragraph("RFC : ", boldFontTexto));
    PdfPCell celdaRFC = new PdfPCell(new Paragraph(x.getRfc(), FontTexto));
    celdaRFC.setColspan(5);
    celdaRFC.setBorder(0);
    table.addCell(celdaRFC);
    table.addCell(new Paragraph("Direccion: ", boldFontTexto));
    PdfPCell celdaDir = new PdfPCell(
            new Paragraph(x.getCall() + ", " + x.getNo_ext() + ", " + x.getNo_int() + ", " + x.getColonia()
                    + ", " + x.getDelegacion() + ", " + x.getEstado() + ", " + x.getCp(), FontTexto));
    celdaDir.setColspan(5);
    celdaDir.setBorder(0);
    table.addCell(celdaDir);
    table.addCell(new Paragraph("Email: ", boldFontTexto));
    table.addCell(AddCell(x.getMail(), 5));
    table.addCell(new Paragraph("Telefono ", boldFontTexto));
    PdfPCell celdaTel = new PdfPCell(new Paragraph(x.getTelefono(), FontTexto));
    celdaTel.setColspan(5);
    celdaTel.setBorder(0);
    table.addCell(celdaTel);

    document.add(table);
    document.add(saltodelinea);

    document.add(new Paragraph(" Datos del Vehiculo: ", boldFontTitulo));
    //      document.add(saltodelinea);

    //agrego otra tabla
    table = new PdfPTable(6);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);
    table.addCell(new Paragraph("Marca: ", boldFontTexto));
    table.addCell(AddCell(x.getId_marca(), 5));
    table.addCell(new Paragraph("Modelo:", boldFontTexto));
    table.addCell(AddCell(x.getId_anio().toString(), 5));
    table.addCell(new Paragraph("Tipo: ", boldFontTexto));
    table.addCell(AddCell(x.getId_submarca(), 5));
    table.addCell(new Paragraph("Version:  ", boldFontTexto));
    table.addCell(AddCell(x.getId_modelo(), 5));
    table.addCell(new Paragraph("No. De Serie: ", boldFontTexto));
    table.addCell(AddCell(x.getSerie(), 5));

    document.add(table);
    document.add(saltodelinea);

    document.add(new Paragraph(" Informacion de la Poliza: ", boldFontTitulo));
    //    document.add(saltodelinea);

    //agrego otra tabla
    table = new PdfPTable(6);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);
    table.addCell(new Paragraph("Pago: ", boldFontTexto));
    table.addCell(AddCell(x.getTipo_pago(), 5));
    table.addCell(new Paragraph("Aseguradora: ", boldFontTexto));
    table.addCell(AddCell(x.getId_aseguradora(), 5));

    document.add(table);
    document.add(saltodelinea);

    document.add(new Paragraph(" Detalles de la Cobertura: Cobertura Amplia ", boldFontTitulo));
    //  document.add(saltodelinea);

    //agrego otra tabla
    table = new PdfPTable(3);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);
    table.addCell(new Paragraph("Cobertura ", boldFontTexto));
    table.addCell(new Paragraph("Responsabilidad Civil", boldFontTexto));
    table.addCell(new Paragraph("Deducible ", boldFontTexto));
    table.addCell(new Paragraph("Daos Materiales", FontTexto));
    table.addCell(new Paragraph("Valor Comercial", FontTexto));
    table.addCell(new Paragraph("5%", FontTexto));
    table.addCell(new Paragraph("Robo Total", FontTexto));
    table.addCell(new Paragraph("Valor Comercial", FontTexto));
    table.addCell(new Paragraph("10%", FontTexto));
    table.addCell(new Paragraph("Responsabilidad Civil", FontTexto));
    table.addCell(new Paragraph("$4,000,000.00", FontTexto));
    table.addCell(new Paragraph("", FontTexto));
    table.addCell(new Paragraph("Gastos Medicos Ocupantes", FontTexto));
    table.addCell(new Paragraph("$500,000.00", FontTexto));
    table.addCell(new Paragraph("", FontTexto));
    table.addCell(new Paragraph("Asistencia Legal", FontTexto));
    table.addCell(new Paragraph("Amparada", FontTexto));
    table.addCell(new Paragraph("", FontTexto));
    table.addCell(new Paragraph("Asistencia Vial", FontTexto));
    table.addCell(new Paragraph("Amparada", FontTexto));
    table.addCell(new Paragraph("", FontTexto));

    document.add(table);
    document.add(saltodelinea);

    document.add(new Paragraph(" Informacion del Pago ", boldFontTitulo));
    document.add(new Paragraph(" Instrumento de Pago: " + x.getMetododepago(), boldFontTexto));

    //agrego otra tabla
    table = new PdfPTable(6);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);
    table.addCell(AddCell("Concepto ", 2));
    table.addCell(AddCell("Monto", 4));
    table.addCell(AddCell("Prima Total ", 2));
    table.addCell(AddCell(x.getMonto(), 4));
    table.addCell(AddCell("Prima Inicial", 2));
    table.addCell(AddCell(x.getMonto(), 4));
    table.addCell(AddCell("Pago Subsecuente ", 2));
    table.addCell(AddCell("0", 4));

    document.add(table);
    document.add(saltodelinea);

    if (x.getCobertura_auto_siempre() == true) {

        document.add(new Paragraph(" Informacion de Modulos HDI ", boldFontTitulo));
        table = new PdfPTable(6);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(0);
        table.addCell(AddCell("Modulos ", 2));
        table.addCell(AddCell("Contratados", 4));
        table.addCell(AddCell("HDI - Autos por Siempre ", 2));
        table.addCell(AddCell("$ 1,799.00", 4));
        document.add(table);

    } else {
        if (x.getCobertura_auto_amante() == true) {

            document.add(new Paragraph(" Informacion de Modulos HDI ", boldFontTitulo));
            table = new PdfPTable(6);
            table.setWidthPercentage(100);
            table.getDefaultCell().setBorder(0);
            table.addCell(AddCell("Modulos ", 2));
            table.addCell(AddCell("Contratados", 4));
            table.addCell(AddCell("HDI - Amante de los Autos ", 2));
            table.addCell(AddCell("$ 1,799.00", 4));
            document.add(table);

        } else {

        }
        document.add(saltodelinea);
    }
    document.add(new Paragraph("* Estaras asegurado a partir de las 12 horas del siguiente dia habil.",
            boldFontTexto));

    document.close();

}

From source file:modelo.GeneratorPDF.java

public static void main(String[] args) {
    // criao do documento 
    Document document = new Document(PageSize.A4, 72, 72, 72, 72);
    try {//from w  w  w . j a  v a2s  . co  m
        PdfWriter.getInstance(document, new FileOutputStream("C:\\Users\\Amanda\\Desktop\\teste.pdf"));

        document.open();
        Font f = new Font(FontFamily.COURIER, 20, Font.BOLD);

        // adicionando um pargrafo no documento 
        Paragraph p1 = new Paragraph("Gerando PDF - Java", f);
        p1.setAlignment(Element.ALIGN_CENTER);
        document.add(p1);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:mvjce.PDF.java

public static void create(int sino) {// sino = SI.No
    // TODO code application logic here
    try {// ww w.j  a v  a  2s.  c  o m
        //Create Document instance.
        Document document = new Document();

        //Create OutputStream instance.
        OutputStream outputStream = new FileOutputStream(
                new File("/home/narein/NetBeansProjects/" + sem + cl + "/" + usn + ".pdf"));

        //Create PDFWriter instance.
        PdfWriter.getInstance(document, outputStream);

        //Open the document.
        document.open();
        //image position
        Image imageCenter = Image.getInstance("/home/narein/Downloads/mvj.png");
        //imageCenter.setAlignment(Image.MIDDLE);
        imageCenter.setAbsolutePosition(235, 780);
        imageCenter.scaleAbsolute(146f, 53f);
        //Permanently affiliated para
        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.addCell(getCell(
                "\n\n\nPermanently affiliated to VTU, Govt. of Karnataka\nApproved by AICTE, New Delhi\nNear ITPB, Bengaluru- 560067\n\n"
                        + hod_name + ", HOD - " + dep,
                PdfPCell.ALIGN_LEFT));
        table.addCell(getCell("\n\n\n\nPh: 080-42991000\nFax: 080-28452443\nWebsite: www.mvjce.edu.in\nEmail: "
                + hod_email + "\n\n", PdfPCell.ALIGN_RIGHT));
        //line across pdf
        final LineSeparator lineSeparator = new LineSeparator();
        Chunk linebreak = new Chunk(lineSeparator);
        Phrase p = new Phrase("\nPROGRESS REPORT\n",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.UNDERLINE | Font.BOLD));
        Paragraph para = new Paragraph(p);
        para.setAlignment(Element.ALIGN_CENTER);
        Chunk glue = new Chunk(new VerticalPositionMark());
        Paragraph p1 = new Paragraph("\nRef:", new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD));
        p1.add(new Chunk(glue));
        //get current date
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yyyy");
        LocalDate localDate = LocalDate.now();
        //add date to pdf
        p1.add(new Phrase("Date: " + dtf.format(localDate) + "\n",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
        Phrase dear_prnts = new Phrase("Dear Parents,\n", new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD));
        Phrase The_acad = new Phrase(
                "                  The academic performance of your ward Mr/Ms " + name + " of Semester " + sem
                        + " bearing the USN " + usn + " is as follows,\n\n",
                new Font(FontFamily.TIMES_ROMAN, 9));
        Phrase Rem = new Phrase("Remarks\n", new Font(FontFamily.TIMES_ROMAN, 10, Font.UNDERLINE | Font.BOLD));
        Phrase your_ward = new Phrase(
                "\nYour ward's overall performance is Good / Satisfactory / Poor / Very Poor\n",
                new Font(FontFamily.TIMES_ROMAN, 9));
        Phrase you_are = new Phrase("\nYou are requested to:\n",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD));
        Phrase req = new Phrase("");
        Paragraph para2 = new Paragraph(
                "1) Advice your ward to attend classes regularly\n2) Note that he/she may likely be detainedfrom appearing for examinations\n"
                        + "3) Advice your ward to improve in Test/Exam performance particularly in subject\n4) Meet the Head of the Department\n5) Meet the principal\n",
                new Font(FontFamily.TIMES_ROMAN, 9));
        Chunk glue1 = new Chunk(new VerticalPositionMark());
        Paragraph p3 = new Paragraph("\nSIGNATURE:\n\nNAME OF PROCTOR:\n\nCONTACT NUMBER:",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD));
        p3.add(new Chunk(glue1));
        p3.add(new Phrase(
                "SIGNATURE OF HOD\n\n            Kindly attend the Parent Teacher Meeting to be held on the date informed to your ward.\n",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
        Phrase Note = new Phrase("\nNOTE:", new Font(FontFamily.TIMES_ROMAN, 10, Font.UNDERLINE | Font.BOLD));
        Paragraph p4 = new Paragraph();
        p4.add(Note);
        p4.add(new Phrase(
                "  Parents are requested to contact the proctor (By Email/Letter/Phone) and confirm receipt of this feedback. Parents are also"
                        + "welcome to interact with proctors/subject faculty/ HOD for any discussion/clarification.\n",
                new Font(FontFamily.TIMES_ROMAN, 9)));
        //Add content to the document.
        document.add(imageCenter);
        document.add(table);
        document.add(linebreak);
        document.add(para);
        document.add(p1);
        document.add(dear_prnts);
        document.add(The_acad);
        document.add(createinternalsTable());
        if (internal.equals("1")) {
            document.add(new Phrase("\nPREVIOUS SEMESTER VTU RESULT\n\n",
                    new Font(FontFamily.TIMES_ROMAN, 10, Font.UNDERLINE | Font.BOLD)));
            document.add(createexternalTable());
        }
        document.add(Rem);
        document.add(your_ward);
        document.add(you_are);
        document.add(para2);
        document.add(p3);
        document.add(p4);
        //document.add(paragraph);document.add(paragraph1);

        //Close document and outputStream.
        document.close();
        outputStream.close();

        System.out.println("Pdf created successfully.");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:mvjce.PDF.java

public static PdfPCell getCell(String text, int alignment) {

    PdfPCell cell = new PdfPCell(new Phrase(text, new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
    cell.setPadding(1);/*from ww w.  ja va2 s. c  o m*/
    cell.setHorizontalAlignment(alignment);
    cell.setBorder(PdfPCell.NO_BORDER);
    return cell;
}

From source file:mvjce.PDF.java

public static PdfPTable createinternalsTable() {
    // a table with five columns
    PdfPTable table = new PdfPTable(5);
    float f[] = new float[] { 0.5f, 3f, 1f, 1f, 1.5f };
    try {/*from w  w  w  .j ava 2s  .  c  o m*/
        table.setWidths(f);
    } catch (Exception e) {
        System.out.println(e);
    }
    // the cell object
    PdfPCell cell;
    // we add a cell with colspan 3
    cell = new PdfPCell(new Phrase("SI.No", new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD)));
    cell.setRowspan(3);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("SUBJECT TITLE", new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD)));
    cell.setRowspan(3);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("SUB CODE", new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD)));
    cell.setRowspan(3);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    cell = new PdfPCell(
            new Phrase("Internal" + internal + " Test Marks", new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD)));
    cell.setRowspan(3);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("Attendance\nAS ON DATE", new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD)));
    cell.setRowspan(3);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    for (int i = 1; i <= 8; i++) {
        table.addCell(new Phrase(Integer.toString(i), new Font(FontFamily.TIMES_ROMAN, 9)));
        table.addCell(new Phrase(sub[i - 1], new Font(FontFamily.TIMES_ROMAN, 9)));
        table.addCell(new Phrase(subcode[i - 1], new Font(FontFamily.TIMES_ROMAN, 9)));
        table.addCell(new Phrase(intr[i - 1], new Font(FontFamily.TIMES_ROMAN, 9)));
        table.addCell(new Phrase(att[i - 1], new Font(FontFamily.TIMES_ROMAN, 9)));
    }
    return table;
    //}catch(Exception e){System.out.println(e);}return null;
}

From source file:nwk.com.br.documents.OrcamentoPdf.java

private PdfPTable dadosRodape(Orcamento orcamento) throws Exception {
    //tabela que pega com 100% do tamanho do arquivo, alinhada no centro com tres colunas e sem bordas
    PdfPTable rodape = new PdfPTable(new float[] { 0.5f, 0.2f, 0.3f });
    rodape.setWidthPercentage(100.0f);//seta o tamanho da tabela em relaao ao documento
    rodape.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    rodape.getDefaultCell().setBorder(0);

    PdfPCell obs = new PdfPCell(new Paragraph("\n\n Observaes:\n" + orcamento.getObservacoes(), f));
    PdfPCell ass = new PdfPCell(new Paragraph("\n\n_________________________\nAssinatura", f));

    Font fonteAviso = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLDITALIC);

    PdfPCell spc = new PdfPCell(new Paragraph(" "));
    PdfPCell aviso = new PdfPCell(new Paragraph(
            "AGRADEEMOS A PREFERNCIA\nORAMENTO VALIDO SOMENTE PARA O DIA DE SUA CRIAO!", fonteAviso));

    aviso.setHorizontalAlignment(Element.ALIGN_CENTER);
    obs.setHorizontalAlignment(Element.ALIGN_LEFT);
    ass.setHorizontalAlignment(Element.ALIGN_CENTER);

    obs.setBorder(0);/*from  w w w . j  av a  2 s. co m*/
    ass.setBorder(0);
    spc.setBorder(0);
    aviso.setBorder(0);

    spc.setColspan(3);
    aviso.setColspan(3);

    rodape.addCell(obs);
    rodape.addCell(new Paragraph(" "));
    rodape.addCell(ass);
    rodape.addCell(spc);
    rodape.addCell(spc);
    rodape.addCell(spc);
    rodape.addCell(spc);
    rodape.addCell(aviso);
    //rodape.setExtendLastRow(true);

    //cria uma nova celula que recebe a tabela anterior
    PdfPCell otherCell = new PdfPCell(rodape);
    otherCell.setBorder(0);
    otherCell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    otherCell.setHorizontalAlignment(Element.ALIGN_CENTER);

    //cria uma nova tabela que recebe a celula otherCell
    PdfPTable rodape2 = new PdfPTable(new float[] { 1.0f });
    rodape2.setWidthPercentage(100.0f);//seta o tamanho da tabela em relaao ao documento

    rodape2.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    rodape2.getDefaultCell().setBorder(0);

    //estende a tabela at o fim da pagina, como o alinhamento horizontal dela  bottom, ela fica toda no rodape
    rodape2.addCell(otherCell);
    rodape2.setExtendLastRow(true);

    return rodape2;
}

From source file:Operaciones.Destajo.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    // TODO add your handling code here:
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);//from   w w  w  .  ja va2 s. c  o  m
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        session.beginTransaction().begin();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
        //Orden ord=buscaApertura();
        PDF reporte = new PDF();
        Date fecha = new Date();
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
        String valor = dateFormat.format(fecha);
        File folder = new File("reportes/" + ord);
        folder.mkdirs();
        reporte.Abrir(PageSize.LETTER.rotate(), "Valuacin", "reportes/" + ord + "/" + valor + "-destajo.pdf");
        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);
        BaseColor contenido = BaseColor.WHITE;
        int centro = Element.ALIGN_CENTER;
        int izquierda = Element.ALIGN_LEFT;
        int derecha = Element.ALIGN_RIGHT;
        float tam[] = new float[] { 150, 50, 100, 300 };
        PdfPTable tabla = reporte.crearTabla(4, tam, 100, Element.ALIGN_LEFT);

        DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00");
        formatoPorcentaje.setMinimumFractionDigits(2);

        cabecera(reporte, bf, tabla);

        session.beginTransaction().begin();
        Orden dato = (Orden) session.get(Orden.class, Integer.parseInt(this.ord));
        List cuentas = null;
        for (int x = 0; x < t_datos.getRowCount(); x++) {
            tabla.addCell(reporte.celda(t_datos.getValueAt(x, 1).toString(), font, contenido, izquierda, 0, 1,
                    Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda(formatoPorcentaje.format((Double) t_datos.getValueAt(x, 2)), font,
                    contenido, derecha, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda(formatoPorcentaje.format((Double) t_datos.getValueAt(x, 3)), font,
                    contenido, derecha, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda(t_datos.getValueAt(x, 4).toString(), font, contenido, izquierda, 0, 1,
                    Rectangle.RECTANGLE));
        }
        session.beginTransaction().rollback();

        tabla.setHeaderRows(1);
        reporte.agregaObjeto(tabla);
        reporte.cerrar();
        reporte.visualizar("reportes/" + ord + "/" + valor + "-destajo.pdf");

    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto.");
    }
    if (session != null)
        if (session.isOpen()) {
            session.flush();
            session.clear();
            session.close();
        }
}

From source file:Operaciones.Destajo.java

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
    // TODO add your handling code here:
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);//w w w  .  ja  va  2 s  . c o m
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        session.beginTransaction().begin();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
        //Orden ord=buscaApertura();
        PDF reporte = new PDF();
        Date fecha = new Date();
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
        String valor = dateFormat.format(fecha);
        File folder = new File("reportes/" + ord);
        folder.mkdirs();
        reporte.Abrir(PageSize.LETTER.rotate(), "Valuacin", "reportes/" + ord + "/" + valor + "-destajo.pdf");
        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);
        BaseColor contenido = BaseColor.WHITE;
        int centro = Element.ALIGN_CENTER;
        int izquierda = Element.ALIGN_LEFT;
        int derecha = Element.ALIGN_RIGHT;
        float tam[] = new float[] { 150, 50, 100, 300 };
        PdfPTable tabla = reporte.crearTabla(4, tam, 100, Element.ALIGN_LEFT);

        cabecera(reporte, bf, tabla);

        session.beginTransaction().begin();
        Orden dato = (Orden) session.get(Orden.class, Integer.parseInt(this.ord));
        List cuentas = null;
        for (int x = 0; x < 21; x++) {
            tabla.addCell(reporte.celda(" \n ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda(" \n ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda(" \n ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda(" \n ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
        }
        session.beginTransaction().rollback();

        tabla.setHeaderRows(1);
        reporte.agregaObjeto(tabla);
        reporte.cerrar();
        reporte.visualizar("reportes/" + ord + "/" + valor + "-destajo.pdf");

    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto.");
    }
    if (session != null)
        if (session.isOpen()) {
            session.flush();
            session.clear();
            session.close();
        }
}

From source file:Operaciones.Destajo.java

public void cabecera(PDF reporte, BaseFont bf, PdfPTable tabla) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {/*w  w  w .  j  a v  a  2  s  .c  o m*/
        reporte.contenido.setLineWidth(0.5f);
        reporte.contenido.setColorStroke(new GrayColor(0.2f));
        reporte.contenido.setColorFill(new GrayColor(0.9f));
        reporte.contenido.roundRectangle(160, 515, 210, 45, 5);
        reporte.contenido.roundRectangle(380, 515, 375, 45, 5);
        reporte.contenido.roundRectangle(35, 480, 720, 30, 5);

        reporte.inicioTexto();
        reporte.contenido.setFontAndSize(bf, 14);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, con.getEmpresa(), 160, 580, 0);
        reporte.contenido.setFontAndSize(bf, 8);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Hoja de Avance", 160, 570, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 760, 580, 0);

        Orden dato = (Orden) session.get(Orden.class, Integer.parseInt(ord));
        Foto foto = (Foto) session.createCriteria(Foto.class)
                .add(Restrictions.eq("orden.idOrden", Integer.parseInt(ord))).addOrder(Order.desc("fecha"))
                .setMaxResults(1).uniqueResult();
        if (foto != null) {
            reporte.agregaObjeto(reporte.crearImagen(
                    "ordenes/" + dato.getIdOrden() + "/" + foto.getDescripcion(), 0, -60, 120, 80, 0));
        } else {
        }
        //************************datos de la orden****************************
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Orden:" + dato.getIdOrden(), 164, 550, 0);

        if (dato.getFecha() != null)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Apertura:" + dato.getFecha(), 285,
                    550, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Apertura:", 285, 550, 0);

        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "Compaia:" + dato.getCompania().getIdCompania() + " " + dato.getCompania().getNombre(), 164,
                540, 0);

        if (dato.getSiniestro() != null)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Siniestro:" + dato.getSiniestro(),
                    164, 530, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Siniestro:", 164, 530, 0);

        if (dato.getFechaSiniestro() != null)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "F. Siniestro:" + dato.getFechaSiniestro(), 285, 530, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "F.Siniestro:", 285, 530, 0);

        if (dato.getPoliza() != null)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Poliza:" + dato.getPoliza(), 164, 520,
                    0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Poliza:", 164, 520, 0);

        if (dato.getInciso() != null)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Inciso:" + dato.getInciso(), 285, 520,
                    0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Inciso:", 285, 520, 0);
        //**********************************************************

        //************datos de la unidad
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Unidad:" + dato.getTipo().getTipoNombre(),
                385, 550, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT, "Modelo:" + dato.getModelo(), 664, 550,
                0);

        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "Marca:" + dato.getMarca().getMarcaNombre(), 385, 540, 0);
        if (dato.getNoEconomico() != null)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT, "Economico:" + dato.getNoEconomico(),
                    664, 540, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT, "Economico:", 664, 540, 0);

        if (dato.getNoMotor() != null)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "N Motor:" + dato.getNoMotor(), 385,
                    530, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "N Motor:", 385, 530, 0);

        if (dato.getNoSerie() != null)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "N Serie:" + dato.getNoSerie(), 385,
                    520, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "N Serie:", 385, 520, 0);
        //*************************************************************

        switch (this.global) {
        case "h":
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Especialidad: Hojalateria", 40, 495,
                    0);
            break;
        case "m":
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Especialidad: Mecanica", 40, 495, 0);
            break;
        case "s":
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Especialidad: Suspension", 40, 495,
                    0);
            break;
        case "e":
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Especialidad: electrico", 40, 495, 0);
            break;
        case "p":
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Especialidad: Pintura", 40, 495, 0);
            break;
        }
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Empleado:" + t_responsable.getText(), 165,
                495, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "Fecha Asignacin:" + t_asignacion.getText(), 430, 495, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Fecha Limite:" + t_limite.getText(), 600,
                495, 0);

        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Monto x Hora: $" + t_monto.getText(), 40,
                485, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Horas Totales: " + t_horas.getText(), 165,
                485, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Importe a Pagar: $" + t_importe.getText(),
                600, 485, 0);

        reporte.finTexto();
        //agregamos renglones vacios para dejar un espacio
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));

        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);

        BaseColor cabecera = BaseColor.GRAY;
        BaseColor contenido = BaseColor.WHITE;
        int centro = Element.ALIGN_CENTER;
        int izquierda = Element.ALIGN_LEFT;
        int derecha = Element.ALIGN_RIGHT;

        tabla.addCell(reporte.celda("Fecha Avance", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("% de Avance", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Importe Pagado", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Notas", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    } catch (Exception e) {
        System.out.println(e);
    }
    if (session != null)
        if (session.isOpen()) {
            session.flush();
            session.clear();
            session.close();
        }
}

From source file:opticalworkshopmonitoringsystem.CenteringAndEdgingView.java

License:Open Source License

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    //code for the forating of the pdf report.

    try {/*from w  w w.  j a  va2s. c o m*/
        Document document = new Document();
        JFileChooser fc = new JFileChooser();
        fc.showOpenDialog(null);

        PdfWriter.getInstance(document, new FileOutputStream(fc.getSelectedFile().getAbsolutePath()));
        document.open();

        Font courierFontItalic = new Font(Font.FontFamily.COURIER, 10, Font.ITALIC);
        Font courierFontUnderline = new Font(Font.FontFamily.COURIER, 10, Font.UNDERLINE);
        Font tr = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
        Font timesRomanUnderline = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.UNDERLINE);
        Font helvetica = new Font(Font.FontFamily.HELVETICA, 14, Font.UNDERLINE);

        document.add(new Paragraph(
                "                         Centering And Edging Division                            ",
                timesRomanUnderline));
        document.add(new Paragraph(
                "----------------------------------------------------------------------------------------------------------------------------------"));

        document.add(new Paragraph(jLabel1.getText(), tr));
        document.add(
                new Chunk("                                                      " + jTextField1.getText()));
        document.add(new Paragraph(
                "----------------------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph(jLabel2.getText(), tr));
        document.add(
                new Chunk("                                                      " + jTextField2.getText()));
        document.add(new Paragraph(
                "----------------------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph(jLabel3.getText(), tr));
        document.add(
                new Chunk("                                                      " + jTextField3.getText()));
        document.add(new Paragraph(
                "----------------------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph(jLabel4.getText(), tr));
        document.add(
                new Chunk("                                                      " + jTextField4.getText()));
        document.add(new Paragraph(
                "----------------------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph(jLabel5.getText(), tr));
        document.add(
                new Chunk("                                                      " + jTextField5.getText()));
        document.add(new Paragraph(
                "----------------------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph(jLabel6.getText(), tr));
        document.add(
                new Chunk("                                                      " + jTextField6.getText()));
        document.add(new Paragraph(
                "----------------------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph(jLabel7.getText(), tr));
        document.add(
                new Chunk("                                                      " + jTextField7.getText()));
        document.add(new Paragraph(
                "----------------------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph(jLabel8.getText(), tr));
        document.add(
                new Chunk("                                                      " + jTextField8.getText()));
        document.add(new Paragraph(
                "----------------------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph(jLabel9.getText(), tr));
        document.add(
                new Chunk("                                                      " + jTextField9.getText()));
        document.add(new Paragraph(
                "----------------------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph(jLabel10.getText(), tr));
        document.add(
                new Chunk("                                                      " + jTextField10.getText()));
        document.add(new Paragraph(
                "----------------------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph(jLabel11.getText(), tr));
        document.add(
                new Chunk("                                                      " + jTextField11.getText()));
        document.add(new Paragraph(
                "----------------------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph(jLabel12.getText(), tr));
        document.add(
                new Chunk("                                                      " + jTextField12.getText()));
        document.add(new Paragraph(
                "----------------------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph(jLabel13.getText(), tr));
        document.add(
                new Chunk("                                                      " + jTextField13.getText()));
        document.add(new Paragraph(
                "----------------------------------------------------------------------------------------------------------------------------------"));

        document.add(new Paragraph(
                "                                                                                                                                  "));
        document.add(new Paragraph(
                "                                                                                                                                  "));
        document.add(new Paragraph(
                "                                                                                                                                  "));
        document.add(new Paragraph(
                "                                                                                                                                  "));
        document.add(new Paragraph(
                "      Prepared by                                   Checked by                                       Approved by                  "));

        document.close();
        JOptionPane.showMessageDialog(null, "report generated successfully");
    } catch (DocumentException ex) {
        Logger.getLogger(CenteringAndEdgingView.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(CenteringAndEdgingView.class.getName()).log(Level.SEVERE, null, ex);
    }

}