Example usage for com.itextpdf.text Document newPage

List of usage examples for com.itextpdf.text Document newPage

Introduction

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

Prototype


public boolean newPage() 

Source Link

Document

Signals that an new page has to be started.

Usage

From source file:com.linksinnovation.elearning.utils.ppt2pdf.Ppt2Pdf.java

public static void convert(FileInputStream inputStream, FileOutputStream out)
        throws IOException, DocumentException {
    XMLSlideShow ppt = new XMLSlideShow(inputStream);
    inputStream.close();/*from   ww w  .j  a v  a  2 s  .c om*/
    Dimension pgsize = ppt.getPageSize();

    Document document = new Document();
    PdfWriter pdfWriter = PdfWriter.getInstance(document, out);
    document.setPageSize(new Rectangle((float) pgsize.getWidth(), (float) pgsize.getHeight()));
    document.open();
    for (XSLFSlide slide : ppt.getSlides()) {
        System.out.println(pgsize.getWidth() + " " + pgsize.getHeight());
        PdfGraphics2D graphics = (PdfGraphics2D) pdfWriter.getDirectContent()
                .createGraphics((float) pgsize.getWidth(), (float) pgsize.getHeight());
        slide.draw(graphics);
        graphics.dispose();
        document.newPage();
    }
    document.close();
}

From source file:com.microware.intrahealth.Createpdf2.java

