Example usage for com.lowagie.text Paragraph add

List of usage examples for com.lowagie.text Paragraph add

Introduction

In this page you can find the example usage for com.lowagie.text Paragraph add.

Prototype

public boolean add(Object o) 

Source Link

Document

Adds an Object to the Paragraph.

Usage

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

License:GNU General Public License

@SuppressWarnings("unchecked")
private void exportMessage(Set<ClientMessage> cm, Document d, boolean isForward) throws DocumentException {

    LineSeparator hr = new LineSeparator();
    StyleSheet styles = new StyleSheet();
    Font fnormal = new Font(Font.HELVETICA, 9, Font.NORMAL);
    Font fbold = new Font(Font.HELVETICA, 9, Font.BOLD);

    Iterator<ClientMessage> it = cm.iterator();
    Cell c = null;/*  w ww  .  j av a  2 s .  c  om*/
    while (it.hasNext()) {
        ClientMessage fwdCm = it.next();
        if (isForward) {
            c = new Cell();
        }

        // Subject (only if isForward)
        if (isForward) {
            String subjectText = fwdCm.getSubject();
            String dateText = formatDate(fwdCm.getDate());
            Chunk subject = new Chunk(subjectText, fbold);
            Chunk date = new Chunk(dateText, fbold);
            Paragraph subjectPar = new Paragraph(subject + ", " + date);
            subjectPar.setIndentationLeft(5.0f);
            c.add(subjectPar);
            c.add(Chunk.NEWLINE);
        } else {
            String dateText = formatDate(fwdCm.getDate());
            Chunk date = new Chunk(dateText, fbold);
            Paragraph datePar = new Paragraph(date);
            datePar.setAlignment(Element.ALIGN_RIGHT);
            d.add(datePar);
        }

        // Sender
        String senderText = formatAddress(fwdCm.getSender());
        Chunk sender = new Chunk(senderText, fbold);
        sender.setTextRise(10.0f);
        Paragraph senderPar = new Paragraph(sender);
        if (isForward) {
            senderPar.setIndentationLeft(5.0f);
            c.add(senderPar);
        } else {
            d.add(senderPar);
        }

        appendRecipients(d, c, isForward, "To:", fwdCm.getTo());
        appendRecipients(d, c, isForward, "Cc:", fwdCm.getCc());
        appendRecipients(d, c, isForward, "Bcc:", fwdCm.getBcc());
        if (isForward) {
            c.add(Chunk.NEWLINE);
        }

        // Body
        String bodyText = fwdCm.getBody().getCleanHtml();
        Paragraph bodyPar = new Paragraph();
        bodyPar.setFont(fnormal);
        if (bodyText != null && !bodyText.isEmpty()) {
            try {
                List<Element> objects = HTMLWorker.parseToList(new StringReader(bodyText), styles);
                for (Iterator<Element> iterator = objects.iterator(); iterator.hasNext();) {
                    Element el = iterator.next();
                    if (!(el instanceof Image)) {
                        // bodyPar.add(el);
                        if (isForward) {
                            c.add(el);
                        } else {
                            bodyPar.add(el);
                        }
                    }
                }
            } catch (Exception e) {
                logger.warn("Cannot generate pdf from html body use plain text instead", e);
                // bodyPar.add(fwdCm.getBody().getPlain());
                if (isForward) {
                    Chunk t = new Chunk(fwdCm.getBody().getPlain());
                    t.setFont(fnormal);
                    c.add(t);
                } else {
                    bodyPar.add(fwdCm.getBody().getPlain());
                }
            }
        } else {
            if (isForward) {
                Chunk t = new Chunk(fwdCm.getBody().getPlain());
                t.setFont(fnormal);
                c.add(t);
            } else {
                bodyPar.add(fwdCm.getBody().getPlain());
            }
        }

        if (isForward) {
            // c.add(bodyPar);
            Table t = new Table(1);
            t.setPadding(5);
            t.setBackgroundColor(new Color(242, 242, 242));
            t.addCell(c);
            d.add(t);
        } else {
            bodyPar.setIndentationLeft(15.0f);
            d.add(bodyPar);
        }

        if (fwdCm.getFwdMessages() != null) {
            this.exportMessage(fwdCm.getFwdMessages(), d, true);
        }
        d.add(hr);
    }

}

