Example usage for com.itextpdf.text FontFactory getFont

List of usage examples for com.itextpdf.text FontFactory getFont

Introduction

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

Prototype


public static Font getFont(final String fontname, final float size, final int style) 

Source Link

Document

Constructs a Font-object.

Usage

From source file:be.rheynaerde.poolsheets.configuration.defaultconfiguration.DefaultPufCompletePoolSheetConfiguration.java

License:Open Source License

@Override
public Font getSubtitleFont() {
    return FontFactory.getFont("courier", 24f, Font.BOLD);
}

From source file:bestdeal.util.genererPdf.java

public static void main(String[] args) {
    // - Paramtres de connexion  la base de donnes
    Connection connection;//from w  ww. j  a  v  a 2s .co m
    String[][] data = new String[][] { { " ", " ", " ", " ", " " }, { " ", " ", " ", " ", " " },
            { " ", " ", " ", " ", " " }, };

    try {
        String requete = "select c.nom,c.prenom,c.email,k.nom,k.prenom,k.telephone,k.adresse,k.email,d.id_deal,d.nom_deal,v.quantite,v.prix_unitaire from client c INNER JOIN voucher v on v.id_client=c.id_client INNER JOIN deal d on v.id_deal=d.id_deal INNER JOIN vendeur k on d.id_vendeur=k.id_vendeur";
        connection = MyConnection.getInstance();
        mypdf = new Document(PageSize.A4, 50, 50, 50, 50);
        File di = new File("C:/Voucher");
        File fl[] = di.listFiles();
        try {
            OutputStream file = new FileOutputStream(new File("C:/Voucher\\Voucher.pdf"));
            PdfWriter.getInstance(mypdf, file);

            mypdf.open();
            Statement stm;

            mypdf.addAuthor("Best Deal");
            mypdf.addSubject("Voucher ");
            mypdf.add(new Paragraph("Socite BestDeal"));
            mypdf.add(new Paragraph("Adresse La Chotrana ESPRIT "));
            mypdf.add(new Paragraph("TEL : xx xxx xxx"));
            mypdf.add(new Paragraph("FAX : xx xxx xxx"));
            mypdf.add(new Paragraph(
                    "                                                                                                       "
                            + new Date().toString()));
            mypdf.add(new Paragraph("  "));
            mypdf.add(new Paragraph("                                   " + "Voucher N'01",
                    FontFactory.getFont(FontFactory.HELVETICA, 21, Font.BOLDITALIC)));
            mypdf.add(new Paragraph("  "));

            mypdf.add(new Paragraph("CLIENT :",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC)));
            try {
                stm = connection.createStatement();
                ResultSet rs = stm.executeQuery(requete);

                while (rs.next()) {
                    // add a country to the document as a Chunk
                    //mypdf.add(new Chunk(rs.getString("quantite")));
                    Phrase p = new Phrase("Nom:   ");
                    Phrase p2 = new Phrase(new Chunk(rs.getString("nom")));
                    Paragraph pa = new Paragraph();
                    pa.add(p);
                    pa.add(p2);
                    mypdf.add(pa);

                    Phrase p3 = new Phrase("Prenom:  ");
                    Phrase p4 = new Phrase(new Chunk(rs.getString("prenom")));
                    Paragraph pa1 = new Paragraph();
                    pa1.add(p3);
                    pa1.add(p4);
                    mypdf.add(pa1);

                    Phrase p5 = new Phrase("Adresse:  ");
                    Phrase p6 = new Phrase(new Chunk(rs.getString("adresse")));
                    Paragraph pa2 = new Paragraph();
                    pa2.add(p5);
                    pa2.add(p6);
                    mypdf.add(pa2);

                    Phrase p7 = new Phrase("Tlphone:  ");
                    Phrase p8 = new Phrase(new Chunk(rs.getString("telephone")));
                    Paragraph pa3 = new Paragraph();
                    pa3.add(p7);
                    pa3.add(p8);
                    mypdf.add(pa3);

                    mypdf.add(new Paragraph("  "));

                    mypdf.add(new Paragraph("Vendeur :",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC)));

                    Phrase p9 = new Phrase("Nom:  ");
                    Phrase p10 = new Phrase(new Chunk(rs.getString("nom")));
                    Paragraph pa4 = new Paragraph();
                    pa4.add(p9);
                    pa4.add(p10);
                    mypdf.add(pa4);

                    Phrase p11 = new Phrase("Prnom:  ");
                    Phrase p12 = new Phrase(new Chunk(rs.getString("prenom")));
                    Paragraph pa5 = new Paragraph();
                    pa5.add(p11);
                    pa5.add(p12);
                    mypdf.add(pa5);

                    Phrase p13 = new Phrase("Tlphone:  ");
                    Phrase p14 = new Phrase(new Chunk(rs.getString("telephone")));
                    Paragraph pa6 = new Paragraph();
                    pa6.add(p13);
                    pa6.add(p14);
                    mypdf.add(pa6);

                    Phrase p15 = new Phrase("Adresse:  ");
                    Phrase p16 = new Phrase(new Chunk(rs.getString("adresse")));
                    Paragraph pa7 = new Paragraph();
                    pa7.add(p15);
                    pa7.add(p16);
                    mypdf.add(pa7);

                    Phrase p17 = new Phrase("Email:  ");
                    Phrase p18 = new Phrase(new Chunk(rs.getString("email")));
                    Paragraph pa8 = new Paragraph();
                    pa8.add(p17);
                    pa8.add(p18);
                    mypdf.add(pa8);

                    mypdf.add(new Paragraph("  "));
                    mypdf.add(new Paragraph("  "));
                    mypdf.add(new Paragraph("  "));

                    for (int i = 0; i < rs.getRow(); i++) {
                        for (int j = 0; j < data[i].length - 1; j++) {
                            data[i][j] = rs.getString(j + 9);
                            // if (j==3)
                            //     data[i][4]= Float.parseFloat(data[i][3])*Integer.parseInt(data[i][2])+"";
                        }
                    }

                    for (int i = 0; i < rs.getRow(); i++) {
                        float s = Integer.parseInt(data[i][2].trim()) * Float.parseFloat(data[i][3].trim());
                        data[i][4] = s + "";
                    }

                    //mypdf.add(new Phrase("nom"));
                    //mypdf.add(new  Chunk(rs.getString("nom")));
                    //mypdf.add( new Paragraph("nom:", new Chunk(rs.getString("nom"))));
                    //mypdf.add(new Chunk(" "));
                    //Chunk id = new Chunk(rs.getString("id"));
                    // with a background color
                    //id.setBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f);
                    // and a text rise
                    //id.setTextRise(6);
                    //  mypdf.add(id);
                    mypdf.add(Chunk.NEWLINE);
                }

            } catch (SQLException ex) {
                Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
            }
            // mypdf.add(new Paragraph("Nom "));
            //  mypdf.add(new Paragraph("Prenom "));
            // mypdf.add(new Paragraph("Adresse "));
            //mypdf.add(new Paragraph("Tlphone "));

            // mypdf.add(new Paragraph("Nom "));
            // mypdf.add(new Paragraph("Nom de la socit "));
            //  mypdf.add(new Paragraph("Adresse "));
            // mypdf.add(new Paragraph("Tlphone "));
            // mypdf.add(new Paragraph("  "));

            String[] headers = new String[] { "  Id_deal", "   Nom Deal", "   Quantit", "    Prix unitaire",
                    "   Prix total" };
            PdfPTable table = new PdfPTable(headers.length);
            for (int i = 0; i < headers.length; i++) {
                String header = headers[i];
                PdfPCell cell = new PdfPCell();
                cell.setGrayFill(0.9f);
                cell.setPhrase(new Phrase(header.toUpperCase()));
                table.addCell(cell);
            }
            table.completeRow();
            for (int i = 0; i < data.length; i++) {
                for (int j = 0; j < data[i].length; j++) {
                    String datum = data[i][j];
                    PdfPCell cell = new PdfPCell();
                    cell.setPhrase(new Phrase(datum.toUpperCase()));
                    table.addCell(cell);
                }
                table.completeRow();
            }

            mypdf.add(table);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
        }

        mypdf.add(new Paragraph(" "));
        mypdf.add(new Paragraph(" "));
        mypdf.add(new Paragraph(
                "Pour toute question concernant cette facture,veuillez contacter Nom,numro de tlphone,adresse de messagerie ",
                FontFactory.getFont(null, 9, Font.NORMAL)));
        mypdf.add(new Paragraph(
                "                                                      Merci pour votre confiance",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLDITALIC)));
        mypdf.add(new Paragraph("      "));
        mypdf.add(new Paragraph("  "));
        mypdf.add(new Paragraph("  "));

        mypdf.close();

    } catch (DocumentException ex) {
        Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:billerfx.FXMLBillController.java

File generatePDF() {
    File fi = null;/*from  ww  w.j  a va 2 s  .com*/
    try {
        Stage gg = ((Stage) imv.getParent().getScene().getWindow());
        fi = File.createTempFile("billerfx_" + gg.getTitle(), ".pdf");
        fi.deleteOnExit();

        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(fi));
        Rectangle r = new RectangleReadOnly(207, 575);
        document.setPageSize(r);
        document.setMargins(15, 15, 0, 0);
        document.open();
        Font fontbold = FontFactory.getFont("Times-Roman", 10, Font.NORMAL);
        Font fontbold2 = FontFactory.getFont("Times-Roman", 9, Font.NORMAL);

        String[] ll = Database.getCurrentSettings();
        String ss = "-----------------------------------------------------\n";
        ss += ll[0] + "\nAddress: " + ll[1] + "\nPhone: " + ll[2] + "\n";
        String kk = Calendar.getInstance().get(Calendar.AM_PM) == Calendar.AM ? "AM"
                : (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.PM ? "PM" : "");
        ss += Calendar.getInstance().get(Calendar.DATE) + "/" + (1 + Calendar.getInstance().get(Calendar.MONTH))
                + "/" + Calendar.getInstance().get(Calendar.YEAR) + " at "
                + Calendar.getInstance().get(Calendar.HOUR) + ":" + Calendar.getInstance().get(Calendar.MINUTE)
                + " " + kk + "\n";
        ss += "Table No. " + c.getText() + "     Bill No. " + a.getText() + "\n";
        ss += "-----------------------------------------------------\n";
        Paragraph para = new Paragraph(ss, fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        float[] columnWidths = { 3f, 1f };
        table.setWidths(columnWidths);
        PdfPCell defaultCell = table.getDefaultCell();
        defaultCell.setBorder(PdfPCell.NO_BORDER);

        ObservableList ob = map.get(Integer.parseInt(gg.getTitle()));
        for (int i = 0; i < ob.size(); i++) {
            Item2 ii = (Item2) ob.get(i);
            String s1 = ii.getQuantity() + " x " + ii.getName();
            String s2 = "Rs. " + ii.getTotal();
            Paragraph para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            Paragraph para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            PdfPCell cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            PdfPCell cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }
        document.add(table);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(columnWidths);
        defaultCell = table.getDefaultCell();
        defaultCell.setBorder(PdfPCell.NO_BORDER);

        String s1 = "Total:";
        String s2 = "Rs. " + h.getText();
        Paragraph para1 = new Paragraph(s1, fontbold2);
        para1.setAlignment(Paragraph.ALIGN_LEFT);
        Paragraph para2 = new Paragraph(s2, fontbold2);
        para2.setAlignment(Paragraph.ALIGN_RIGHT);
        PdfPCell cell1 = new PdfPCell(para1);
        cell1.setBorder(PdfPCell.NO_BORDER);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        PdfPCell cell2 = new PdfPCell(para2);
        cell2.setBorder(PdfPCell.NO_BORDER);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell1);
        table.addCell(cell2);

        if (Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()) > 0.0) {
            s1 = "Discount:";
            s2 = "Rs. " + BillerFX.df.format(Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()));
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        if (ll[7].equals("1")) {
            s1 = ll[3];
            s2 = "Rs. " + k.getText();
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        if (ll[8].equals("1")) {
            s1 = ll[4];
            s2 = "Rs. " + l.getText();
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        s1 = "Grand Total:";
        s2 = "Rs. " + m.getText();
        para1 = new Paragraph(s1, fontbold2);
        para1.setAlignment(Paragraph.ALIGN_LEFT);
        para2 = new Paragraph(s2, fontbold2);
        para2.setAlignment(Paragraph.ALIGN_RIGHT);
        cell1 = new PdfPCell(para1);
        cell1.setBorder(PdfPCell.NO_BORDER);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell2 = new PdfPCell(para2);
        cell2.setBorder(PdfPCell.NO_BORDER);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell1);
        table.addCell(cell2);

        document.add(table);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        fontbold2 = FontFactory.getFont("Times-Roman", 8, Font.NORMAL);
        para = new Paragraph(
                "Thank You.\nThis invoice was created using BillerFX.\n (BillerFX Contact: ayushmaanbhav1008@gmail.com)\n",
                fontbold2);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        document.close();
    } catch (Exception mm) {
    }
    return fi;
}