private static void addTitlePage(Document document) throws DocumentException {

    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);//from  w w  w .j  a va2 s .  c  om
    // Lets write a big header
    preface.add(new Paragraph("Break Even Master Input", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Community profile", subFont));
    //      addEmptyLine(preface, 3);
    //      preface.add(new Paragraph("This document describes something which is very important ",
    //            smallBold));
    //
    //      addEmptyLine(preface, 8);
    //
    //      preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
    //            redFont));

    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:com.mim.controllers.HomeCtrl.java

private void ordenReport(Document document, Lugar lugar)
        throws BadElementException, DocumentException, IOException {
    document.addTitle(current.getNumeroOrden());
    // step 3//  w  w w. ja  v  a 2  s. c  o m

    // step 4
    PdfPTable table = new PdfPTable(8);

    //LEFT HEADER CONTENT
    PdfPTable leftHeaderTable = new PdfPTable(4);

    PdfPCell imgCell = new PdfPCell();
    imgCell.setBorder(Rectangle.NO_BORDER);
    imgCell.setPaddingTop(14);
    imgCell.setColspan(1);
    imgCell.setFixedHeight(25);

    //Image img = Image.getInstance("/opt/shared/home/logo.png");
    Image img = Image.getInstance("http://mimconstructions.com/img/mim%20trendy.png");

    imgCell.addElement(img);

    PdfPCell reportTitleCell = new PdfPCell(new Paragraph("REPORTE MANTENIMIENTO"));
    reportTitleCell.setPaddingTop(14);
    reportTitleCell.setPaddingLeft(20);
    reportTitleCell.setColspan(3);
    reportTitleCell.setBorder(Rectangle.NO_BORDER);

    leftHeaderTable.addCell(imgCell);
    leftHeaderTable.addCell(reportTitleCell);

    PdfPCell leftHeaderMainCell = new PdfPCell(leftHeaderTable);
    leftHeaderMainCell.setColspan(4);

    //END CONTENT
    //RIGHT HEADER WITH INFO ABOUT ORDER AND DATE
    PdfPTable infHeader = new PdfPTable(3);

    PdfPCell numberOrderLabel = new PdfPCell(new Paragraph("#ORDEN"));
    numberOrderLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderLabel.setColspan(1);
    String numeroOrden = null;
    if (current.getNumeroOrden() != null) {
        numeroOrden = current.getNumeroOrden();
    } else {
        numeroOrden = current.getActividad();
    }

    PdfPCell numberOrderValue = new PdfPCell(new Paragraph(numeroOrden));
    numberOrderValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderValue.setColspan(2);

    PdfPCell prioridadLabel = new PdfPCell(new Paragraph("PRIORIDAD"));
    prioridadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadLabel.setColspan(1);

    PdfPCell prioridadValue = new PdfPCell(new Paragraph(current.getPrioridad()));
    prioridadValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadValue.setColspan(2);

    PdfPCell fechaLabel = new PdfPCell(new Paragraph("FECHA"));
    fechaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaLabel.setColspan(1);
    //dd-MM-yyyy
    SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-yyyy");
    Date startDate = current.getStartDate();
    if (startDate == null) {
        startDate = new Date();
    }
    String fecha = format1.format(startDate);

    PdfPCell fechaValue = new PdfPCell(new Paragraph(fecha));
    fechaValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaValue.setColspan(2);

    infHeader.addCell(numberOrderLabel);
    infHeader.addCell(numberOrderValue);
    infHeader.addCell(prioridadLabel);
    infHeader.addCell(prioridadValue);
    infHeader.addCell(fechaLabel);
    infHeader.addCell(fechaValue);

    PdfPCell cellHeaderRight = new PdfPCell(infHeader);
    cellHeaderRight.setColspan(4);
    //END HEADER

    PdfPCell areaLabel = new PdfPCell(new Paragraph("AREA"));
    areaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    areaLabel.setFixedHeight(30);
    areaLabel.setPaddingTop(5);
    areaLabel.setColspan(2);

    PdfPCell actividadLabel = new PdfPCell(new Paragraph("ACTIVIDAD"));
    actividadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setFixedHeight(30);
    actividadLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setPaddingTop(5);
    actividadLabel.setColspan(3);

    PdfPCell responsableLabel = new PdfPCell(new Paragraph("RESPONSABLE DE OPERACION"));
    responsableLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setFixedHeight(30);
    responsableLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setPaddingTop(5);
    responsableLabel.setColspan(3);

    String area;
    if (lugar.getNombre().contains("linea")) {
        area = "envasado";
    } else if (lugar.getNombre().contains("otro")) {
        area = "Tecate 500";
    } else if (lugar.getNombre().contains("PD")) {
        area = "concretos";
    } else if (lugar.getNombre().contains("planta agua")) {
        area = "cerveceria";
    } else {
        area = "elaboracion";
    }

    PdfPCell areaValor = new PdfPCell(new Paragraph(area));
    areaValor.setFixedHeight(25);
    areaValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaValor.setColspan(2);

    PdfPCell actividadValor = new PdfPCell(new Paragraph(current.getActividad()));
    actividadValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadValor.setFixedHeight(25);
    actividadValor.setColspan(3);

    PdfPCell responsableValor = new PdfPCell(new Paragraph(current.getEncargado()));
    responsableValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableValor.setFixedHeight(25);
    responsableValor.setColspan(3);

    // 2 FILAS PARA INF. EQUIPO Y LUGAR
    PdfPCell equipoLabel = new PdfPCell(new Paragraph("EQUIPO/CONJUNTO"));
    equipoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setFixedHeight(30);
    equipoLabel.setPaddingTop(5);
    equipoLabel.setColspan(4);

    PdfPCell lugarLabel = new PdfPCell(new Paragraph("LUGAR"));
    lugarLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setFixedHeight(30);
    lugarLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setPaddingTop(5);
    lugarLabel.setColspan(4);

    String numeroEquipo = null;
    if (equipo.getNumeroEquipo() != null) {
        numeroEquipo = equipo.getNumeroEquipo();
    } else {
        numeroEquipo = "n/a";
    }

    PdfPCell equipoValor = new PdfPCell(new Paragraph(numeroEquipo));
    equipoValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoValor.setFixedHeight(25);
    equipoValor.setColspan(4);

    PdfPCell lugarValor = new PdfPCell(new Paragraph(lugar.getNombre()));
    lugarValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarValor.setFixedHeight(25);
    lugarValor.setColspan(4);

    //END INFO EQUIPO
    // 4 ROW and 5 ROW
    PdfPCell descripcionLabel = new PdfPCell(new Paragraph("DESCRIPCION"));
    descripcionLabel.setPadding(12);
    descripcionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    descripcionLabel.setColspan(8);

    PdfPCell descripcionValor = new PdfPCell(new Paragraph(current.getDescripcion()));
    descripcionValor.setPadding(10);
    descripcionValor.setColspan(8);
    //END ROWS

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell historialLabel = new PdfPCell(new Paragraph("OBSERVACIONES"));
    historialLabel.setPadding(12);
    historialLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    historialLabel.setColspan(8);
    //END HISTORIAL

    table.addCell(leftHeaderMainCell);
    table.addCell(cellHeaderRight);
    table.addCell(areaLabel);
    table.addCell(actividadLabel);
    table.addCell(responsableLabel);

    table.addCell(areaValor);
    table.addCell(actividadValor);
    table.addCell(responsableValor);
    table.addCell(equipoLabel);
    table.addCell(lugarLabel);
    table.addCell(equipoValor);
    table.addCell(lugarValor);
    table.addCell(descripcionLabel);
    table.addCell(descripcionValor);

    List<HistorialDetalles> observaciones = hisFacade.findAllByOrder(current.getIdorden());

    if (observaciones != null) {
        if (observaciones.size() > 0) {
            table.addCell(historialLabel);

            //LOOP HISTORIAL_DETALLES
            for (int i = 0; i < observaciones.size(); i++) {
                HistorialDetalles historial = observaciones.get(i);

                PdfPCell paramCell = new PdfPCell();
                paramCell.setColspan(3);
                paramCell.addElement(new Paragraph(historial.getParametro()));
                paramCell.setVerticalAlignment(Element.ALIGN_CENTER);
                paramCell.setPaddingLeft(10);
                paramCell.setPaddingBottom(10);

                PdfPCell valueParamCell = new PdfPCell();
                valueParamCell.setColspan(5);
                valueParamCell.setPaddingLeft(10);
                valueParamCell.setVerticalAlignment(Element.ALIGN_CENTER);
                valueParamCell.addElement(new Paragraph(historial.getValor()));
                valueParamCell.setPaddingBottom(10);

                if (historial.getValor() != null) {
                    if (historial.getValor().length() > 0) {
                        table.addCell(paramCell);
                        table.addCell(valueParamCell);
                    }
                }
            }
        }
    }
    //END LOOP HISTORIAL

    // FIRST ROWS OF FOTOGRAPHIC REPORT
    PdfPCell pasoLabel = new PdfPCell(new Paragraph("PASO"));
    pasoLabel.setFixedHeight(20);
    pasoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    pasoLabel.setColspan(1);

    PdfPCell accionLabel = new PdfPCell(new Paragraph("ACCION"));
    accionLabel.setFixedHeight(20);
    accionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    accionLabel.setColspan(3);

    PdfPCell imagenLabel = new PdfPCell(new Paragraph("IMAGENES"));
    imagenLabel.setFixedHeight(20);
    imagenLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    imagenLabel.setColspan(4);
    //END ROWS

    PdfPTable table2 = new PdfPTable(8);

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell headerPictures = new PdfPCell(new Paragraph("PROCEDIMIENTO"));
    headerPictures.setPadding(12);
    headerPictures.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerPictures.setColspan(8);

    table2.addCell(headerPictures);
    //END HISTORIAL

    table2.addCell(pasoLabel);
    table2.addCell(accionLabel);
    table2.addCell(imagenLabel);

    //fotos loop
    List<Fotos> fotos = fotoFacade.findAllByOrder(current.getIdorden());

    for (int i = 0; i < fotos.size(); i++) {
        Fotos foto = fotos.get(i);
        PdfPCell pasoVal = new PdfPCell(new Paragraph(String.valueOf(i)));
        pasoVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        pasoVal.setColspan(1);

        PdfPCell detail = new PdfPCell(new Paragraph(foto.getTitulo()));
        detail.setPadding(5);
        detail.setBorder(Rectangle.NO_BORDER);

        PdfPCell accionVal = new PdfPCell();
        accionVal.addElement(new Paragraph(foto.getDescripcion()));
        accionVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        accionVal.setBorder(Rectangle.NO_BORDER);
        //accionVal.setColspan(3);

        PdfPTable infoTable = new PdfPTable(1);
        infoTable.addCell(detail);
        infoTable.addCell(accionVal);

        PdfPCell infiCell = new PdfPCell();
        infiCell.setColspan(3);
        infiCell.addElement(infoTable);

        //Table collumn
        //System.getenv("OPENSHIFT_DATA_DIR") + "imagenes/" + name)
        //Image imgFoto = Image.getInstance("http://mantenimiento-contactres.rhcloud.com/MantenimientoRest/webresources/com.mim.entities.fotos/api/" + foto.getIdfotos());
        String archivo = foto.getArchivo();
        String[] split = archivo.split("/");
        int size = split.length;
        final String name = split[size - 1];
        System.out.println("Valor " + name);

        Image imgFoto = Image.getInstance("/opt/shared/home/" + "imagenes/" + name);

        PdfPTable imagenTable = new PdfPTable(1);

        PdfPCell fotoCell = new PdfPCell();
        fotoCell.setColspan(1);
        fotoCell.addElement(imgFoto);
        fotoCell.setFixedHeight(310);
        fotoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        fotoCell.setBorder(Rectangle.NO_BORDER);

        imagenTable.addCell(fotoCell);

        PdfPCell imagenVal = new PdfPCell();
        imagenVal.setColspan(4);
        imagenVal.addElement(imagenTable);

        table2.addCell(pasoVal);
        table2.addCell(infiCell);
        table2.addCell(imagenVal);
    }
    //end loop

    //table.addCell(tiempoLabel);
    document.add(table);
    document.newPage();
    document.add(table2);
}

From source file:com.mim.controllers.OrdenCtrl.java

private void ordenReport(Document document, Lugar lugar)
        throws BadElementException, DocumentException, IOException {
    document.addTitle(current.getNumeroOrden());
    // step 3/* w  ww  .  j a  va 2 s .  co m*/

    // step 4
    PdfPTable table = new PdfPTable(8);

    //LEFT HEADER CONTENT
    PdfPTable leftHeaderTable = new PdfPTable(4);

    PdfPCell imgCell = new PdfPCell();
    imgCell.setBorder(Rectangle.NO_BORDER);
    imgCell.setPaddingTop(14);
    imgCell.setColspan(1);
    imgCell.setFixedHeight(25);

    //Image img = Image.getInstance("/opt/shared/home/logo.png");
    Image img = Image.getInstance("http://mimconstructions.com/img/mim%20trendy.png");

    imgCell.addElement(img);

    PdfPCell reportTitleCell = new PdfPCell(new Paragraph("REPORTE MANTENIMIENTO"));
    reportTitleCell.setPaddingTop(14);
    reportTitleCell.setPaddingLeft(20);
    reportTitleCell.setColspan(3);
    reportTitleCell.setBorder(Rectangle.NO_BORDER);

    leftHeaderTable.addCell(imgCell);
    leftHeaderTable.addCell(reportTitleCell);

    PdfPCell leftHeaderMainCell = new PdfPCell(leftHeaderTable);
    leftHeaderMainCell.setColspan(4);

    //END CONTENT
    //RIGHT HEADER WITH INFO ABOUT ORDER AND DATE
    PdfPTable infHeader = new PdfPTable(3);

    PdfPCell numberOrderLabel = new PdfPCell(new Paragraph("#ORDEN"));
    numberOrderLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderLabel.setColspan(1);
    String numeroOrden = null;
    if (current.getNumeroOrden() != null) {
        numeroOrden = current.getNumeroOrden();
    } else {
        numeroOrden = current.getActividad();
    }

    PdfPCell numberOrderValue = new PdfPCell(new Paragraph(numeroOrden));
    numberOrderValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderValue.setColspan(2);

    PdfPCell prioridadLabel = new PdfPCell(new Paragraph("PRIORIDAD"));
    prioridadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadLabel.setColspan(1);

    PdfPCell prioridadValue = new PdfPCell(new Paragraph(current.getPrioridad()));
    prioridadValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadValue.setColspan(2);

    PdfPCell fechaLabel = new PdfPCell(new Paragraph("FECHA"));
    fechaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaLabel.setColspan(1);
    //dd-MM-yyyy
    SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-yyyy");
    Date startDate = current.getStartDate();
    if (startDate == null) {
        startDate = new Date();
    }
    String fecha = format1.format(startDate);

    PdfPCell fechaValue = new PdfPCell(new Paragraph(fecha));
    fechaValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaValue.setColspan(2);

    infHeader.addCell(numberOrderLabel);
    infHeader.addCell(numberOrderValue);
    infHeader.addCell(prioridadLabel);
    infHeader.addCell(prioridadValue);
    infHeader.addCell(fechaLabel);
    infHeader.addCell(fechaValue);

    PdfPCell cellHeaderRight = new PdfPCell(infHeader);
    cellHeaderRight.setColspan(4);
    //END HEADER

    PdfPCell areaLabel = new PdfPCell(new Paragraph("AREA"));
    areaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    areaLabel.setFixedHeight(30);
    areaLabel.setPaddingTop(5);
    areaLabel.setColspan(2);

    PdfPCell actividadLabel = new PdfPCell(new Paragraph("ACTIVIDAD"));
    actividadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setFixedHeight(30);
    actividadLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setPaddingTop(5);
    actividadLabel.setColspan(3);

    PdfPCell responsableLabel = new PdfPCell(new Paragraph("RESPONSABLE DE OPERACION"));
    responsableLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setFixedHeight(30);
    responsableLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setPaddingTop(5);
    responsableLabel.setColspan(3);

    PdfPCell areaValor = new PdfPCell(new Paragraph("concretera"));
    areaValor.setFixedHeight(25);
    areaValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaValor.setColspan(2);

    PdfPCell actividadValor = new PdfPCell(new Paragraph(current.getActividad()));
    actividadValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadValor.setFixedHeight(25);
    actividadValor.setColspan(3);

    PdfPCell responsableValor = new PdfPCell(new Paragraph(current.getEncargado()));
    responsableValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableValor.setFixedHeight(25);
    responsableValor.setColspan(3);

    // 2 FILAS PARA INF. EQUIPO Y LUGAR
    PdfPCell equipoLabel = new PdfPCell(new Paragraph("EQUIPO/CONJUNTO"));
    equipoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setFixedHeight(30);
    equipoLabel.setPaddingTop(5);
    equipoLabel.setColspan(4);

    PdfPCell lugarLabel = new PdfPCell(new Paragraph("LUGAR"));
    lugarLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setFixedHeight(30);
    lugarLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setPaddingTop(5);
    lugarLabel.setColspan(4);

    String numeroEquipo = null;
    if (equipo.getNumeroEquipo() != null) {
        numeroEquipo = equipo.getNumeroEquipo();
    } else {
        numeroEquipo = "n/a";
    }

    PdfPCell equipoValor = new PdfPCell(new Paragraph(numeroEquipo));
    equipoValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoValor.setFixedHeight(25);
    equipoValor.setColspan(4);

    PdfPCell lugarValor = new PdfPCell(new Paragraph(lugar.getNombre()));
    lugarValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarValor.setFixedHeight(25);
    lugarValor.setColspan(4);

    //END INFO EQUIPO
    // 4 ROW and 5 ROW
    PdfPCell descripcionLabel = new PdfPCell(new Paragraph("DESCRIPCION"));
    descripcionLabel.setPadding(12);
    descripcionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    descripcionLabel.setColspan(8);

    PdfPCell descripcionValor = new PdfPCell(new Paragraph(current.getDescripcion()));
    descripcionValor.setPadding(10);
    descripcionValor.setColspan(8);
    //END ROWS

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell historialLabel = new PdfPCell(new Paragraph("OBSERVACIONES"));
    historialLabel.setPadding(12);
    historialLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    historialLabel.setColspan(8);
    //END HISTORIAL

    table.addCell(leftHeaderMainCell);
    table.addCell(cellHeaderRight);
    table.addCell(areaLabel);
    table.addCell(actividadLabel);
    table.addCell(responsableLabel);

    table.addCell(areaValor);
    table.addCell(actividadValor);
    table.addCell(responsableValor);
    table.addCell(equipoLabel);
    table.addCell(lugarLabel);
    table.addCell(equipoValor);
    table.addCell(lugarValor);
    table.addCell(descripcionLabel);
    table.addCell(descripcionValor);

    List<HistorialDetalles> observaciones = hisFacade.findAllByOrder(current.getIdorden());

    if (observaciones != null) {
        if (observaciones.size() > 0) {
            table.addCell(historialLabel);

            //LOOP HISTORIAL_DETALLES
            for (int i = 0; i < observaciones.size(); i++) {
                HistorialDetalles historial = observaciones.get(i);

                PdfPCell paramCell = new PdfPCell();
                paramCell.setColspan(3);
                paramCell.addElement(new Paragraph(historial.getParametro()));
                paramCell.setVerticalAlignment(Element.ALIGN_CENTER);
                paramCell.setPaddingLeft(10);
                paramCell.setPaddingBottom(10);

                PdfPCell valueParamCell = new PdfPCell();
                valueParamCell.setColspan(5);
                valueParamCell.setPaddingLeft(10);
                valueParamCell.setVerticalAlignment(Element.ALIGN_CENTER);
                valueParamCell.addElement(new Paragraph(historial.getValor()));
                valueParamCell.setPaddingBottom(10);

                table.addCell(paramCell);
                table.addCell(valueParamCell);
            }
        }
    }
    //END LOOP HISTORIAL

    // FIRST ROWS OF FOTOGRAPHIC REPORT
    PdfPCell pasoLabel = new PdfPCell(new Paragraph("PASO"));
    pasoLabel.setFixedHeight(20);
    pasoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    pasoLabel.setColspan(1);

    PdfPCell accionLabel = new PdfPCell(new Paragraph("ACCION"));
    accionLabel.setFixedHeight(20);
    accionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    accionLabel.setColspan(3);

    PdfPCell imagenLabel = new PdfPCell(new Paragraph("IMAGENES"));
    imagenLabel.setFixedHeight(20);
    imagenLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    imagenLabel.setColspan(4);
    //END ROWS

    PdfPTable table2 = new PdfPTable(8);

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell headerPictures = new PdfPCell(new Paragraph("PROCEDIMIENTO"));
    headerPictures.setPadding(12);
    headerPictures.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerPictures.setColspan(8);

    table2.addCell(headerPictures);
    //END HISTORIAL

    table2.addCell(pasoLabel);
    table2.addCell(accionLabel);
    table2.addCell(imagenLabel);

    //fotos loop
    List<Fotos> fotos = fotoFacade.findAllByOrder(current.getIdorden());

    for (int i = 0; i < fotos.size(); i++) {
        Fotos foto = fotos.get(i);
        PdfPCell pasoVal = new PdfPCell(new Paragraph(String.valueOf(i)));
        pasoVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        pasoVal.setColspan(1);

        PdfPCell detail = new PdfPCell(new Paragraph(foto.getTitulo()));
        detail.setPadding(5);
        detail.setBorder(Rectangle.NO_BORDER);

        PdfPCell accionVal = new PdfPCell();
        accionVal.addElement(new Paragraph(foto.getDescripcion()));
        accionVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        accionVal.setBorder(Rectangle.NO_BORDER);
        //accionVal.setColspan(3);

        PdfPTable infoTable = new PdfPTable(1);
        infoTable.addCell(detail);
        infoTable.addCell(accionVal);

        PdfPCell infiCell = new PdfPCell();
        infiCell.setColspan(3);
        infiCell.addElement(infoTable);

        //Table collumn
        //System.getenv("OPENSHIFT_DATA_DIR") + "imagenes/" + name)
        //Image imgFoto = Image.getInstance("http://mantenimiento-contactres.rhcloud.com/MantenimientoRest/webresources/com.mim.entities.fotos/api/" + foto.getIdfotos());
        String archivo = foto.getArchivo();
        String[] split = archivo.split("/");
        int size = split.length;
        final String name = split[size - 1];
        System.out.println("Valor " + name);

        Image imgFoto = Image.getInstance("/opt/shared/home/" + "imagenes/" + name);

        PdfPTable imagenTable = new PdfPTable(1);

        PdfPCell fotoCell = new PdfPCell();
        fotoCell.setColspan(1);
        fotoCell.addElement(imgFoto);
        fotoCell.setFixedHeight(310);
        fotoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        fotoCell.setBorder(Rectangle.NO_BORDER);

        imagenTable.addCell(fotoCell);

        PdfPCell imagenVal = new PdfPCell();
        imagenVal.setColspan(4);
        imagenVal.addElement(imagenTable);

        table2.addCell(pasoVal);
        table2.addCell(infiCell);
        table2.addCell(imagenVal);
    }
    //end loop

    //table.addCell(tiempoLabel);
    document.add(table);
    document.newPage();
    document.add(table2);
}

From source file:com.mim.servlet.ReportGen.java

private void ordenReport(Document document, Lugar lugar)
        throws BadElementException, DocumentException, IOException {
    document.addTitle(current.getNumeroOrden());
    // step 3/*  w w w. j  a v  a2s .c o  m*/

    // step 4
    PdfPTable table = new PdfPTable(8);

    //LEFT HEADER CONTENT
    PdfPTable leftHeaderTable = new PdfPTable(4);

    PdfPCell imgCell = new PdfPCell();
    imgCell.setBorder(Rectangle.NO_BORDER);
    imgCell.setPaddingTop(14);
    imgCell.setColspan(1);
    imgCell.setFixedHeight(25);

    //Image img = Image.getInstance("/opt/shared/home/logo.png");
    Image img = Image.getInstance("http://mimconstructions.com/img/mim%20trendy.png");

    imgCell.addElement(img);

    PdfPCell reportTitleCell = new PdfPCell(new Paragraph("REPORTE MANTENIMIENTO"));
    reportTitleCell.setPaddingTop(14);
    reportTitleCell.setPaddingLeft(20);
    reportTitleCell.setColspan(3);
    reportTitleCell.setBorder(Rectangle.NO_BORDER);

    leftHeaderTable.addCell(imgCell);
    leftHeaderTable.addCell(reportTitleCell);

    PdfPCell leftHeaderMainCell = new PdfPCell(leftHeaderTable);
    leftHeaderMainCell.setColspan(4);

    //END CONTENT
    //RIGHT HEADER WITH INFO ABOUT ORDER AND DATE
    PdfPTable infHeader = new PdfPTable(3);

    PdfPCell numberOrderLabel = new PdfPCell(new Paragraph("#ORDEN"));
    numberOrderLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderLabel.setColspan(1);
    String numeroOrden = null;
    if (current.getNumeroOrden() != null) {
        numeroOrden = current.getNumeroOrden();
    } else {
        numeroOrden = current.getActividad();
    }

    PdfPCell numberOrderValue = new PdfPCell(new Paragraph(numeroOrden));
    numberOrderValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderValue.setColspan(2);

    PdfPCell prioridadLabel = new PdfPCell(new Paragraph("PRIORIDAD"));
    prioridadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadLabel.setColspan(1);

    PdfPCell prioridadValue = new PdfPCell(new Paragraph(current.getPrioridad()));
    prioridadValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadValue.setColspan(2);

    PdfPCell fechaLabel = new PdfPCell(new Paragraph("FECHA"));
    fechaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaLabel.setColspan(1);
    //dd-MM-yyyy
    SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-yyyy");
    Date startDate = current.getStartDate();
    if (startDate == null) {
        startDate = new Date();
    }
    String fecha = format1.format(startDate);

    PdfPCell fechaValue = new PdfPCell(new Paragraph(fecha));
    fechaValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaValue.setColspan(2);

    infHeader.addCell(numberOrderLabel);
    infHeader.addCell(numberOrderValue);
    infHeader.addCell(prioridadLabel);
    infHeader.addCell(prioridadValue);
    infHeader.addCell(fechaLabel);
    infHeader.addCell(fechaValue);

    PdfPCell cellHeaderRight = new PdfPCell(infHeader);
    cellHeaderRight.setColspan(4);
    //END HEADER

    PdfPCell areaLabel = new PdfPCell(new Paragraph("AREA"));
    areaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    areaLabel.setFixedHeight(30);
    areaLabel.setPaddingTop(5);
    areaLabel.setColspan(2);

    PdfPCell actividadLabel = new PdfPCell(new Paragraph("ACTIVIDAD"));
    actividadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setFixedHeight(30);
    actividadLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setPaddingTop(5);
    actividadLabel.setColspan(3);

    PdfPCell responsableLabel = new PdfPCell(new Paragraph("RESPONSABLE DE OPERACION"));
    responsableLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setFixedHeight(30);
    responsableLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setPaddingTop(5);
    responsableLabel.setColspan(3);

    PdfPCell areaValor = new PdfPCell(new Paragraph("concretera"));
    areaValor.setFixedHeight(25);
    areaValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaValor.setColspan(2);

    PdfPCell actividadValor = new PdfPCell(new Paragraph(current.getActividad()));
    actividadValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadValor.setFixedHeight(25);
    actividadValor.setColspan(3);

    PdfPCell responsableValor = new PdfPCell(new Paragraph(current.getEncargado()));
    responsableValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableValor.setFixedHeight(25);
    responsableValor.setColspan(3);

    // 2 FILAS PARA INF. EQUIPO Y LUGAR
    PdfPCell equipoLabel = new PdfPCell(new Paragraph("EQUIPO/CONJUNTO"));
    equipoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setFixedHeight(30);
    equipoLabel.setPaddingTop(5);
    equipoLabel.setColspan(4);

    PdfPCell lugarLabel = new PdfPCell(new Paragraph("LUGAR"));
    lugarLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setFixedHeight(30);
    lugarLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setPaddingTop(5);
    lugarLabel.setColspan(4);

    String numeroEquipo = null;
    if (equipo.getNumeroEquipo() != null) {
        numeroEquipo = equipo.getNumeroEquipo();
    } else {
        numeroEquipo = "n/a";
    }

    PdfPCell equipoValor = new PdfPCell(new Paragraph(numeroEquipo));
    equipoValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoValor.setFixedHeight(25);
    equipoValor.setColspan(4);

    PdfPCell lugarValor = new PdfPCell(new Paragraph(lugar.getNombre()));
    lugarValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarValor.setFixedHeight(25);
    lugarValor.setColspan(4);

    //END INFO EQUIPO
    // 4 ROW and 5 ROW
    PdfPCell descripcionLabel = new PdfPCell(new Paragraph("DESCRIPCION"));
    descripcionLabel.setPadding(12);
    descripcionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    descripcionLabel.setColspan(8);

    PdfPCell descripcionValor = new PdfPCell(new Paragraph(current.getDescripcion()));
    descripcionValor.setPadding(10);
    descripcionValor.setColspan(8);
    //END ROWS

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell historialLabel = new PdfPCell(new Paragraph("OBSERVACIONES"));
    historialLabel.setPadding(12);
    historialLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    historialLabel.setColspan(8);
    //END HISTORIAL

    table.addCell(leftHeaderMainCell);
    table.addCell(cellHeaderRight);
    table.addCell(areaLabel);
    table.addCell(actividadLabel);
    table.addCell(responsableLabel);

    table.addCell(areaValor);
    table.addCell(actividadValor);
    table.addCell(responsableValor);
    table.addCell(equipoLabel);
    table.addCell(lugarLabel);
    table.addCell(equipoValor);
    table.addCell(lugarValor);
    table.addCell(descripcionLabel);
    table.addCell(descripcionValor);

    List<HistorialDetalles> observaciones = hisFacade.findAllByOrder(current.getIdorden());

    if (observaciones != null) {
        if (observaciones.size() > 0) {
            table.addCell(historialLabel);

            //LOOP HISTORIAL_DETALLES
            for (int i = 0; i < observaciones.size(); i++) {
                HistorialDetalles historial = observaciones.get(i);

                if (historial.getValor() != null) {
                    if (historial.getValor().length() > 0) {
                        PdfPCell paramCell = new PdfPCell();
                        paramCell.setColspan(3);
                        paramCell.addElement(new Paragraph(historial.getParametro()));
                        paramCell.setVerticalAlignment(Element.ALIGN_CENTER);
                        paramCell.setPaddingLeft(10);
                        paramCell.setPaddingBottom(10);

                        PdfPCell valueParamCell = new PdfPCell();
                        valueParamCell.setColspan(5);
                        valueParamCell.setPaddingLeft(10);
                        valueParamCell.setVerticalAlignment(Element.ALIGN_CENTER);
                        valueParamCell.addElement(new Paragraph(historial.getValor()));
                        valueParamCell.setPaddingBottom(10);

                        table.addCell(paramCell);
                        table.addCell(valueParamCell);
                    }
                }
            }
        }
    }
    //END LOOP HISTORIAL

    // FIRST ROWS OF FOTOGRAPHIC REPORT
    PdfPCell pasoLabel = new PdfPCell(new Paragraph("PASO"));
    pasoLabel.setFixedHeight(20);
    pasoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    pasoLabel.setColspan(1);

    PdfPCell accionLabel = new PdfPCell(new Paragraph("ACCION"));
    accionLabel.setFixedHeight(20);
    accionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    accionLabel.setColspan(3);

    PdfPCell imagenLabel = new PdfPCell(new Paragraph("IMAGENES"));
    imagenLabel.setFixedHeight(20);
    imagenLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    imagenLabel.setColspan(4);
    //END ROWS

    PdfPTable table2 = new PdfPTable(8);

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell headerPictures = new PdfPCell(new Paragraph("PROCEDIMIENTO"));
    headerPictures.setPadding(12);
    headerPictures.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerPictures.setColspan(8);

    table2.addCell(headerPictures);
    //END HISTORIAL

    table2.addCell(pasoLabel);
    table2.addCell(accionLabel);
    table2.addCell(imagenLabel);

    //fotos loop
    List<Fotos> fotos = fotoFacade.findAllByOrder(current.getIdorden());

    for (int i = 0; i < fotos.size(); i++) {
        Fotos foto = fotos.get(i);
        PdfPCell pasoVal = new PdfPCell(new Paragraph(String.valueOf(i)));
        pasoVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        pasoVal.setColspan(1);

        PdfPCell detail = new PdfPCell(new Paragraph(foto.getTitulo()));
        detail.setPadding(5);
        detail.setBorder(Rectangle.NO_BORDER);

        PdfPCell accionVal = new PdfPCell();
        accionVal.addElement(new Paragraph(foto.getDescripcion()));
        accionVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        accionVal.setBorder(Rectangle.NO_BORDER);
        //accionVal.setColspan(3);

        PdfPTable infoTable = new PdfPTable(1);
        infoTable.addCell(detail);
        infoTable.addCell(accionVal);

        PdfPCell infiCell = new PdfPCell();
        infiCell.setColspan(3);
        infiCell.addElement(infoTable);

        //Table collumn
        //System.getenv("OPENSHIFT_DATA_DIR") + "imagenes/" + name)
        //Image imgFoto = Image.getInstance("http://mantenimiento-contactres.rhcloud.com/MantenimientoRest/webresources/com.mim.entities.fotos/api/" + foto.getIdfotos());
        String archivo = foto.getArchivo();
        String[] split = archivo.split("/");
        int size = split.length;
        final String name = split[size - 1];
        System.out.println("Valor " + name);

        Image imgFoto = Image.getInstance("/opt/shared/home/" + "imagenes/" + name);

        PdfPTable imagenTable = new PdfPTable(1);

        PdfPCell fotoCell = new PdfPCell();
        fotoCell.setColspan(1);
        fotoCell.addElement(imgFoto);
        fotoCell.setFixedHeight(310);
        fotoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        fotoCell.setBorder(Rectangle.NO_BORDER);

        imagenTable.addCell(fotoCell);

        PdfPCell imagenVal = new PdfPCell();
        imagenVal.setColspan(4);
        imagenVal.addElement(imagenTable);

        table2.addCell(pasoVal);
        table2.addCell(infiCell);
        table2.addCell(imagenVal);
    }
    //end loop

    //table.addCell(tiempoLabel);
    document.add(table);
    document.newPage();
    document.add(table2);
}

From source file:com.miraflorescarwash.controller.PdfController.java

private void crearPdfCombosReporte(Document doc, List<ComboReporte> combos, PdfWriter writer) {
    Paragraph parrafo;//from   w w w.j  av  a 2s. com
    PdfPTable tabla;
    String txt;
    PdfPCell cell;
    Phrase frase;
    String fuente;
    int i;
    JFreeChart chart;
    int w, h;
    int pos;
    pos = 0;
    w = h = 500;

    fuente = "arial";
    if (combos.isEmpty()) {
        return;
    }
    try {
        //

        // Se abre el documento.
        doc.open();

        txt = "Miraflores Car Wash";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 10, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);

        txt = "Reporte de Combos";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 30, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_CENTER);

        doc.add(parrafo);
        LineSeparator ls = new LineSeparator();
        doc.add(new Chunk(ls));

        tabla = new PdfPTable(3);

        frase = new Phrase("Id", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Nombre", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Dinero Recaudado", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        i = 1;

        for (ComboReporte combo : combos) {

            if (i % 2 == 0) {
                cell = new PdfPCell();
                cell.setBackgroundColor(new BaseColor(244, 119, 119));

                frase = new Phrase(combo.getId() + "");
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(combo.getNombre());
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase("S/. " + combo.getCantidad() + "0");
                cell.setPhrase(frase);
                tabla.addCell(cell);

            } else {
                tabla.addCell(combo.getId() + "");
                tabla.addCell(combo.getNombre());
                tabla.addCell("S/. " + combo.getCantidad() + "0");
            }
            i++;
        }
        doc.add(tabla);
        doc.newPage();
        txt = "Miraflores Car Wash";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 10, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);

        chart = comboService.generarChartReporte(combos);

        w = 500;
        h = 500;

        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate tp = cb.createTemplate(w, h);
        Graphics2D g2d = tp.createGraphics(w, h, new DefaultFontMapper());
        Rectangle2D r2d = new Rectangle2D.Double(0, 0, w, h);
        chart.draw(g2d, r2d);
        cb.addTemplate(tp, 50, 250);
        g2d.dispose();
        doc.close();
    } catch (DocumentException ex) {

    }
}