From source file:fr.opensagres.xdocreport.itext.extension.ExtendedSection.java

License:Open Source License

public static Paragraph constructTitle(IParagraphFactory factory, Paragraph ancestorTitle, ArrayList numbers,
        int numberDepth, int numberStyle, PdfPCell cell) {
    if (ancestorTitle != null && cell != null) {
        Paragraph newTitle = factory.createParagraph();
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(100f);/*from  www  .  j a va  2 s.  co  m*/
        cell.addElement(ancestorTitle);
        table.addCell(cell);
        newTitle.add(table);
        return newTitle;
    }
    return ancestorTitle;
}

From source file:fr.opensagres.xdocreport.itext.extension.NestedTable2.java

License:Open Source License

public static void main(String[] args) {
    Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
    try {//www.  j  ava 2 s.  c o m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("NestedTable2.pdf"));
        document.open();

        PdfPTable table = new PdfPTable(1);

        PdfPTable nestedTable = new PdfPTable(2);
        PdfPCell cell1 = new PdfPCell();
        cell1.addElement(new Chunk("cell1"));
        nestedTable.addCell(cell1);

        PdfPCell cell2 = new PdfPCell();
        cell2.addElement(new Chunk("cell2"));
        nestedTable.addCell(cell2);

        Paragraph paragraph = new Paragraph();
        paragraph.add(new Chunk("eeeeeeeeee"));
        paragraph.add(nestedTable);

        PdfPCell cell = new PdfPCell(paragraph);
        //cell.addElement( nestedTable );
        //cell.addElement( new Chunk("cell3") );
        //cell.
        table.addCell(cell);

        document.add(table);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:fr.opensagres.xdocreport.itext.extension.TableWithVerticalAlignment.java

License:Open Source License

public static void main(String[] args) {
    Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
    try {//from   w ww .j  av a 2s  .co m
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("TableWithVerticalAlignment.pdf"));

        document.open();

        PdfPTable table = new PdfPTable(1);
        // PdfPCell cell1 = new PdfPCell();
        // cell1.setVerticalAlignment( Element.ALIGN_BOTTOM );
        // //cell1.setMinimumHeight( 100f );
        // cell1.addElement( new Chunk( "cell1" ) );
        // table.addCell( cell1 );

        PdfPCell cell2 = new PdfPCell();
        Paragraph p = new Paragraph();
        p.add(new Chunk("cellp&"));

        cell2.addElement(p);
        cell2.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell2.setMinimumHeight(38f);
        table.addCell(cell2);

        document.add(table);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:fr.paris.lutece.plugins.directory.modules.pdfproducer.utils.PDFUtils.java

License:Open Source License

/**
 * Build the fields in a whole paragraph.
 * @param listRecordFields the list of record fields
 * @param entry the entry/*w  w w . j  a  v  a2 s . c om*/
 * @param locale the locale
 * @param phraseEntry the phrase entry
 * @param paragraphEntry the paragraph entry
 * @param bExtractNotFilledField if true, extract empty fields, false
 * @throws DocumentException exception if there is an error
 */
private static void builFieldsInParagraph(List<RecordField> listRecordFields, IEntry entry, Locale locale,
        Phrase phraseEntry, Paragraph paragraphEntry, Boolean bExtractNotFilledField) throws DocumentException {
    com.lowagie.text.List listValue = new com.lowagie.text.List(true);
    listValue.setPreSymbol("- ");
    listValue.setNumbered(false);
    listValue.setIndentationLeft(DirectoryUtils
            .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_MARGIN_LEFT_ENTRY_VALUE)));

    Font fontEntryValue = new Font(
            DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_NAME)),
            DirectoryUtils
                    .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_SIZE_ENTRY_VALUE)),
            DirectoryUtils
                    .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_STYLE_ENTRY_VALUE)));

    for (RecordField recordField : listRecordFields) {
        String strValue = StringUtils.EMPTY;

        if (entry instanceof EntryTypeDownloadUrl && StringUtils.isNotBlank(recordField.getFileName())) {
            strValue = recordField.getFileName();
        } else if ((recordField.getFile() != null)
                && StringUtils.isNotBlank(recordField.getFile().getTitle())) {
            // The thumbnails and big thumbnails should not be displayed
            if (!((StringUtils.isNotBlank(recordField.getValue())
                    && recordField.getValue().startsWith(FIELD_THUMBNAIL))
                    || (StringUtils.isNotBlank(recordField.getValue())
                            && recordField.getValue().startsWith(FIELD_BIG_THUMBNAIL)))) {
                strValue = recordField.getFile().getTitle();
            }
        } else {
            strValue = entry.convertRecordFieldValueToString(recordField, locale, false, false);
        }

        if (bExtractNotFilledField || (!bExtractNotFilledField && StringUtils.isNotBlank(strValue))) {
            listValue.add(new ListItem(strValue, fontEntryValue));
        }
    }

    if (bExtractNotFilledField
            || (!bExtractNotFilledField && CollectionUtils.isNotEmpty(listValue.getItems()))) {
        paragraphEntry.add(phraseEntry);
        paragraphEntry.add(listValue);
    }
}

