Example usage for com.lowagie.text.pdf PdfWriter setPageEvent

List of usage examples for com.lowagie.text.pdf PdfWriter setPageEvent

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfWriter setPageEvent.

Prototype


public void setPageEvent(PdfPageEvent event) 

Source Link

Document

Sets the PdfPageEvent for this document.

Usage

From source file:domain.reports.menu.PDFReportMenu.java

License:LGPL

@Override
protected void createPDF(GenericTransaction data, ByteArrayOutputStream buf) throws Throwable {

    //inicializar documento: tamano de pagina, orientacion, margenes
    Document doc = new Document();
    PdfWriter docWriter = PdfWriter.getInstance(doc, buf);
    doc.setPageSize(PageSize.LETTER.rotate());
    doc.setMargins(30, 30, 30, 40);/*  w  w  w . j  av  a  2s .  com*/

    doc.open();

    //crear fonts por defecto
    tblHeaderFont = new Font(Font.HELVETICA, 10f, Font.BOLD);
    tblBodyFont = new Font(Font.HELVETICA, 10f, Font.NORMAL);

    //definir pie de pagina del lado izquierdo
    String footerText = this.getFooter(); //read it from config.xml or web.xml
    String reportDate = StringUtil.formatDate(new java.util.Date(), "dd-MM-yyyy HH:mm");

    //crear template (objeto interno de IText) y manejador de evento 
    //para imprimir el pie de pagina
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    cb = docWriter.getDirectContent();
    tpl = cb.createTemplate(20, 14);
    docWriter.setPageEvent(new PDFPageEvents(footerText, pageXofY, tpl, bf, cb, reportDate));

    //titulo - lo lee de config.xml por defecto
    reportTitle = getReportTitle();
    Paragraph t = new Paragraph(reportTitle, new Font(Font.HELVETICA, 14f, Font.BOLD));
    t.setAlignment(Rectangle.ALIGN_RIGHT);
    doc.add(t);

    //logo
    img = Image.getInstance(getImage(this.getServerBaseURL() + logoPath, false));
    img.scalePercent(100);
    float imgY = doc.top() - img.getHeight();
    float imgX = doc.left();
    img.setAbsolutePosition(imgX, imgY);
    doc.add(img);

    //blank line
    doc.add(new Paragraph(" "));
    //blank line
    doc.add(new Paragraph(" "));
    //blank line
    doc.add(new Paragraph(" "));

    //for each master record print a master/detail section
    MasterDetailReader dataobj = (MasterDetailReader) data;
    Recordset master = dataobj.getRecordset("master");
    master.top();
    while (master.next()) {
        //blank line
        doc.add(new Paragraph(" "));

        //print master section
        doc.add(getGroupMaster(master));

        //print detail section
        doc.add(getGroupDetail(master, dataobj.getDetail(master)));

    }

    //print grand total
    doc.add(new Paragraph(" "));

    doc.close();
    docWriter.close();

}

From source file:fr.aliasource.webmail.server.export.ConversationExporter.java

License:GNU General Public License

public void exportToPdf(IAccount account, ConversationReference cr, ClientMessage[] cm, OutputStream out)
        throws ConversationExporterException {
    try {/*from ww w .  j  ava 2  s .  c om*/
        Document document = new Document(PageSize.A4, 22, 22, 80, 72);
        PdfWriter writer = PdfWriter.getInstance(document, out);
        writer.setPageEvent(new ConversationPdfEventHandler(account, cr, cm));
        // NPP by Tom
        if (cr.getTitle() != null) {
            document.addTitle(cr.getTitle());
        } else {
            document.addTitle("");
        }
        document.addAuthor("MiniG");
        document.open();

        document.add(Chunk.NEWLINE);

        Set<ClientMessage> scm = new LinkedHashSet<ClientMessage>();
        for (int i = 0; i < cm.length; i++) {
            scm.add(cm[i]);
        }
        this.exportMessage(scm, document, false);
        document.close();
    } catch (Exception e) {
        throw new ConversationExporterException("Cannot export conversation ", e);
    }
}