From source file:com.miraflorescarwash.controller.PdfController.java

private void crearPdfClientesFreq(Document doc, List<ClienteReporte> reporteCompras, PdfWriter writer) {
    Paragraph parrafo;/*from   ww  w. j ava2  s  .  c  o  m*/
    PdfPTable tabla;
    String txt;
    PdfPCell cell;
    Phrase frase;
    String fuente;
    JFreeChart chart;
    int i, w, h;

    fuente = "arial";
    if (reporteCompras.isEmpty()) {
        return;
    }
    try {
        //

        // Se abre el documento.
        doc.open();

        txt = "Miraflores Car Wash";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 10, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);

        txt = "Clientes Frecuentes";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 30, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_CENTER);

        doc.add(parrafo);
        LineSeparator ls = new LineSeparator();
        doc.add(new Chunk(ls));

        doc.add(Chunk.NEWLINE);

        tabla = new PdfPTable(3);

        frase = new Phrase("Id", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Nombre", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Dinero", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        i = 1;

        for (ClienteReporte clienteReporte : reporteCompras) {

            if (i % 2 == 0) {
                cell = new PdfPCell();
                cell.setBackgroundColor(new BaseColor(244, 119, 119));

                frase = new Phrase(clienteReporte.getId() + "");
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(clienteReporte.getApellido() + " " + clienteReporte.getNombre());
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase("S/. " + clienteReporte.getTotal() + "0");
                cell.setPhrase(frase);
                tabla.addCell(cell);

            } else {
                tabla.addCell(clienteReporte.getId() + "");
                tabla.addCell(clienteReporte.getApellido() + " " + clienteReporte.getNombre());
                tabla.addCell("S/. " + clienteReporte.getTotal() + "0");
            }
            i++;
        }
        doc.add(tabla);

        doc.newPage();
        txt = "Miraflores Car Wash";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 10, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);

        chart = clienteService.generarChartReporte(reporteCompras);

        w = 500;
        h = 500;

        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate tp = cb.createTemplate(w, h);
        Graphics2D g2d = tp.createGraphics(w, h, new DefaultFontMapper());
        Rectangle2D r2d = new Rectangle2D.Double(0, 0, w, h);
        chart.draw(g2d, r2d);
        cb.addTemplate(tp, 50, 250);
        g2d.dispose();
        doc.close();
    } catch (DocumentException ex) {

    }
}