From source file:fr.paris.lutece.plugins.directory.modules.pdfproducer.utils.PDFUtils.java

License:Open Source License

/**
 * Build the fields in a single paragraph.
 * @param listRecordFields the list of record fields
 * @param entry the entry// w w w.  j av  a2s . c om
 * @param locale the locale
 * @param phraseEntry the phrase entry
 * @param paragraphEntry the paragraph entry
 * @param bExtractNotFilledField if true, extract empty fields, false
 * @throws DocumentException exception if there is an error
 */
private static void builFieldsInSinglePhrase(List<RecordField> listRecordFields, IEntry entry, Locale locale,
        Phrase phraseEntry, Paragraph paragraphEntry, Boolean bExtractNotFilledField) throws DocumentException {
    RecordField recordField = listRecordFields.get(0);
    Chunk chunkEntryValue = null;
    Font fontEntryValue = new Font(
            DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_NAME)),
            DirectoryUtils
                    .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_SIZE_ENTRY_VALUE)),
            DirectoryUtils
                    .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_STYLE_ENTRY_VALUE)));

    if (entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeDownloadUrl) {
        if (StringUtils.isNotBlank(recordField.getFileName())) {
            chunkEntryValue = new Chunk(recordField.getFileName());
        } else {
            chunkEntryValue = new Chunk(StringUtils.EMPTY);
        }
    } else if (entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeGeolocation) {
        for (RecordField recordFieldGeo : listRecordFields) {
            if ((recordFieldGeo.getField() != null)
                    && EntryTypeGeolocation.CONSTANT_ADDRESS.equals(recordFieldGeo.getField().getTitle())) {
                chunkEntryValue = new Chunk(
                        entry.convertRecordFieldValueToString(recordFieldGeo, locale, false, false),
                        fontEntryValue);
            }
        }
    } else if (entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeCheckBox
            || entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeSelect
            || entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeRadioButton) {
        chunkEntryValue = new Chunk(entry.convertRecordFieldTitleToString(recordField, locale, false),
                fontEntryValue);
    } else if (entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeFile
            || entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeImg) {
        String strFileName = StringUtils.EMPTY;

        if ((recordField.getFile() != null) && StringUtils.isNotBlank(recordField.getFile().getTitle())) {
            // The thumbnails and big thumbnails should not be displayed
            if (!((StringUtils.isNotBlank(recordField.getValue())
                    && recordField.getValue().startsWith(FIELD_THUMBNAIL))
                    || (StringUtils.isNotBlank(recordField.getValue())
                            && recordField.getValue().startsWith(FIELD_BIG_THUMBNAIL)))) {
                strFileName = recordField.getFile().getTitle();
            }
        }

        chunkEntryValue = new Chunk(strFileName, fontEntryValue);
    } else if (entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeRichText) {
        String strValue = entry.convertRecordFieldValueToString(recordField, locale, false, false);
        strValue = StringUtils.defaultString(HtmlUtils.htmlUnescape(strValue)).replaceAll("<[^>]*>", "");
        chunkEntryValue = new Chunk(strValue, fontEntryValue);
    } else {
        chunkEntryValue = new Chunk(entry.convertRecordFieldValueToString(recordField, locale, false, false),
                fontEntryValue);
    }

    if (chunkEntryValue != null) {
        if (bExtractNotFilledField
                || (!bExtractNotFilledField && StringUtils.isNotBlank(chunkEntryValue.getContent()))) {
            phraseEntry.add(chunkEntryValue);
            paragraphEntry.add(phraseEntry);
        }
    }
}

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

