Example usage for com.lowagie.text Image setAlignment

List of usage examples for com.lowagie.text Image setAlignment

Introduction

In this page you can find the example usage for com.lowagie.text Image setAlignment.

Prototype


public void setAlignment(int alignment) 

Source Link

Document

Sets the alignment for the image.

Usage

From source file:s2s.luna.reports.Report_REP_SOP.java

License:GNU General Public License

@Override
public void doReport() throws DocumentException, IOException, BadElementException, Exception {

    SecurityWrapper Security = SecurityWrapper.getInstance();
    ISopraluogoHome home1 = (ISopraluogoHome) PseudoContext.lookup("SopraluogoBean");
    ISopraluogo bean = home1.findByPrimaryKey(new Long(new Long(request.getParameter("ID"))));
    IAnagrProcedimentoHome home_pro = (IAnagrProcedimentoHome) PseudoContext.lookup("AnagrProcedimentoBean");
    IAnagrProcedimento bean_pro = home_pro.findByPrimaryKey(new Long(bean.getCOD_PRO()));
    IDipendenteHome home_dpd = (IDipendenteHome) PseudoContext.lookup("DipendenteBean");

    ICantiereHome home_can = (ICantiereHome) PseudoContext.lookup("CantiereBean");
    ICantiere bean_can = home_can.findByPrimaryKey(new Long(bean.getCOD_CAN()));

    IAnagrOpereHome home_ope = (IAnagrOpereHome) PseudoContext.lookup("AnagrOpereBean");
    IAnagrOpere bean_ope = null;// ww w  .  j av  a  2s .  c om
    long COD_OPE = bean.getCOD_OPE();
    if (COD_OPE != 0) {
        bean_ope = home_ope.findByPrimaryKey(COD_OPE);
    }

    lCOD_AZL = Security.getAziendaR();
    IAziendaHome home_az = (IAziendaHome) PseudoContext.lookup("AziendaBean");
    IAzienda bean_az = home_az.findByPrimaryKey(new Long(lCOD_AZL));

    initDocument("the doc",
            // Intestazione - Cella a sinistra
            bean_pro.getstrDES(),
            // Intestazione - Cella centrale
            bean_can.getNOM_CAN() + " - " + bean.getNUM_SOP(),
            // Pi di pagina Cella a sinistra
            bean_az.getRAG_SCL_AZL(),
            // Pi di pagina Cella a destra
            formatPlain(bean.getDAT_SOP()));

    m_handler.bShowDate = false;

    // LOGO E TITOLO
    {
        CenterMiddleTable tbl = new CenterMiddleTable(2);
        tbl.setDefaultCellBorder(0);
        int width[] = { 15, 75 };
        tbl.setWidths(width);
        if (IncludeLogo) {
            Image png = loadImage("LOGO");
            png.scalePercent(50);
            png.setAlignment(Image.ALIGN_LEFT);
            Cell cImage = new Cell(png);
            tbl.addCell(cImage);
        } else {
            tbl.addCell("");
        }
        CenterMiddleTable tbl2 = new CenterMiddleTable(1);
        tbl2.setDefaultCellBorder(0);
        tbl2.addCellBU(ApplicationConfigurator.CUSTOMER_NAME.toUpperCase(), 15);
        tbl2.addCellBU(ApplicationConfigurator.LanguageManager.getString("Coordinamento.sicurezza.cantieri")
                .toUpperCase(), 15);

        Cell cText = new Cell(tbl2);
        tbl.addCell(cText);
        m_document.add(tbl);
    }

    writeIndent();
    {
        CenterMiddleTable tbl = new CenterMiddleTable(1);
        if (bStandAlone) {
        }
        m_document.add(tbl);
    }

    // DATI DEL SOPRALLUOGO
    {
        CenterMiddleTable tbl = new CenterMiddleTable(4);
        tbl.toLeft();
        int width[] = { 30, 20, 25, 25 };
        tbl.setWidths(width);
        tbl.addCell(
                ApplicationConfigurator.LanguageManager.getString("Sopralluogo.N") + "  " + bean.getNUM_SOP(),
                defaultFontSize);
        tbl.addCell(ApplicationConfigurator.LanguageManager.getString("del") + "  "
                + formatPlain(bean.getDAT_SOP()), defaultFontSize);
        tbl.addCell(
                ApplicationConfigurator.LanguageManager.getString("Inizio.h")
                        + (bean.getORA_INI() != null ? bean.getORA_INI().toString().substring(0, 5) : ""),
                defaultFontSize);
        tbl.addCell(
                ApplicationConfigurator.LanguageManager.getString("Fine.h")
                        + (bean.getORA_FIN() != null ? bean.getORA_FIN().toString().substring(0, 5) : ""),
                defaultFontSize);
        m_document.add(tbl);
    }
    {
        CenterMiddleTable tbl = new CenterMiddleTable(3);
        tbl.toLeft();
        int width[] = { 34, 33, 33 };
        tbl.setWidths(width);
        tbl.addCell(ApplicationConfigurator.LanguageManager.getString("Linea") + ":  " + bean_pro.getstrDES(),
                defaultFontSize);
        tbl.addCell(
                ApplicationConfigurator.LanguageManager.getString("Stazione") + ":  " + bean_can.getNOM_CAN(),
                defaultFontSize);
        tbl.addCell(ApplicationConfigurator.LanguageManager.getString("Opera") + ":  "
                + (bean_ope != null ? bean_ope.getstrNOM_OPE() : ""), defaultFontSize);
        m_document.add(tbl);
    }

    // PRESENTI AZIENDA
    {
        CenterMiddleTable tbl = new CenterMiddleTable(2);
        tbl.toLeft();
        int width[] = { 25, 70 };
        tbl.setWidths(width);
        tbl.border();
        java.util.Collection col = home_dpd.getDipendentiBySOP_View(lCOD_SOP);
        tbl.addCell(ApplicationConfigurator.LanguageManager.getString("Presenti.RM"), defaultFontSize);
        java.util.Iterator it = col.iterator();
        String presentiRM = "";
        while (it.hasNext()) {
            DipendentiBySOP_View obj = (DipendentiBySOP_View) it.next();
            presentiRM += (StringManager.isEmpty(presentiRM) ? "" : ", ") + obj.COG_DPD + " " + obj.NOM_DPD;
        }
        tbl.addCell(presentiRM, defaultFontSize);
        m_document.add(tbl);
    }

    // PRESENTI IMPRESA
    {
        CenterMiddleTable tbl = new CenterMiddleTable(2);
        tbl.toLeft();
        tbl.setPadding(1 / 2);
        int width[] = { 25, 70 };
        tbl.setWidths(width);
        tbl.border();
        java.util.Collection col = home_dpd.getDipendentiEstBySOP_View(lCOD_SOP);
        java.util.Iterator it = col.iterator();
        tbl.addCell(ApplicationConfigurator.LanguageManager.getString("Presenti.impresa"), defaultFontSize);
        String presentiIMP = "";
        while (it.hasNext()) {
            DipendentiBySOP_View obj = (DipendentiBySOP_View) it.next();
            presentiIMP += (StringManager.isEmpty(presentiIMP) ? "" : ", ") + obj.COG_DPD + " " + obj.NOM_DPD
                    + " (" + obj.IMPRESA + ")";
        }
        tbl.addCell(presentiIMP, defaultFontSize);
        m_document.add(tbl);
    }
    writeLine();

    // CONSTATAZIONI
    {
        CenterMiddleTable tbl = new CenterMiddleTable(1);
        tbl.toLeft();
        int width[] = { 100 };
        tbl.setWidths(width);
        tbl.addHeaderCellB2(ApplicationConfigurator.LanguageManager.getString("CONSTATAZIONI"), 1, false, 11);
        m_document.add(tbl);
    }
    {
        CenterMiddleTable tbl = new CenterMiddleTable(2);
        tbl.toLeft();
        int width[] = { 5, 85 };
        tbl.setWidths(width);
        java.util.Collection col = home1.getConstatazioniSop(lCOD_SOP);
        java.util.Iterator it = col.iterator();
        tbl.setWidths(width);
        String constElementSeparator = " - ";
        Alphabet c = new Alphabet();
        String REV1 = c.getNextElement("1");
        while (it.hasNext()) {
            jbConstatazione obj = (jbConstatazione) it.next();

            // Numerazione alfabetica
            Cell cell = new Cell(new Phrase(Formatter.format(REV1), REPORT_SETTINGS.ftText9B));
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            tbl.addCell(cell);

            // Constatazione
            tbl.addCell(Formatter.format(
                    (StringManager.isNotEmpty(obj.sRAG_SCL_DTE) ? obj.sRAG_SCL_DTE + constElementSeparator : "")
                            + (StringManager.isNotEmpty(obj.sNOM_ATT)
                                    ? obj.sNOM_ATT + constElementSeparator
                                    : "")
                            + (StringManager.isNotEmpty(obj.sDES_LIB) ? obj.sDES_LIB + constElementSeparator
                                    : "")
                            + obj.sDESC),
                    defaultFontSize);
            REV1 = c.getNextElement(REV1);
        }
        m_document.add(tbl);
    }
    writeLine();

    // DISPOSIZIONI
    {
        CenterMiddleTable tbl = new CenterMiddleTable(1);
        tbl.toLeft();
        int width[] = { 85 };
        tbl.setWidths(width);
        tbl.addHeaderCellB2(ApplicationConfigurator.LanguageManager.getString("DISPOSIZIONI"), 1, false, 11);
        m_document.add(tbl);
    }
    {
        CenterMiddleTable tbl = new CenterMiddleTable(2);
        tbl.toLeft();
        int width[] = { 5, 85 };
        java.util.Collection col = home1.getConstatazioniSop(lCOD_SOP);
        java.util.Iterator it = col.iterator();
        tbl.setWidths(width);
        Alphabet c = new Alphabet();
        String REV2 = c.getNextElement("1");
        while (it.hasNext()) {
            jbConstatazione obj = (jbConstatazione) it.next();

            // Numerazione alfabetica
            Cell cell = new Cell(new Phrase(Formatter.format(REV2), REPORT_SETTINGS.ftText9B));
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            tbl.addCell(cell);

            // Disposizione generata
            tbl.addCell(Formatter.format(obj.sDIS_GEN), defaultFontSize);
            REV2 = c.getNextElement(REV2);
        }
        m_document.add(tbl);
    }

    // FIRME
    // Spazio per le firme
    for (int i = 1; i <= 5; i++) {
        writeLine();
    }
    {
        CenterMiddleTable tbl = new CenterMiddleTable(2);
        int width[] = { 50, 50 };
        tbl.setWidths(width);
        tbl.setDefaultCellBorder(0);

        // Firme del personale dell'azienda
        Cell cell = new Cell(
                new Phrase(ApplicationConfigurator.CUSTOMER_NAME.toUpperCase(), REPORT_SETTINGS.ftText9));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        tbl.addCell(cell);

        // Firme del personale delle imprese
        Cell cell2 = new Cell(
                new Phrase(ApplicationConfigurator.LanguageManager.getString("Impresa").toUpperCase(),
                        REPORT_SETTINGS.ftText9));
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        tbl.addCell(cell2);

        m_document.add(tbl);
    }

    // FOTO
    {
        Collection<jbMedia> listaFoto = home1.getMediaSOP(lCOD_SOP);
        if (listaFoto != null && listaFoto.size() > 0) {

            // STAMPA L'INDICE DELLE FOTO.
            boolean firstFoto = true;
            int fotoIndex = 0;
            for (jbMedia foto : listaFoto) {
                try {
                    // Verifica che l'immagine sia in un formato supportato.
                    Image.getInstance(foto.mediaData);
                    fotoIndex++;
                    if (firstFoto) {
                        writePage();
                        writeTitle(ApplicationConfigurator.LanguageManager.getString("Indice.foto.allegate"));
                        firstFoto = false;
                    }
                    writeLine();
                    // Stampo il progessivo della foto, nel formato "Foto n".
                    writeText2Bold(ApplicationConfigurator.LanguageManager.getString("Foto") + " " + fotoIndex);
                    // Stampo il "nome" o se questo  assente, "il nome file".
                    writeText2(StringManager.isNotEmpty(foto.sNOM_MED) ? Formatter.format(foto.sNOM_MED)
                            : Formatter.format(foto.sFile));
                    // Stampo, se presente, la "descrizione".
                    writeText2(StringManager.isNotEmpty(foto.sDES_MED) ? Formatter.format(foto.sDES_MED) : "");
                } catch (Exception ex) {
                    // Eccezione silenziosa.
                    // Gestisce il caso in cui l'allegato non sia un immagine
                }
            }
            // STAMPA LE FOTO.
            firstFoto = true;
            fotoIndex = 0;
            byte SPACE_FOR_TITLE = 20;
            byte SPACE_FOR_BOTTOM_MARGIN = 20;
            boolean strictImageSequence = m_writer.isStrictImageSequence();
            m_writer.setStrictImageSequence(true);
            for (jbMedia foto : listaFoto) {
                Element image = prepareImage(m_document, foto.mediaData);
                if (image != null) {
                    fotoIndex++;
                    if (firstFoto) {
                        writePage();
                        firstFoto = false;
                    }
                    if (m_document.getPageSize().getHeight() - m_document.topMargin()
                            + 20 < getAvailablePageSpace(m_document, m_writer)) {
                        writeLine();
                    }
                    if (getAvailablePageSpace(m_document, m_writer)
                            - (SPACE_FOR_TITLE + SPACE_FOR_BOTTOM_MARGIN) < ((Image) image).getScaledHeight()) {
                        writePage();
                    }
                    // Stampo il progessivo della foto, nel formato "Foto n".
                    writeText2(ApplicationConfigurator.LanguageManager.getString("Foto") + " " + fotoIndex);
                    // Stampo l'immagine.
                    m_document.add(image);
                }
            }
            m_writer.setStrictImageSequence(strictImageSequence);
        }
    }
    // DOCUMENTI ALLEGATI
    Collection<DocumentiAssociati_Sopralluogo_View> listadocumenti = home1
            .getDocumentiCantiereSOP_STAMPA(lCOD_SOP);
    if (listadocumenti != null && listadocumenti.size() > 0) {

        // STAMPA L'INDICE DEI DOCUMENTI ALLEGATI
        // i documenti allegati sono quei documenti la cui tipologia risulta avere attivo
        //il flag di stampa in sopralluogo.
        boolean firstdocument = true;
        int documentIndex = 0;
        for (DocumentiAssociati_Sopralluogo_View documento : listadocumenti) {
            try {
                // Verifica che l'immagine sia in un formato supportato.
                documentIndex++;
                if (firstdocument) {
                    writePage();
                    writeTitle(ApplicationConfigurator.LanguageManager.getString("Indice.documenti.allegati"));
                    firstdocument = false;
                }
                writeLine();
                // Stampo il "titolo" del documento.
                writeText3Bold(documentIndex + ")"
                        + (StringManager.isNotEmpty(documento.TIT_DOC) ? Formatter.format(documento.TIT_DOC)
                                : Formatter.format(documento.NOM_TPL_DOC)));
                // Stampo, se presente, la "descrizione".
                if (!(documento.DES).equals("")) {
                    writeLine();
                }
                writeText3_3(StringManager.isNotEmpty(documento.DES) ? Formatter.format(documento.DES) : "");

                IAnagrDocumentoHome doc_home = (IAnagrDocumentoHome) PseudoContext.lookup("AnagrDocumentoBean");
                AnagDocumentoFileInfo fileInfo = null;
                AnagDocumentoFileInfo fileInfoLink = null;
                fileInfo = doc_home.getFileInfoU("", documento.lCOD_DOC);
                fileInfoLink = doc_home.getFileInfoULink("", documento.lCOD_DOC);

                // se esiste stampo il file allegato
                if (fileInfo != null) {
                    writeLine();
                    writeText3_3(Formatter.format("   " + "File Allegato:  " + fileInfo.strName));
                } else {
                    writeLine();
                    writeText3_3(Formatter.format("   " + "File Allegato:  "));
                }

                // se esiste stampo il file link allegato
                if (fileInfoLink != null) {
                    writeText3_3(Formatter.format("   " + "File Link Allegato:  " + fileInfoLink.strName));
                } else {
                    writeText3_3(Formatter.format("   " + "File Link Allegato:  "));
                }
                writeLine();
            } catch (Exception ex) {
                // Eccezione silenziosa.
                // Gestisce il caso in cui l'allegato non sia un immagine
            }

        }
        writePage();
        // Stampa documenti allegati
        boolean endWithNewPage = false;
        endWithNewPage = StampaDocumenti(home1, bean.getCOD_SOP(), m_document, m_writer);

    }
    closeDocument();
}