From source file:com.mobicage.rogerthat.enterprise.samples.hr.bizz.GenerateExpenseNote.java

License:Open Source License

public int handle(final User user, final User manager, final ExpenseNote en)
        throws MalformedURLException, IOException, DocumentException {

    log.info("Building list of expenses ...");
    List<Expense> expenses = Expense.list(en);
    log.info("Retrieved " + expenses.size() + " expenses from the datastore");

    log.info("Creating ExpenseNoteDocOutputStream");
    ExpenseNoteDocOutputStream stream = new ExpenseNoteDocOutputStream(en);

    Document document = new Document();
    PdfWriter.getInstance(document, stream);
    document.open();//from   w  ww.j av  a2  s.c  om

    document.addTitle("Expense note " + en.id + " of " + user.name);
    document.addSubject("Expense note generated by Rogerthat Enterprise!");
    document.addKeywords("expense note");
    document.addAuthor(user.name);
    document.addCreator("Rogerthat OneApp Enterprise Mobility");

    Paragraph preface = new Paragraph();

    preface.add(new Paragraph("TP Vision expense note", titleFont));
    preface.add(new Paragraph(" "));

    DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
    Date date = new Date();
    preface.add(new Paragraph("Date: " + dateFormat.format(date)));
    preface.add(new Paragraph("Requestor: " + user.name));
    preface.add(new Paragraph("Approver: " + manager.name));
    preface.add(new Paragraph(" "));

    PdfPTable table = new PdfPTable(7);
    table.setWidthPercentage(110);
    table.setWidths(new int[] { 5, 15, 15, 35, 10, 15, 10 });
    addHeader(table, "Id");
    addHeader(table, "Date");
    addHeader(table, "Nature");
    addHeader(table, "Description");
    addHeader(table, "Account");
    addHeader(table, "Amount");
    addHeader(table, "Voucher");
    table.setHeaderRows(1);

    Collections.sort(expenses, new Comparator<Expense>() {
        @Override
        public int compare(Expense e1, Expense e2) {
            return (int) (e1.date - e2.date);
        }
    });
    int i = 0;
    double total = 0;
    for (Expense expense : expenses) {
        PdfPCell c1 = new PdfPCell(new Phrase("" + ++i));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
        table.addCell(dateFormat.format(new Date(expense.date * 1000)));
        table.addCell(expense.nature);
        table.addCell(expense.description);
        table.addCell("" + expense.account);
        c1 = new PdfPCell(new Phrase(DECIMAL_FORMAT.format(expense.amount) + " " + expense.currency));
        c1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(c1);
        table.addCell(expense.voucher);
        total += expense.amount;
    }

    preface.add(table);

    preface.add(new Paragraph(" "));
    preface.add(new Paragraph("Total: " + DECIMAL_FORMAT.format(total), titleFont));

    document.add(preface);

    i = 0;
    for (Expense expense : expenses) {
        i++;
        if (expense.receipt == null)
            continue;

        document.newPage();
        Paragraph receipt = new Paragraph();
        receipt.add(new Paragraph("Attachment " + i, titleFont));
        document.add(receipt);
        Image image = Image.getInstance(new URL(expense.receipt));
        image.setRotationDegrees(-90);
        float scaler = (document.getPageSize().getWidth() / image.getWidth()) * 100;

        image.scalePercent(scaler);
        document.add(image);
    }

    document.close();
    stream.close();

    return stream.getSize();

}