License:Apache License

/**
 * /*from   w w w  .  ja va  2 s . com*/
 * @param document pdf
 */
public void creerPdfTrombinoscope(final Document document, List<Inscrit> listeInscrits,
        List<String> listecodind, String libelle, String annee) {

    //configuration des fonts
    Font normal = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.NORMAL);
    Font normalbig = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD);
    Font legerita = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.ITALIC);
    Font leger = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.NORMAL);
    Font headerbig = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD);
    Font header = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD);

    //pieds de pages:
    String part = "";
    Date d = new Date();
    DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    String date = dateFormat.format(d);
    //alignement des libells du pied de page:
    String partie1 = libelle + " " + annee;
    String partie2 = applicationContext.getMessage("pdf.edition.date", null, Locale.getDefault()) + " : "
            + date;
    if (partie1.length() < ECARTEMENT_PIED_PAGE_PDF) {
        int diff = ECARTEMENT_PIED_PAGE_PDF - partie1.length();
        for (int i = 0; i < diff; i++) {
            partie1 = partie1 + " ";

        }
    }
    if (partie2.length() < ECARTEMENT_PIED_PAGE_PDF) {
        int diff = ECARTEMENT_PIED_PAGE_PDF - partie2.length();
        for (int i = 0; i < diff; i++) {
            partie2 = " " + partie2;
        }
    }

    //cration du pied de page:
    Phrase phra = new Phrase(partie1 + "-" + part + " Page", legerita);
    Phrase phra2 = new Phrase("- " + partie2, legerita);
    HeaderFooter hf = new HeaderFooter(phra, phra2);
    hf.setAlignment(HeaderFooter.ALIGN_CENTER);
    document.setFooter(hf);

    //ouverte du document.
    document.open();

    try {

        //ajout image test
        if (configController.getLogoUniversitePdf() != null
                && !configController.getLogoUniversitePdf().equals("")) {
            Image image1 = Image.getInstance(configController.getLogoUniversitePdf());
            float scaleRatio = 40 / image1.getHeight();
            float newWidth = scaleRatio * image1.getWidth();
            image1.scaleAbsolute(newWidth, 40);
            image1.setAbsolutePosition(800 - newWidth, 528);
            document.add(image1);
        }

        Paragraph p = new Paragraph(applicationContext
                .getMessage("pdf.trombinoscope.title", null, Locale.getDefault()).toUpperCase(), headerbig);
        p.setIndentationLeft(15);
        document.add(p);

        Paragraph p3 = new Paragraph(
                applicationContext.getMessage("pdf.promotion", null, Locale.getDefault()) + " : " + libelle,
                normal);
        p3.setIndentationLeft(15);
        document.add(p3);

        Paragraph p2 = new Paragraph(
                applicationContext.getMessage("pdf.year", null, Locale.getDefault()) + " : " + annee, normal);
        p2.setIndentationLeft(15);
        document.add(p2);

        Paragraph p4 = new Paragraph(applicationContext.getMessage("pdf.nbinscrits", null, Locale.getDefault())
                + " : " + listecodind.size(), normal);
        p4.setIndentationLeft(15);
        document.add(p4);

        Paragraph p03 = new Paragraph(
                applicationContext.getMessage("pdf.edition.date", null, Locale.getDefault()) + " : " + date
                        + "\n\n",
                normal);
        p03.setIndentationLeft(15);
        document.add(p03);

        PdfPTable table = new PdfPTable(NB_INSCRITS_LIGNE_TROMBI_PDF);
        table.setWidthPercentage(100f);

        int compteur = 0;
        Rectangle border = new Rectangle(0f, 0f);
        border.setBorderColorLeft(Color.WHITE);
        border.setBorderColorBottom(Color.WHITE);
        border.setBorderColorRight(Color.WHITE);
        border.setBorderColorTop(Color.WHITE);

        String tabNom[] = new String[NB_INSCRITS_LIGNE_TROMBI_PDF];
        String tabNum[] = new String[NB_INSCRITS_LIGNE_TROMBI_PDF];
        //insertion de listeInscrits dans listeInscritstrombi si le trombinoscope n'est pas decoup
        /*   if (listeInscritsTrombi == null || listeInscritsTrombi.size() == 0) {
           ArrayList<Inscrit> listeInscritsbis = (ArrayList<Inscrit>) listeInscrits.clone();
           listeInscritsTrombi.add(listeInscritsbis);
        }*/
        //nombre d'etudiants insrer a la suite dans le pdf:
        int nbEtudiantInsere = 0;
        for (Inscrit inscrit : listeInscrits) {
            if (listecodind.contains(inscrit.getCod_ind())) {
                nbEtudiantInsere++;
                //on en a insr le plus possible d'un coup (pour eviter un timeout du server 
                //de photos sur les premieres photos 
                //au moment de l'insertion dans le pdf : document.add() ):
                //on insere la table dans le pdf et on recommence une nouvelle table
                if (nbEtudiantInsere > (NB_INSCRITS_LIGNE_TROMBI_PDF
                        * NB_LIGNE_INSEREE_TROMBI_PDF_A_LA_SUITE)) {
                    document.add(table);
                    document.newPage();
                    table = new PdfPTable(NB_INSCRITS_LIGNE_TROMBI_PDF);
                    table.setWidthPercentage(100f);
                    tabNom = new String[NB_INSCRITS_LIGNE_TROMBI_PDF];
                    tabNum = new String[NB_INSCRITS_LIGNE_TROMBI_PDF];
                    nbEtudiantInsere = 1;
                    compteur = 0;
                }

                tabNom[compteur] = "" + inscrit.getPrenom() + " \n" + inscrit.getNom() + "\n";
                tabNum[compteur] = "" + inscrit.getCod_etu();

                compteur++;

                //String foto = photo.getUrlPhotoTrombinoscopePdf(inscrit.getCod_ind(), inscrit.getCod_etu());
                String foto = GenericUI.getCurrent().getPhotoProvider().getUrlPhotoTrombinoscopePdf(
                        inscrit.getCod_ind(), inscrit.getCod_etu(), userController.isEnseignant(),
                        userController.getCurrentUserName());
                Image photo = Image.getInstance(foto);
                photo.scaleAbsolute(85, 107);

                PdfPCell cell = new PdfPCell(photo);
                cell.cloneNonPositionParameters(border);
                table.addCell(cell);

                if (compteur == NB_INSCRITS_LIGNE_TROMBI_PDF) {
                    for (int i = 0; i < NB_INSCRITS_LIGNE_TROMBI_PDF; i++) {
                        Phrase ph = new Phrase(tabNom[i], normalbig);
                        Phrase ph2 = new Phrase(tabNum[i], leger);
                        Paragraph pinscrit = new Paragraph();
                        pinscrit.add(ph);
                        pinscrit.add(ph2);
                        PdfPCell celltext = new PdfPCell(pinscrit);
                        celltext.cloneNonPositionParameters(border);
                        table.addCell(celltext);
                    }
                    compteur = 0;
                }

            }

        }
        if (compteur > 0) {
            for (int i = compteur; i < NB_INSCRITS_LIGNE_TROMBI_PDF; i++) {
                PdfPCell cell = new PdfPCell();
                cell.cloneNonPositionParameters(border);
                table.addCell(cell);
            }

            for (int i = 0; i < compteur; i++) {
                Phrase ph = new Phrase(tabNom[i], normalbig);
                Phrase ph2 = new Phrase(tabNum[i], leger);
                Paragraph pinscrit = new Paragraph();
                pinscrit.add(ph);
                pinscrit.add(ph2);
                PdfPCell celltext = new PdfPCell(pinscrit);
                celltext.cloneNonPositionParameters(border);
                table.addCell(celltext);
            }

            for (int i = compteur; i < NB_INSCRITS_LIGNE_TROMBI_PDF; i++) {
                PdfPCell cell = new PdfPCell();
                cell.cloneNonPositionParameters(border);
                table.addCell(cell);
            }

        }

        document.add(table);

    } catch (BadElementException e) {
        LOG.error("Erreur  la gnration du certificat : BadElementException ", e);
    } catch (MalformedURLException e) {
        LOG.error("Erreur  la gnration du certificat : MalformedURLException ", e);
    } catch (IOException e) {
        LOG.error("Erreur  la gnration du certificat : IOException ", e);
    } catch (DocumentException e) {
        LOG.error("Erreur  la gnration du certificat : DocumentException ", e);
    }

    // step 6: fermeture du document.
    document.close();

}

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