From source file:bladwin.web.reg.regPDF.java

public void genPed(String loc, regMgr regMgr, dbMgrInterface db) {
    Document document = null;/*from  ww w .j a  v  a 2  s.c  om*/
    //String loc = "C:/_bisc/_javaApps/jlData/jvp/CellWidths.pdf";

    //regMgr.getCustomerRegBean().setPdf(loc);
    try {

        document = new Document(PageSize.A4, 30, 30, 30, 30);
        PdfWriter.getInstance(document, new FileOutputStream(loc));
        document.open();
        customerRegBean r = regMgr.getCustomerRegBean();
        customerBean c = regMgr.getCustomerBean();
        customerBean a = new custObj().getcustomerBean(r.getRegCustId(), db);
        mgnLookupBean bean = new mgnLookupObj().getLookupBean(-947, db);
        Paragraph pg;
        pg = new Paragraph(r.getLookupDesc());
        pg.setAlignment(Paragraph.ALIGN_CENTER);
        pg.setFont(FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
        document.add(getHeader(r.getLookupDesc()));
        document.add(getHeader("BALDWIN BLAZERS TRACK CLUB"));
        document.add(getHeader("REGISTRATION"));
        pg = new Paragraph("\n\r");
        document.add(pg);
        // -------------------------------------------------------
        document.add(genAthleteInfo(r, a));
        pg = new Paragraph("\n\r");
        document.add(pg);
        document.add(genParentInfo(c));
        pg = new Paragraph("\n\r");
        document.add(pg);
        document.add(genSport(r));
        pg = new Paragraph("\n\r");
        document.add(pg);
        pg = new Paragraph("PARENTS SIGNATURE");
        document.add(pg);
        pg = new Paragraph("\n\r");
        document.add(pg);
        pg = new Paragraph("\n\r");
        document.add(pg);
        pg = new Paragraph("_____________________________________________________________________");
        document.add(pg);
        pg = new Paragraph("\n\r");
        document.add(pg);
        document.add(getHeader(r.getFeeDesc() + "\n\r" + bean.getSubjectBody()));
        // ----------------------------------------------------------------------------

    } catch (DocumentException ex) {
        logger.error("DocumentException", ex);
    } catch (FileNotFoundException ex) {
        logger.error("FileNotFoundException", ex);
    } finally {
        try {
            if (document != null)
                document.close();

            //pdfFileOpen(loc);

        } catch (Exception e) {
            logger.error("FileNotFoundException", e);
        }
    }
}

From source file:bladwin.web.reg.regPDF.java

private Paragraph getHeader(String text) {
    Paragraph pg = new Paragraph(text);
    pg.setAlignment(Paragraph.ALIGN_CENTER);
    pg.setFont(FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
    return pg;/*from w  w  w .j a  va  2s. c  om*/
}

From source file:com.app.gpo.pdf.utils.PDForderLabelCard.java

License:Open Source License

@Override
protected void buildPdfDocument(Map<String, Object> model, Document doc, PdfWriter writer,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    // get data model which is passed by the Spring container
    OrderItem orderItem = (OrderItem) model.get("orderItem");
    Font font = FontFactory.getFont(FontFactory.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    font.setSize(20);//from   ww w.ja va 2 s  .co  m
    Font font2 = FontFactory.getFont(FontFactory.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    font2.setSize(12);

    String utf = orderItem.getorderItemName();
    byte[] data = utf.getBytes("CP1250");
    String ascii = new String(data);
    String code = orderItem.getorderNumber();
    Paragraph numberText = new Paragraph(code, font);
    numberText.setAlignment(Element.ALIGN_CENTER);
    doc.add(new Phrase("\n"));
    Paragraph nameText = new Paragraph(ascii, font2);
    nameText.setAlignment(Element.ALIGN_CENTER);
    // document.newPage()
    /*BarcodeEAN barcode = new BarcodeEAN();
    barcode.setCodeType(Barcode.CODE128);
    barcode.setCode(code);
    Rectangle barcodeRect = new Rectangle(400,200);
    barcode.placeBarcode(barcodeRect, BaseColor.BLACK, BaseColor.YELLOW);
    doc.add(barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY));*/
    doc.add(numberText);
    doc.add(new Phrase("\n"));
    doc.add(nameText);
}

From source file:com.app.gpo.pdf.utils.PDForderLabelCards.java

License:Open Source License

@Override
protected void buildPdfDocument(Map<String, Object> model, Document doc, PdfWriter writer,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    // get data model which is passed by the Spring container
    List<OrderItem> orderItemList = (List<OrderItem>) model.get("orderItemList");
    Font font = FontFactory.getFont(FontFactory.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    font.setSize(18);//from  w  w w  .j ava 2  s  . c o  m
    Font font2 = FontFactory.getFont(FontFactory.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    font2.setSize(12);

    Iterator<OrderItem> it = orderItemList.iterator();
    while (it.hasNext()) {
        OrderItem orderItem = it.next();
        String utf = orderItem.getorderItemName();
        byte[] data = utf.getBytes("CP1250");
        String ascii = new String(data);
        String code = orderItem.getorderNumber();
        Paragraph numberText = new Paragraph(code, font);
        numberText.setAlignment(Element.ALIGN_CENTER);
        doc.add(new Phrase("\n"));
        Paragraph nameText = new Paragraph(ascii, font2);
        nameText.setAlignment(Element.ALIGN_CENTER);
        // document.newPage()
        /*BarcodeEAN barcode = new BarcodeEAN();
        barcode.setCodeType(Barcode.CODE128);
        barcode.setCode(code);
        Rectangle barcodeRect = new Rectangle(400,200);
        barcode.placeBarcode(barcodeRect, BaseColor.BLACK, BaseColor.YELLOW);
        doc.add(barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY));*/
        doc.add(numberText);
        doc.add(new Phrase("\n"));
        doc.add(nameText);
        doc.newPage();
    }

}

From source file:com.centurylink.mdw.pdf.PdfExportHelper.java

License:Apache License

public PdfExportHelper(Project project) {
    super(project);
    chapterFont = FontFactory.getFont(FontFactory.TIMES, 20, Font.BOLD);
    sectionFont = FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLD);
    subSectionFont = FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD);
    normalFont = FontFactory.getFont(FontFactory.TIMES, 12, Font.NORMAL);
    boldFont = FontFactory.getFont(FontFactory.TIMES, 12, Font.BOLD);
    fixedWidthFont = FontFactory.getFont(FontFactory.COURIER, 11, Font.NORMAL);
}

From source file:com.centurylink.mdw.pdf.PdfExportHelper.java

License:Apache License

private void printActivity(Activity act, Chapter chapter) throws Exception {
    Section section;/*from w  ww  . j  a v a 2 s. c  o  m*/
    String tmp = ACTIVITY + act.getLogicalId() + ": \"" + act.getName().replace('\n', ' ') + "\n";
    Paragraph sTitle = new Paragraph(tmp, sectionFont);
    section = chapter.addSection(sTitle, 2);
    String summary = act.getAttribute(WorkAttributeConstant.DESCRIPTION);
    if (summary != null && summary.length() > 0) {
        printBoldParagraphs(section, summary);
    }

    String detail = act.getAttribute(WorkAttributeConstant.DOCUMENTATION);
    if (detail != null && detail.length() > 0) {
        printHtmlParagraphs(section, detail, 2);
        section.add(new Paragraph("\n", FontFactory.getFont(FontFactory.TIMES, 4, Font.NORMAL)));
    }
    if (!act.getAttributes().isEmpty()) {
        printAttributes(section, act.getAttributes(), 2);
    }
    section.add(new Paragraph("\n", normalFont));
}

From source file:com.deadormi.servlet.CreaPdfServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w  w  w .  j  a va  2 s  .  c o  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String url = request.getQueryString();
    Integer gruppo_id = Integer.parseInt(url.substring(url.indexOf("=") + 1, url.length()));

    List<Utente> iscritti = null;
    List<Post> posts = null;
    Gruppo gruppo = null;
    Utente utente = null;
    String imageUrl = null;
    String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();

    try {
        iscritti = UtenteController.getUserByGroupId(request, gruppo_id);
        gruppo = GruppoController.getGruppoById(request, gruppo_id);
    } catch (SQLException ex) {
        log.error(ex);
    }

    // step 1: creation of a document-object
    Document document = new Document();
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);
        document.open();

        String incipit = "Report del " + CurrentDate.getCurrentDate() + "\n";
        Paragraph pIncipit = new Paragraph(incipit,
                FontFactory.getFont(FontFactory.HELVETICA, 14, BaseColor.BLACK));
        pIncipit.setAlignment(Element.ALIGN_CENTER);
        pIncipit.setSpacingAfter(10);
        document.add(pIncipit);

        String title = "Gruppo " + gruppo.getNome();
        Paragraph pTitle = new Paragraph(title, FontFactory.getFont(FontFactory.HELVETICA, 18, BaseColor.BLUE));
        pTitle.setAlignment(Element.ALIGN_CENTER);
        pTitle.setSpacingAfter(40);
        document.add(pTitle);

        PdfPCell labelNome = new PdfPCell(new Paragraph("Nome utente"));
        PdfPCell labelNumPost = new PdfPCell(new Paragraph("Num. post"));
        PdfPCell labelData = new PdfPCell(new Paragraph("Data ultimo post"));
        labelNome.setBorder(Rectangle.NO_BORDER);
        labelNumPost.setBorder(Rectangle.NO_BORDER);
        labelData.setBorder(Rectangle.NO_BORDER);

        for (int i = 0; i < iscritti.size(); i++) {
            utente = iscritti.get(i);
            try {
                posts = PostController.getPostByGruppoIdAndUserId(request, gruppo_id, utente.getId_utente());
            } catch (SQLException ex) {
                Logger.getLogger(CreaPdfServlet.class.getName()).log(Level.SEVERE, null, ex);
            }

            if (utente.getNome_avatar() != null) {
                imageUrl = baseUrl + request.getContextPath() + AVATAR_RESOURCE_PATH + "/"
                        + utente.getId_utente() + "_" + utente.getNome_avatar();
                ;
            } else {
                imageUrl = baseUrl + request.getContextPath() + "/res/images/user_avatar.png";
            }
            Image image = Image.getInstance(new URL(imageUrl));
            image.scaleToFit(50, 50);

            PdfPTable table = new PdfPTable(3);

            PdfPCell cellAvatar = new PdfPCell(image);
            cellAvatar.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellAvatar.setBorder(Rectangle.NO_BORDER);
            cellAvatar.setRowspan(3);

            PdfPCell cellNome = new PdfPCell(new Paragraph(utente.getUsername() + ""));
            cellNome.setBorder(Rectangle.NO_BORDER);

            PdfPCell cellNumPost = new PdfPCell(new Paragraph(posts.size() + ""));
            cellNumPost.setBorder(Rectangle.NO_BORDER);

            //L'ultimo  sempre il piu recente siccome la query  ORDER BY data_creazione
            PdfPCell cellData;
            if (posts.size() != 0) {
                cellData = new PdfPCell(new Paragraph(posts.get(posts.size() - 1).getData_creazione()));
            } else {
                cellData = new PdfPCell(new Paragraph("N/A"));

            }
            cellData.setBorder(Rectangle.NO_BORDER);

            PdfPCell cellVoidBottom = new PdfPCell(new Paragraph(" "));
            cellVoidBottom.setBorder(Rectangle.BOTTOM);
            cellVoidBottom.setPaddingBottom(10);
            cellVoidBottom.setColspan(3);

            PdfPCell cellVoidTop = new PdfPCell(new Paragraph(" "));
            cellVoidTop.setBorder(Rectangle.NO_BORDER);
            cellVoidTop.setPaddingTop(10);
            cellVoidTop.setColspan(3);

            table.addCell(cellVoidTop);
            table.addCell(cellAvatar);
            table.addCell(labelNome);
            table.addCell(cellNome);
            table.addCell(labelNumPost);
            table.addCell(cellNumPost);
            table.addCell(labelData);
            table.addCell(cellData);
            table.addCell(cellVoidBottom);

            document.add(table);

        }

        document.close();
        response.setContentType("application/pdf");
        response.addHeader("Content-Disposition", "inline; filename=ahahah.pdf");
        OutputStream os = response.getOutputStream();
        baos.writeTo(os);
        os.flush();
        os.close();
    } catch (DocumentException ex) {
        Logger.getLogger(CreaPdfServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}