From source file:com.mycompany.mavenproject1.Createpdf.java

public void createPDF(String pdfFilename) {

    Document doc = new Document();
    PdfWriter docWriter = null;//from   ww  w . j  a  v a  2 s .com
    initializeFonts();

    try {
        String path = "C:\\Users\\Thaskioglu\\Downloads\\" + pdfFilename;
        docWriter = PdfWriter.getInstance(doc, new FileOutputStream(path));
        doc.addAuthor("FabulousCar");
        doc.addCreationDate();
        doc.addProducer();
        doc.addCreator("FabulousCar");
        doc.addTitle("Invoice");
        doc.setPageSize(PageSize.LETTER);

        doc.open();
        PdfContentByte cb = docWriter.getDirectContent();

        boolean beginPage = true;
        int y = 0;

        for (int i = 0; i < 100; i++) {
            if (beginPage) {
                beginPage = false;
                generateLayout(doc, cb);
                generateHeader(doc, cb);
                y = 615;
            }
            generateDetail(doc, cb, i, y);
            y = y - 15;
            if (y < 50) {
                printPageNumber(cb);
                doc.newPage();
                beginPage = true;
            }
        }
        printPageNumber(cb);

    } catch (DocumentException dex) {
        dex.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        if (doc != null) {
            doc.close();
        }
        if (docWriter != null) {
            docWriter.close();
        }
    }
}