public void imprimirReporte() {
    //DateFormat dfDateFull = DateFormat.getDateInstance(DateFormat.FULL);
    try {//from  w  ww  . j  av a2 s.  co  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:gov.utah.health.uper.reports.Registration.java

/**
 * Builds Header Information/*from   ww w .ja  v  a 2 s .  c o m*/
 * @param document
 * @throws DocumentException
 */
private void buildHeader(Document document, ApplicationBean app) throws DocumentException {

    Paragraph preface = new Paragraph("Utah Plant Extract Registry", subFont12);
    preface.setAlignment(Element.ALIGN_CENTER);
    document.add(preface);

    preface = new Paragraph("Issue Date:  ", subFont12);
    preface.add(app.getIssuedDate());
    preface.setAlignment(Element.ALIGN_CENTER);
    document.add(preface);

    preface = new Paragraph("Expiration Date:  ", subFont12);
    preface.add(app.getExpirationDate());

    preface.setAlignment(Element.ALIGN_CENTER);
    document.add(preface);

    preface = new Paragraph("Registration Number: ", subFont12);
    preface.add(app.getStateFileNumber());
    preface.setAlignment(Element.ALIGN_CENTER);
    document.add(preface);
    addSpacing(document);

}

From source file:gov.utah.health.uper.reports.Registration.java

private void buildPatient(Document document, PatientBean pt) throws DocumentException {
    Paragraph preface = new Paragraph(PATIENT, normalFontBold);
    preface.setAlignment(Element.ALIGN_LEFT);
    document.add(preface);//from  w w w .j  av a  2  s. c  o m

    preface = new Paragraph("Name: ", normalFontBold);
    preface.add(pt.getFirstName() + " " + pt.getLastName());
    preface.setAlignment(Element.ALIGN_LEFT);
    document.add(preface);

    preface = new Paragraph("Date of Birth: ", normalFontBold);
    preface.add(pt.getDob());
    preface.setAlignment(Element.ALIGN_LEFT);
    document.add(preface);

    preface = new Paragraph("Address: ", normalFontBold);
    preface.setAlignment(Element.ALIGN_LEFT);
    StringBuilder sb = new StringBuilder(pt.getAddressCurrent());
    sb.append(" ");
    sb.append(pt.getCityCurrent());
    sb.append(", ");
    sb.append(pt.getStateCurrent());
    sb.append(" ");
    sb.append(pt.getZipCurrent());

    preface.add(sb.toString());
    document.add(preface);
    addSpacing(document);

}