From source file:fr.univlorraine.mondossierweb.controllers.NoteController.java

License:Apache License

/**
 * //from ww  w. j  ava2s  .  c  o m
 * @return le fichier pdf du rsum des notes.
 */
public com.vaadin.server.Resource exportPdfResume() {

    String nomFichier = applicationContext.getMessage("pdf.notes.title", null, Locale.getDefault()) + " "
            + MainUI.getCurrent().getEtudiant().getNom().replace('.', ' ').replace(' ', '_') + ".pdf";
    nomFichier = nomFichier.replaceAll(" ", "_");

    StreamResource.StreamSource source = new StreamResource.StreamSource() {
        private static final long serialVersionUID = 1L;

        @Override
        public InputStream getStream() {
            try {
                ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(OUTPUTSTREAM_SIZE);
                PdfWriter docWriter = null;
                Document document = configureDocument(MARGE_PDF);
                docWriter = PdfWriter.getInstance(document, baosPDF);
                docWriter.setEncryption(null, null, PdfWriter.AllowPrinting, PdfWriter.ENCRYPTION_AES_128);
                docWriter.setStrictImageSequence(true);
                if (configController.isInsertionFiligranePdfNotes()) {
                    docWriter.setPageEvent(new Watermark());
                }
                creerPdfResume(document, MainUI.getCurrent().getEtudiant());
                docWriter.close();
                baosPDF.close();
                //Creation de l'export
                byte[] bytes = baosPDF.toByteArray();
                return new ByteArrayInputStream(bytes);
            } catch (DocumentException e) {
                LOG.error("Erreur  la gnration du rsum des notes : DocumentException ", e);
                return null;
            } catch (IOException e) {
                LOG.error("Erreur  la gnration du rsum des notes : IOException ", e);
                return null;
            }

        }
    };

    // Cration de la ressource 
    StreamResource resource = new StreamResource(source, nomFichier);
    resource.setMIMEType("application/force-download;charset=UTF-8");
    resource.setCacheTime(0);
    return resource;
}

From source file:fr.univlorraine.mondossierweb.controllers.NoteController.java

License:Apache License

/**
 * //from   w  w  w . j av a2 s. c  om
 * @return le fichier pdf du detail des notes.
 */
public com.vaadin.server.Resource exportPdfDetail(Etape etape) {

    String nomFichier = applicationContext.getMessage("pdf.detail.title", null, Locale.getDefault()) + " "
            + MainUI.getCurrent().getEtudiant().getNom().replace('.', ' ').replace(' ', '_') + ".pdf";
    nomFichier = nomFichier.replaceAll(" ", "_");

    StreamResource.StreamSource source = new StreamResource.StreamSource() {
        private static final long serialVersionUID = 1L;

        @Override
        public InputStream getStream() {
            try {
                ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(OUTPUTSTREAM_SIZE);
                PdfWriter docWriter = null;
                Document document = configureDocument(MARGE_PDF);
                docWriter = PdfWriter.getInstance(document, baosPDF);
                docWriter.setEncryption(null, null, PdfWriter.AllowPrinting, PdfWriter.ENCRYPTION_AES_128);
                docWriter.setStrictImageSequence(true);
                if (configController.isInsertionFiligranePdfNotes()) {
                    docWriter.setPageEvent(new Watermark());
                }
                creerPdfDetail(document, MainUI.getCurrent().getEtudiant(), etape);
                docWriter.close();
                baosPDF.close();
                //Creation de l'export
                byte[] bytes = baosPDF.toByteArray();
                return new ByteArrayInputStream(bytes);
            } catch (DocumentException e) {
                LOG.error("Erreur  la gnration du dtail des notes : DocumentException ", e);
                return null;
            } catch (IOException e) {
                LOG.error("Erreur  la gnration du dtail des notes : IOException ", e);
                return null;
            }

        }
    };

    // Cration de la ressource 
    StreamResource resource = new StreamResource(source, nomFichier);
    resource.getStream().setParameter("Content-Disposition", "attachment; filename=" + nomFichier);
    //resource.setMIMEType("application/unknow");
    resource.setMIMEType("application/force-download;charset=UTF-8");
    resource.setCacheTime(0);
    return resource;
}