From source file:com.norbsoft.pdfconverter.helpers.PDFHelper.java

License:Open Source License

public int generate(String saveUrl, SerializableBitmap sign, Form form, ArrayList<String> photos,
        ArrayList<String> workers) {
    try {//w  w  w.  java  2s . c o m
        Document document = new Document();

        url = saveUrl;
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(url));
        document.setMargins(20, 20, 20, 20);
        document.open();

        Bitmap inputLogo = BitmapFactory.decodeStream(context.getAssets().open("logo.jpg"));
        ByteArrayOutputStream outstream = new ByteArrayOutputStream();
        inputLogo.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
        Image logo = Image.getInstance(outstream.toByteArray());

        Bitmap inputQR = BitmapFactory.decodeStream(context.getAssets().open("qr.jpg"));
        outstream = new ByteArrayOutputStream();
        inputQR.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
        Image qr = Image.getInstance(outstream.toByteArray());

        outstream = new ByteArrayOutputStream();
        sign.getImage().compress(Bitmap.CompressFormat.JPEG, 100, outstream);
        Image sgn = Image.getInstance(outstream.toByteArray());

        qr.scaleAbsolute(90f, 90f);
        qr.setAbsolutePosition(340f, 705f);

        logo.scaleAbsolute(150f, 50f);
        logo.setAbsolutePosition(50f, 750f);

        sgn.scaleAbsolute(130f, 30f);
        sgn.setAbsolutePosition(25f, 75f);

        Paragraph p = new Paragraph("\r\n\r\n\r\nMPWiK S.A.\r\n50-421 Wrocaw\r\nul.Na Grobli 14-16", normal);
        p.setIndentationLeft(420f);
        document.add(p);

        p = new Paragraph("RAPORT WYMIANY WODOMIERZA", bold);
        p.setAlignment(Element.ALIGN_CENTER);
        p.setSpacingBefore(60f);
        document.add(p);

        document.add(table(form));

        p = new Paragraph(form.getInformations(), normal);
        p.setAlignment(Element.ALIGN_LEFT);
        p.setIndentationLeft(50f);
        p.setSpacingBefore(20f);
        document.add(p);

        document.add(signTable(form, sgn, workers));

        document.add(logo);
        document.add(qr);

        if (photos != null && photos.size() > 0) {
            document.newPage();
            for (int i = 0; i < photos.size(); i++) {
                try {
                    if (photos.get(i) != null && !photos.get(i).equals("")) {
                        Log.d(TAG, photos.get(i));
                        Bitmap temp = PictureHelper.bitmapFromUrl(photos.get(i));
                        outstream = new ByteArrayOutputStream();
                        temp.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
                        Image photo = Image.getInstance(outstream.toByteArray());
                        photo.scaleToFit(document.getPageSize().getWidth() - 50,
                                document.getPageSize().getHeight());
                        document.add(photo);
                    }
                } catch (Exception e) {

                }
            }
        }
        document.close();
        writer.close();
        return 1;
    } catch (FileNotFoundException e) {
        Log.e(TAG, e.getMessage());
        return 0;
    } catch (DocumentException e) {
        Log.e(TAG, e.getMessage());
        return 0;
    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
        return 0;
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
        return 0;
    }
}