From source file:s2s.report.Report.java

License:GNU General Public License

public void AddImage() throws Exception {
    if (ApplicationConfigurator.VIEW_REPORT_IMAGE == true) {
        //carica immagine logo
        writeTitle("\n");
        Image png = loadImage("LOGO");
        png.setAlignment(Image.MIDDLE);
        m_document.add(png);/*from   w  w w  .  j  a v a 2  s .  co  m*/
        writeTitle("\n");
    }
}

From source file:s2s.report.Report.java

License:GNU General Public License

public void AddScaledImage(float percentScale) throws Exception {
    if (ApplicationConfigurator.VIEW_REPORT_IMAGE == true) {
        //carica immagine logo
        writeTitle("\n");
        Image png = loadImage("LOGO");
        png.scalePercent(percentScale);/*from w  w w  .  j  a v  a  2s. c  o  m*/
        png.setAlignment(Image.MIDDLE);
        m_document.add(png);
        writeTitle("\n");
    }
}

From source file:subcentro_licto.presentacion.beans.DatosBuscadorBean.java

public void imprimirDatos() {
    //DateFormat dfDateFull = DateFormat.getDateInstance(DateFormat.FULL);
    try {//w  w  w.  j a  va2  s .  c o m

        //Generamos el archivo PDF
        String directorioArchivos;
        ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
                .getContext();
        directorioArchivos = ctx.getRealPath("/") + "reports";
        String name = directorioArchivos + "/documento-datos.pdf";
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(name));

        //PdfWriter writer = PdfWriter.getInstance(document,
        //new FileOutputStream("C:"));
        Paragraph paragraph = new Paragraph();

        PdfPTable table = new PdfPTable(2);
        PdfPTable table1 = new PdfPTable(2);
        PdfPTable table2 = new PdfPTable(2);
        PdfPTable table3 = new PdfPTable(2);
        PdfPTable table4 = new PdfPTable(2);
        PdfPTable table5 = new PdfPTable(2);
        PdfPTable table6 = new PdfPTable(2);
        PdfPTable table7 = new PdfPTable(2);
        PdfPTable table8 = new PdfPTable(2);
        PdfPTable table9 = new PdfPTable(2);
        PdfPTable table10 = new PdfPTable(2);
        PdfPTable table11 = new PdfPTable(2);
        PdfPTable table12 = new PdfPTable(2);
        PdfPTable table13 = new PdfPTable(1);

        paragraph.add("\n\n\n\n\n\n");
        paragraph.setAlignment(Paragraph.ALIGN_CENTER);

        document.open();
        Image image1 = Image.getInstance(
                "C:/Users/Usuario/Documents/NetBeansProjects/gestionsalud/web/resources/images/logoMSP.jpg");

        image1.setAlignment(Element.ALIGN_CENTER);

        PdfPCell cell5 = new PdfPCell(new Paragraph("Fecha Agresin: " + datosSel.getFecha_agresion()));
        PdfPCell cell7 = new PdfPCell(new Paragraph("Fecha Atencin: " + datosSel.getFecha_de_atencion()));
        PdfPCell cell8 = new PdfPCell(new Paragraph("Nombres: " + datosSel.getNombres()));
        PdfPCell cell11 = new PdfPCell(new Paragraph("Apellidos: " + datosSel.getApellidos()));
        PdfPCell cell12 = new PdfPCell(new Paragraph("Edad: " + datosSel.getEdad()));
        PdfPCell cell9 = new PdfPCell(new Paragraph("Sexo: " + datosSel.getSexo()));
        PdfPCell cell10 = new PdfPCell(new Paragraph("Estado Civil:" + datosSel.getEstado_civil()));
        PdfPCell cell13 = new PdfPCell(new Paragraph("Instruccin:" + datosSel.getInstruccion_formal()));
        PdfPCell cell1 = new PdfPCell(new Paragraph("Ocupacin: " + datosSel.getOcupacion()));
        PdfPCell cell2 = new PdfPCell(new Paragraph("Institucin: " + datosSel.getInstitucion()));
        PdfPCell cell3 = new PdfPCell(new Paragraph("Asociacin: " + datosSel.getAsociacion()));
        PdfPCell cell4 = new PdfPCell(new Paragraph("Provincia: " + datosSel.getProvincia()));
        PdfPCell cell6 = new PdfPCell(new Paragraph("Cantn: " + datosSel.getCanton_domicilio()));
        PdfPCell cell14 = new PdfPCell(new Paragraph("Parroquia: " + datosSel.getParroquia_domicilio()));
        PdfPCell cell15 = new PdfPCell(new Paragraph("Barrio: " + datosSel.getBarrio()));
        PdfPCell cell16 = new PdfPCell(new Paragraph("Calles: " + datosSel.getCalles_domicilio()));
        PdfPCell cell17 = new PdfPCell(new Paragraph("Direccin Trabajo: " + datosSel.getDireccion_trabajo()));
        PdfPCell cell18 = new PdfPCell(new Paragraph("Telfono Domicilio: " + datosSel.getTelefono()));
        PdfPCell cell19 = new PdfPCell(new Paragraph("Telfono Trabajo: " + datosSel.getTelefono_trabajo()));
        PdfPCell cell20 = new PdfPCell(
                new Paragraph("Objeto de Agresin: " + datosSel.getObjeto_de_agresion()));
        PdfPCell cell21 = new PdfPCell(
                new Paragraph("Tipo de Agresin: " + datosSel.getTipos_de_agresiones()));
        PdfPCell cell22 = new PdfPCell(
                new Paragraph("Estado de Conciencia: " + datosSel.getEstado_de_conciencia()));
        PdfPCell cell23 = new PdfPCell(new Paragraph("Lugar de Agresin: " + datosSel.getLugar_de_agresion()));
        PdfPCell cell24 = new PdfPCell(new Paragraph("Frecuencia: " + datosSel.getFrecuencia()));
        PdfPCell cell25 = new PdfPCell(new Paragraph("Caso Medico: " + datosSel.getCaso_medico()));
        PdfPCell cell26 = new PdfPCell(new Paragraph("Tratamiento: " + datosSel.getTratamiento()));
        PdfPCell cell27 = new PdfPCell(new Paragraph("Referido: " + datosSel.getReferido()));

        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell2.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell3.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell4.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell5.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell6.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell7.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell8.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell9.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell10.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell11.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell12.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell13.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell14.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell15.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell16.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell17.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell18.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell19.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell20.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell21.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell22.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell23.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell24.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell25.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell26.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell27.setHorizontalAlignment(Element.ALIGN_LEFT);

        cell1.setBorder(Rectangle.NO_BORDER);
        cell2.setBorder(Rectangle.NO_BORDER);
        cell3.setBorder(Rectangle.NO_BORDER);
        cell4.setBorder(Rectangle.NO_BORDER);
        cell5.setBorder(Rectangle.NO_BORDER);
        cell6.setBorder(Rectangle.NO_BORDER);
        cell7.setBorder(Rectangle.NO_BORDER);
        cell8.setBorder(Rectangle.NO_BORDER);
        cell9.setBorder(Rectangle.NO_BORDER);
        cell10.setBorder(Rectangle.NO_BORDER);
        cell11.setBorder(Rectangle.NO_BORDER);
        cell12.setBorder(Rectangle.NO_BORDER);
        cell13.setBorder(Rectangle.NO_BORDER);
        cell14.setBorder(Rectangle.NO_BORDER);
        cell15.setBorder(Rectangle.NO_BORDER);
        cell16.setBorder(Rectangle.NO_BORDER);
        cell17.setBorder(Rectangle.NO_BORDER);
        cell18.setBorder(Rectangle.NO_BORDER);
        cell19.setBorder(Rectangle.NO_BORDER);
        cell20.setBorder(Rectangle.NO_BORDER);
        cell21.setBorder(Rectangle.NO_BORDER);
        cell22.setBorder(Rectangle.NO_BORDER);
        cell23.setBorder(Rectangle.NO_BORDER);
        cell24.setBorder(Rectangle.NO_BORDER);
        cell25.setBorder(Rectangle.NO_BORDER);
        cell26.setBorder(Rectangle.NO_BORDER);
        cell27.setBorder(Rectangle.NO_BORDER);

        table1.addCell(cell5);
        table1.addCell(cell7);
        table2.addCell(cell8);
        table2.addCell(cell11);
        table3.addCell(cell12);
        table3.addCell(cell9);
        table.addCell(cell10);
        table.addCell(cell13);
        table4.addCell(cell1);
        table4.addCell(cell2);
        table5.addCell(cell3);
        table5.addCell(cell4);
        table6.addCell(cell6);
        table6.addCell(cell14);
        table7.addCell(cell15);
        table7.addCell(cell16);
        table8.addCell(cell17);
        table8.addCell(cell18);
        table9.addCell(cell19);
        table9.addCell(cell20);
        table10.addCell(cell21);
        table10.addCell(cell22);
        table11.addCell(cell23);
        table11.addCell(cell24);
        table12.addCell(cell25);
        table12.addCell(cell26);
        table13.addCell(cell27);

        document.add(image1);
        document.add(paragraph);
        document.add(table1);
        document.add(table2);
        document.add(table3);
        document.add(table);
        document.add(table4);
        document.add(table5);
        document.add(table6);
        document.add(table7);
        document.add(table8);
        document.add(table9);
        document.add(table10);
        document.add(table11);
        document.add(table12);
        document.add(table13);
        //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:tk.diginspect.main.SoOFSignatories.java

private void FDALetterhead() {
    try {//from  w ww  .  j  av a  2s  .  co  m
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        Bitmap bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(),
                R.drawable.fda_letterhead);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        Image Img = Image.getInstance(stream.toByteArray());
        Img.setAlignment(Image.MIDDLE);
        Img.scalePercent(40f);
        doc.add(Img);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (BadElementException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:vistas.reportes.procesos.rptAsistenciaTotal.java

public void crearPdf(String nombreFile, List<String> dnis, Date fechaInicio, Date fechaFin, String oficina,
        String tipo, String usuario, boolean isSelectedComp, boolean isSelectedHoraM)
        throws IOException, DocumentException {
    Document documento = new Document(PageSize.A4);
    PdfWriter.getInstance(documento, new FileOutputStream(nombreFile));
    documento.open();//from  w w  w .  j a  v a  2 s . c  o m
    Image cabecera = Image.getInstance("img/cabecera.png");
    cabecera.setAlignment(1);
    documento.add(cabecera);
    String nombreGrupoOficina = "";
    if (tipo == "O") {
        nombreGrupoOficina = "DEPENDENCIA:      ";
    } else if (tipo == "G") {
        nombreGrupoOficina = "GRUPO HORARIO: ";
    } else if (tipo == "P") {
        nombreGrupoOficina = "DEPENDENCIA:      ";
    }
    Font font = new Font(Font.HELVETICA, 10, Font.BOLD);
    Chunk nombreReporte = new Chunk("REPORTE DE CONTROL DE ASISTENCIA",
            new Font(Font.HELVETICA, 12, Font.BOLD));
    Chunk labelOficina = new Chunk(nombreGrupoOficina, font);
    Chunk labelFechaInicio = new Chunk("FECHA INICIO:        ", font);
    Chunk labelFechaFin = new Chunk("       FECHA FIN: ", font);
    //Chunk labelUsuario = new Chunk("USUARIO: ",font);

    Chunk nombreOficina = new Chunk(oficina, new Font(Font.HELVETICA, 10));
    Chunk nombreFechaInicio = new Chunk(ReporteUtil.obtenerFechaFormateada(fechaInicio, "/").toUpperCase(),
            new Font(Font.HELVETICA, 10));
    Chunk nombreFechaFin = new Chunk(ReporteUtil.obtenerFechaFormateada(fechaFin, "/").toUpperCase(),
            new Font(Font.HELVETICA, 10));
    //Chunk nombreUsuario = new Chunk(usuario.toUpperCase(), new Font(Font.HELVETICA,10));

    Paragraph pNombreReporte = new Paragraph(nombreReporte);
    pNombreReporte.setAlignment(1);
    documento.add(pNombreReporte);
    documento.add(ReporteUtil.darEspaciado(25));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelOficina, nombreOficina)));
    documento.add(ReporteUtil.darEspaciado(15));
    if (tipo == "P") {
        Chunk labelDniEmpleado = new Chunk("DNI:                           ", font);
        Chunk labelNombreEmpleado = new Chunk("NOMBRE:                ", font);
        Empleado empleado = ec.buscarPorDni(dnis.get(0));
        Chunk nombreDni = new Chunk(empleado.getNroDocumento(), new Font(Font.HELVETICA, 10));
        Chunk nombreEmpleado = new Chunk(empleado.getApellidoPaterno() + " " + empleado.getApellidoMaterno()
                + " " + empleado.getNombre(), new Font(Font.HELVETICA, 10));
        documento.add(new Paragraph(ReporteUtil.unirChunks(labelNombreEmpleado, nombreEmpleado)));
        documento.add(ReporteUtil.darEspaciado(15));
        documento.add(new Paragraph(ReporteUtil.unirChunks(labelDniEmpleado, nombreDni)));
        documento.add(ReporteUtil.darEspaciado(15));
    }
    documento.add(new Paragraph(
            ReporteUtil.unirChunks(labelFechaInicio, nombreFechaInicio, labelFechaFin, nombreFechaFin)));
    documento.add(ReporteUtil.darEspaciado(15));

    //documento.add(new Paragraph(ReporteUtil.unirChunks(labelFechaFin,nombreFechaFin)));
    //documento.add(ReporteUtil.darEspaciado(15));
    //documento.add(new Paragraph(ReporteUtil.unirChunks(labelUsuario,nombreUsuario)));
    documento.add(ReporteUtil.darEspaciado(20));
    PdfPTable tabla = new rptAsistenciaTotal().crearTabla(dnis, fechaInicio, fechaFin, isSelectedComp,
            isSelectedHoraM, tipo);
    documento.add(tabla);
    documento.close();
    try {
        File path = new File(nombreFile);
        Desktop.getDesktop().open(path);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:vistas.reportes.procesos.rptTardanzaTotal.java

public void crearPdf(String nombreFile, List<String> dnis, Date fechaInicio, Date fechaFin, String oficina,
        String tipo, String usuario) throws IOException, DocumentException {
    Document documento = new Document(PageSize.A4.rotate());
    PdfWriter.getInstance(documento, new FileOutputStream(nombreFile));
    documento.open();/*from   w  w w . j ava 2 s  .  com*/
    Image cabecera = Image.getInstance("img/cabecera.png");
    cabecera.setAlignment(1);
    documento.add(cabecera);
    String nombreGrupoOficina = "";
    if (tipo == "O") {
        nombreGrupoOficina = "OFICINA: ";
    } else {
        nombreGrupoOficina = "GRUPO HORARIO: ";
    }
    Font font = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
    Chunk nombreReporte = new Chunk("REPORTE DE CONSOLIDADO DE TARDANZA", font);
    Chunk labelOficina = new Chunk(nombreGrupoOficina, font);
    Chunk labelMes = new Chunk("MES: ", font);
    Chunk labelUsuario = new Chunk("USUARIO: ", font);

    Chunk nombreOficina = new Chunk(oficina, new Font(Font.TIMES_ROMAN, 10));
    Chunk nombreMes = new Chunk(ReporteUtil.obtenerNombreMes(fechaInicio).toUpperCase(),
            new Font(Font.TIMES_ROMAN, 10));
    Chunk nombreUsuario = new Chunk(usuario.toUpperCase(), new Font(Font.TIMES_ROMAN, 10));

    documento.add(new Paragraph(nombreReporte));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelOficina, nombreOficina)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelMes, nombreMes)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelUsuario, nombreUsuario)));
    documento.add(ReporteUtil.darEspaciado(20));
    PdfPTable tabla = new rptTardanzaTotal().crearTabla(dnis, fechaInicio, fechaFin);
    documento.add(tabla);
    documento.close();
    try {
        File path = new File(nombreFile);
        Desktop.getDesktop().open(path);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}