From source file:geoportal.presentacion.beans.ReportesControlador.java

public void imprimirReporte() {
    //DateFormat dfDateFull = DateFormat.getDateInstance(DateFormat.FULL);
    try {//from  w  w w .  ja  v  a  2  s.c  o m

        //Generamos el archivo PDF
        String directorioArchivos;
        ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
                .getContext();
        directorioArchivos = ctx.getRealPath("/") + "reportes";
        String name = directorioArchivos + "/document-reporte.pdf";
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(name));
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(name));
        //PdfWriter writer = PdfWriter.getInstance(document,
        //new FileOutputStream("C:"));

        Paragraph paragraph = new Paragraph();
        Paragraph paragraph1 = new Paragraph();
        Paragraph paragraph2 = new Paragraph();

        //PdfPTable table = new PdfPTable(4);
        PdfPTable table1 = new PdfPTable(1);
        PdfPTable table2 = new PdfPTable(4);
        PdfPTable table3 = new PdfPTable(4);
        PdfPTable table5 = new PdfPTable(1);

        paragraph.add("\n\n\n\n\n\n\n");
        paragraph.setAlignment(Paragraph.ALIGN_CENTER);
        paragraph1.add("\n");
        paragraph1.setAlignment(Paragraph.ALIGN_CENTER);
        paragraph2.add("Total Denuncias:" + totalDenuncias);
        paragraph2.setAlignment(Paragraph.ALIGN_LEFT);

        //  Obtenemos una instancia de nuestro manejador de eventos
        MembreteHeaderiText header = new MembreteHeaderiText();
        //Asignamos el manejador de eventos al escritor.
        writer.setPageEvent(header);

        document.open();
        //            Chunk titulo = new Chunk(CHUNK, FontFactory.getFont(FontFactory.COURIER, 20, Font.UNDERLINE, BaseColor.BLACK));
        //
        //            titulo = new Chunk(IMAGE, FontFactory.getFont(FontFactory.COURIER, 20, Font.UNDERLINE, BaseColor.BLACK));
        //            document.add(titulo);
        //            Image foto = Image.getInstance(resources / ferrari.jpg?);
        //foto.scaleToFit(100, 100);        foto.setAlignment(Chunk.ALIGN_MIDDLE);

        //primera linea   
        PdfPCell cell5 = new PdfPCell(new Paragraph("VIOLENCIA INTRAFAMILIAR "));
        //segunda linea
        PdfPCell cell12 = new PdfPCell(new Paragraph("AO"));
        PdfPCell cell6 = new PdfPCell(new Paragraph("2010"));
        PdfPCell cell7 = new PdfPCell(new Paragraph("2011"));
        PdfPCell cell8 = new PdfPCell(new Paragraph("2012"));

        //tercera fila
        PdfPCell cell13 = new PdfPCell(new Paragraph("# DENUNCIAS"));
        PdfPCell cell9 = new PdfPCell(new Paragraph("" + lstVif2010.size()));
        PdfPCell cell10 = new PdfPCell(new Paragraph("" + lstVif2011.size()));
        PdfPCell cell11 = new PdfPCell(new Paragraph("" + lstVif_2012.size()));

        PdfPCell cell15 = new PdfPCell(new Paragraph("TOTAL DENUNCIAS:" + totalDenuncias));

        cell5.setHorizontalAlignment(Element.ALIGN_CENTER);

        cell6.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell7.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell8.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell9.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell10.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell11.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell12.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell13.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell15.setHorizontalAlignment(Element.ALIGN_LEFT);

        cell12.setBackgroundColor(Color.cyan);
        cell13.setBackgroundColor(Color.cyan);

        cell5.setBorder(Rectangle.NO_BORDER);
        cell15.setBorder(Rectangle.NO_BORDER);

        table1.addCell(cell5);
        //aadir segunda fila
        table2.addCell(cell12);
        table2.addCell(cell6);
        table2.addCell(cell7);
        table2.addCell(cell8);
        //aadir tercera fila
        table3.addCell(cell13);
        table3.addCell(cell9);
        table3.addCell(cell10);
        table3.addCell(cell11);
        //aadir cuarta fila
        table5.addCell(cell15);

        document.add(paragraph);
        document.add(table1);
        document.add(paragraph1);
        document.add(table2);
        document.add(table3);
        document.add(table5);
        //document.add(paragraph2);

        //document.add(table);
        //document.setFooter(event);
        document.close();
        //----------------------------
        //Abrimos el archivo PDF
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
        response.setContentType("application/pdf");
        response.setHeader("Content-disposition", "inline=filename=" + name);
        try {
            response.getOutputStream().write(Util.getBytesFromFile(new File(name)));
            response.getOutputStream().flush();
            response.getOutputStream().close();
            context.responseComplete();

        } catch (IOException e) {
            e.printStackTrace();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:io.vertigo.dynamo.plugins.export.pdf.PDFExporter.java

License:Apache License

/** {@inheritDoc} */
@Override//from  w  ww . j ava2 s  .c  o m
protected void createWriter(final Document document, final OutputStream out) throws DocumentException {
    final PdfWriter writer = PdfWriter.getInstance(document, out);
    // writer.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft);

    // simple page numbers : x
    // HeaderFooter footer = new HeaderFooter(new Phrase(), true);
    // footer.setAlignment(Element.ALIGN_RIGHT);
    // footer.setBorder(Rectangle.TOP);
    // document.setFooter(footer);

    // add the event handler for advanced page numbers : x/y
    writer.setPageEvent(new PDFAdvancedPageNumberEvents());
}

From source file:io.vertigo.quarto.plugins.export.pdf.PDFExporter.java

License:Apache License

/** {@inheritDoc} */
@Override//from   ww  w .j  av a2 s.c  om
protected void createWriter(final Document document, final OutputStream out) throws DocumentException {
    final PdfWriter writer = PdfWriter.getInstance(document, out);
    // add the event handler for advanced page numbers : x/y
    writer.setPageEvent(new PDFAdvancedPageNumberEvents());
}

From source file:jm.nom.clas.Carnet.java

public void imprimir(HttpServletResponse response, ResultSet rsCarnets, String path) {
    response.setContentType("application/pdf");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Expires", "Mon, 01 Jan 2001 00:00:01 GMT");
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Cache-Control", "must-revalidate");
    response.setHeader("Cache-Control", "no-cache");

    /*try{//  ww  w .  j a  va  2  s  . co  m
        rsCarnets = objEmpleado.getCarnets(id);
        if(rsCarnets.next()){
            id_sucursal = ((rsCarnets.getString("id_sucursal")!=null) ? rsCarnets.getString("id_sucursal") : "");
            id_instalacion = ((rsCarnets.getString("id_instalacion")!=null) ? rsCarnets.getString("id_instalacion") : "");
            serie_factura = ((rsCarnets.getString("serie_factura")!=null) ? rsCarnets.getString("serie_factura") : "");
            num_factura = ((rsCarnets.getString("num_factura")!=null) ? rsCarnets.getString("num_factura") : "");
            razon_social = ((rsCarnets.getString("razon_social")!=null) ? rsCarnets.getString("razon_social") : "CONSUMIDOR FINAL");
            fecha_emision = ((rsCarnets.getString("fecha_emision")!=null) ? Fecha.ISOaSQL(rsCarnets.getString("fecha_emision")) : "");
            direccion = ((rsCarnets.getString("direccion")!=null) ? rsCarnets.getString("direccion") : "");
            vendedor = ((rsCarnets.getString("vendedor")!=null) ? rsCarnets.getString("vendedor") : "");
            total = ((rsCarnets.getString("total")!=null) ? rsCarnets.getString("total") : "0.00");
            de_activo = ((rsCarnets.getString("de_activo")!=null) ? rsCarnets.getBoolean("de_activo") : false);
            rsCarnets.close();
        }
    }catch(Exception ie){
        ie.printStackTrace();
    }*/
    try {
        /* inicio PDF */
        Document document = new Document(PageSize.A4.rotate());// paso 1
        document.setMargins(-47, 0, 38, 0); /*Izquierda, derecha, tope, pie */

        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Carnet(this._dir));
        document.open(); // paso 3

        //writer.addJavaScript("this.print(false);", false); // Para enviar a la impresora automticamente.

        /* todo el cuerpo del doc es el paso 4 */

        //PdfPTable tbl = new PdfPTable(new float[]{40f,60f});
        PdfPTable tbl = new PdfPTable(4);
        int i = 0;
        try {
            //rsCarnets = objEmpleado.getCarnets(id);
            while (rsCarnets.next()) {
                PdfPTable tbl1 = new PdfPTable(1);
                PdfPTable tbl2 = new PdfPTable(new float[] { 90f, 5f, 5f });
                String foto = ((rsCarnets.getString("padre_nombre") != null)
                        ? rsCarnets.getString("padre_nombre")
                        : "");
                //_dir="C:\\Users\\SoulGael\\Documents\\NetBeansProjects\\trunk\\saitel\\build\\web\\img\\luis.jpg";

                tbl1.addCell(Addons.setCeldaPDFBottom(" ", Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT,
                        0, 26, 0));
                tbl1.addCell(Addons.setLogoCarnet(_dir + foto, 79, 103));
                //tbl1.addCell(Addons.setLogoCarnet(_dir,79,103));
                String nombre = ((rsCarnets.getString("nombre") != null) ? rsCarnets.getString("nombre") : "");
                String apellidos = ((rsCarnets.getString("apellido") != null) ? rsCarnets.getString("apellido")
                        : "");
                String cargo = ((rsCarnets.getString("cargo") != null) ? rsCarnets.getString("cargo") : "");
                ;
                String[] nombresArray = nombre.split(" ");
                String[] apellidosArray = apellidos.split(" ");
                String n_completos = nombresArray[0] + " " + apellidosArray[0];
                String CI = ((rsCarnets.getString("dni") != null) ? rsCarnets.getString("dni") : "");
                ;
                String sangre = ((rsCarnets.getString("tipo_sangre") != null)
                        ? rsCarnets.getString("tipo_sangre")
                        : "");
                ;
                String carnet = ((rsCarnets.getString("carnet") != null) ? rsCarnets.getString("carnet") : "");
                //String carnet="A,B,C,D,E,F,G";
                Color A = Color.WHITE;
                Color B = Color.WHITE;
                Color C = Color.WHITE;
                Color D = Color.WHITE;
                Color E = Color.WHITE;
                Color F = Color.WHITE;
                Color G = Color.WHITE;

                String[] carnetArray = carnet.split(",");
                for (int j = 0; j < carnetArray.length; j++) {
                    if (carnetArray[j].equals("A")) {
                        A = Color.ORANGE;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("B")) {
                        B = Color.ORANGE;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("C")) {
                        C = Color.ORANGE;
                        ;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("D")) {
                        D = Color.ORANGE;
                        ;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("E")) {
                        E = Color.ORANGE;
                        ;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("F")) {
                        F = Color.ORANGE;
                        ;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("G")) {
                        G = Color.ORANGE;
                        ;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    break;
                }

                tbl1.addCell(Addons.setCeldaPDFBottom(" ", Font.ITALIC, 7, Font.BOLD, Element.ALIGN_CENTER, 0,
                        0, 0));
                tbl1.addCell(Addons.setCeldaPDFBottom(n_completos, Font.ITALIC, 13, Font.BOLD,
                        Element.ALIGN_CENTER, 0, 0, 0));
                tbl1.addCell(Addons.setCeldaPDFBottom(cargo, Font.ITALIC, 12, Font.BOLD, Element.ALIGN_CENTER,
                        0, 0, 0));
                tbl1.addCell(Addons.setCeldaPDFBottom(CI, Font.ITALIC, 12, Font.BOLD, Element.ALIGN_CENTER, 0,
                        0, 0));
                tbl1.addCell(Addons.setCeldaPDFBottom(sangre, Font.ITALIC, 12, Font.BOLD, Element.ALIGN_CENTER,
                        0, 0, 0));

                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 7, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 7, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 7, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("  LICENCIA INTERNA DE ", Font.ITALIC, 9, Font.BOLD,
                        Element.ALIGN_CENTER, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("  PREVENCION DE RIESGOS", Font.ITALIC, 9, Font.BOLD,
                        Element.ALIGN_CENTER, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("   Con la induccin recibida y aprobada usted",
                        Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("   est autorizado para:", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("      a. Trabajo de Oficina.", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 2, 0, A));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      b. Trabajo de Marketing y propaganda", Font.ITALIC,
                        8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 2, 0, B));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      c. Trabajo de mantenimiento y limpieza",
                        Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 2, 0, C));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      d. Trabajo de instalaciones menores a los ",
                        Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0,
                        0, 2));
                tbl2.addCell(Addons.setCeldaPDFCarnet("      ocho metros sobre el nivel.", Font.ITALIC, 8,
                        Font.BOLD, Element.ALIGN_LEFT, 0, 0, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 0, 0, D));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet("      (Domicilios, postes, cableado)", Font.ITALIC, 8,
                        Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0,
                        2, 2));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      e. Trabajo de instalaciones, antenas,",
                        Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0,
                        0, 2));
                tbl2.addCell(Addons.setCeldaPDFCarnet("      infraestructura mayores a los ocho", Font.ITALIC,
                        8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 0, 0, E));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet("      metros sobre el nivel", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0,
                        2, 2));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      f. Planes de emergencia y contingencia",
                        Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 2, 0, F));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      g. Planes de rescate", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 2, 0, G));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));

                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 10, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("Ing. FREDDY ROSERO", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 0, 0, 3, Color.BLUE));
                tbl2.addCell(Addons.setCeldaPDFCarnet("GERENTE", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 0, 0, 3, Color.BLUE));
                tbl2.addCell(Addons.setCeldaPDFCarnet("Fecha de Expedicin: Mayo 2015", Font.ITALIC, 5,
                        Font.BOLD, Element.ALIGN_CENTER, 0, 0, 3, Color.BLUE));
                tbl2.addCell(Addons.setCeldaPDFCarnet("Fecha de Caducidad: Mayo 2016", Font.ITALIC, 5,
                        Font.BOLD, Element.ALIGN_CENTER, 0, 0, 3, Color.BLUE));
                /* tbl1.addCell(Addons.setCeldaPDF(((rsCarnets.getString("nombres")!=null) ? rsCarnets.getString("nombres") : ""), Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 1));
                tbl1.addCell(Addons.setCeldaPDF(((rsCarnets.getString("rol")!=null) ? rsCarnets.getString("rol") : ""), Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 1));
                        
                tbl1.addCell(Addons.setCeldaPDF(((rsCarnets.getString("dni")!=null) ? rsCarnets.getString("dni") : ""), Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 1));
                tbl1.addCell(Addons.setCeldaPDF(((rsCarnets.getString("tipo_sangre")!=null) ? rsCarnets.getString("tipo_sangre") : ""), Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 1));
                        
                String idcarnet=(rsCarnets.getString("id_empleado")!=null) ? rsCarnets.getString("id_empleado") : "";*/

                tbl.addCell(Addons.setCeldaPDF(tbl1, 0, 0));
                tbl.addCell(Addons.setCeldaPDF(tbl2, 0, 0));
                if (i % 2 != 0) {
                    tbl1.addCell(
                            Addons.setCeldaPDF(" ", Font.ITALIC, 10, Font.BOLD, Element.ALIGN_LEFT, 0, 16, 3));
                }
                i++;
            }
            if (i % 2 != 0) {
                tbl.addCell(" ");
                tbl.addCell(" ");
            }

            /*Archivo archivo = new Archivo(_ip, _puerto, _db, _usuario, _clave);
                //path = path.substring(0, path.lastIndexOf("/"));
                String carnet = path + "/img/" + archivo.getArchivo(_dir, "vta_empleado", idcarnet, "padre_nombre", "foto");
                archivo.cerrar();
                Image imagen = null;
                try{
                    imagen = Image.getInstance(carnet);
                    imagen.scaleAbsolute(50, 70);
                    PdfPCell celdaImg = new PdfPCell(imagen);
                    celdaImg.setBorderWidth(0);
                    celdaImg.setPadding(0);
                    tbl.addCell(celdaImg);
                    document.add(tbl1);
                }catch(Exception e){
                    tbl.addCell(" ");
                }*/

        } catch (Exception e) {
            e.printStackTrace();
        }
        document.add(tbl);

        document.close(); // paso 5
        /* fin PDF */

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:jm.Reporte.java

License:GNU General Public License

public void lista(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros) {
    /* inicio PDF */
    Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate();
    Document document = new Document(orientacion);// paso 1
    document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */
    try {/*from  w w  w .  j  av  a2 s . c o  m*/
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo,
                this.direccion, this.sucursal, this.rep_pie));

        document.open(); // paso 3

        /* todo el cuerpo del doc es el paso 4 */

        document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion,
                this.sucursal));

        document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla));

        ResultSetMetaData mdata = registros.getMetaData();
        int numCols = mdata.getColumnCount();
        PdfPTable tbl_det = new PdfPTable(anchoTabla);
        int num = 1;
        try {
            while (registros.next()) {
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_CENTER, 1));
                for (int i = 1; i <= numCols; i++) {
                    tbl_det.addCell(
                            Addons.setCeldaPDF(((registros.getString(i) != null) ? registros.getString(i) : ""),
                                    Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                }
                num++;
            }
            registros.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        document.add(tbl_det);

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    document.close(); // paso 5
    /* fin PDF */
}

From source file:jm.Reporte.java

License:GNU General Public License

public void lista(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros,
        int lim) {
    /* inicio PDF */
    Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate();
    Document document = new Document(orientacion);// paso 1
    document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */
    try {/*  ww  w  . ja va2s .  c o m*/
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo,
                this.direccion, this.sucursal, this.rep_pie));
        document.open(); // paso 3

        /* todo el cuerpo del doc es el paso 4 */

        document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion,
                this.sucursal));

        document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla));

        PdfPTable tbl_det = new PdfPTable(anchoTabla);
        int num = 1;
        int alineacion = Element.ALIGN_LEFT;
        try {
            while (registros.next()) {
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_CENTER, 1));
                for (int i = 1; i <= lim; i++) {
                    //alineacion = (i==lim) ? Element.ALIGN_RIGHT : Element.ALIGN_LEFT;
                    tbl_det.addCell(
                            Addons.setCeldaPDF(((registros.getString(i) != null) ? registros.getString(i) : ""),
                                    Font.TIMES_ROMAN, 8, Font.NORMAL, alineacion, 1));
                }
                num++;
            }
            registros.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        document.add(tbl_det);

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    document.close(); // paso 5
    /* fin PDF */
}