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) 

Source Link

Document

Constructs a Font-object.

Usage

From source file:pipe.PdfMaker.java

/**
 * Private constructor, since this is a singleton. Fonts are initialized in
 * the constructor./* w w  w  .  jav a  2s .  c  o m*/
 */
public PdfMaker() {
    arial = FontFactory.getFont("Arial", 8);
    arial.setStyle(Font.BOLD);
    arialSmall = FontFactory.getFont("Arial", 6);
    arialSmall.setStyle(Font.BOLD);
    courier = FontFactory.getFont("Courier", 10);
    arialMini = FontFactory.getFont("Arial", 5);
}

From source file:ro.nextreports.engine.exporter.PdfExporter.java

License:Apache License

private Font getFont(int size) {
    if (encoding == null) {
        return FontFactory.getFont(fontName, size);
    } else {//from  w  w  w  .j av a 2s .  c om
        if (embeddedFont == null) {
            return FontFactory.getFont(fontName, encoding, size);
        } else {
            return FontFactory.getFont(embeddedFont, encoding, true, size, Font.NORMAL);
        }
    }
}

From source file:servlet.PdfGenerator.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w  w  w .  j a v a  2s  .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 {
    Document report = new Document();
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(report, baos);

        DBManager manager = (DBManager) getServletContext().getAttribute("dbmanager");
        Group groupToReport = manager.getGroup(Integer.parseInt(request.getParameter("id")));
        LinkedList<User> groupUsers = manager.getUsersForGroupAndVisible(groupToReport.getId());
        Timestamp lastPosted = manager.getLatestPost(groupToReport);
        int numberOfPosts = manager.getGroupPosts(groupToReport).size();
        String context = request.getServletContext().getRealPath("/");
        Iterator<User> groupIterator = groupUsers.iterator();

        report.open();
        // INSERTING DOCUMENT CONTENT AREA
        Font title = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 24);
        Font text = FontFactory.getFont(FontFactory.HELVETICA, 12);
        Paragraph documentHead = new Paragraph(groupToReport.getName(), title);
        Paragraph newLine = new Paragraph(Chunk.NEWLINE);
        Paragraph latestPost = new Paragraph("Latest post inserted on: " + lastPosted, text);
        Paragraph postsNumberToReport = new Paragraph("Number of posts: " + numberOfPosts, text);

        //LAYOUT AND FINAL PARAGRAPH EDITING AREA
        report.add(documentHead);
        report.add(newLine);
        report.add(postsNumberToReport);
        report.add(newLine);
        report.add(latestPost);
        report.add(newLine);
        PdfPTable usersTable = new PdfPTable(5);

        // LOOP FOR SETTING TABLE
        while (groupIterator.hasNext()) {
            User u = groupIterator.next();
            String userName = u.getName();
            PdfPCell avatarCell = new PdfPCell(Image.getInstance(context + u.getAvatar(request)));
            avatarCell.setBorder(0);
            avatarCell.setPaddingBottom(10);
            avatarCell.setColspan(1);
            PdfPCell userNameCell = new PdfPCell(new Phrase(userName));
            userNameCell.setColspan(4);
            userNameCell.setBorder(0);
            userNameCell.setPaddingBottom(10);
            userNameCell.setPaddingLeft(10);
            usersTable.addCell(avatarCell);
            usersTable.addCell(userNameCell);
        }
        usersTable.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
        report.add(usersTable);

        report.close();

        // SETTING SOME RESPONSE HEADER
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Pragma", "public");
        // SETTING THE CONTENT TYPE
        response.setContentType("application/pdf");
        // THE CONTENTLENGHT
        response.setContentLength(baos.size());
        System.out.println("ci sono");
        try (OutputStream os = response.getOutputStream()) {
            baos.writeTo(os);
            os.flush();
            os.close();
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }
}

From source file:simz1.ManagerHomeScreen.java

private void btnGenerateReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerateReportActionPerformed
    int reply = JOptionPane.showConfirmDialog(null, "Do you wish to fianlize Accounts Report now?", "",
            JOptionPane.YES_NO_OPTION);
    if (reply == JOptionPane.YES_OPTION) {
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {//from  w w w  .ja v a2s . com
            String date = today.replace(":", "_");
            //New PDF File will be created as ACCReport2016_01_01 //today's date
            PdfWriter.getInstance(document,
                    new FileOutputStream("C:\\#SIMZ\\Account Reports\\ACCReport" + date + "" + ".pdf"));
            document.open();
            Image image2 = Image.getInstance("C:\\#SIMZ\\logo1.jpg");
            document.add(image2);
            Paragraph paragraph1 = new Paragraph(
                    "Perera and Sons Bakers(pvt)Ltd.\nAddress: 1/52, Galle Road,Colombo 03.\nT.P:0112552225\n\n");
            document.add(paragraph1);
            paragraph1 = new Paragraph("                Finalized Accounts Report - " + today + "",
                    FontFactory.getFont(FontFactory.HELVETICA, 18));
            document.add(paragraph1);
            //adding a table
            PdfPTable t = new PdfPTable(3);
            t.setSpacingBefore(25);
            t.setSpacingAfter(25);

            t.addCell(new PdfPCell(new Phrase("Description")));
            t.addCell(new PdfPCell(new Phrase("Credit(Rs.)")));
            t.addCell(new PdfPCell(new Phrase("Debit(Rs.)")));
            int rows = tblIncome.getRowCount();

            for (int i = 0; i < rows; i++) {
                t.addCell(new PdfPCell(new Phrase(tblIncome.getValueAt(i, 0) + "")));
                if (tblIncome.getValueAt(i, 1) == null) {
                    t.addCell(new PdfPCell(new Phrase("-")));
                } else {
                    t.addCell(new PdfPCell(new Phrase(tblIncome.getValueAt(i, 1) + "")));
                }
                if (tblIncome.getValueAt(i, 2) == null) {
                    t.addCell(new PdfPCell(new Phrase("-")));
                } else {
                    t.addCell(new PdfPCell(new Phrase(tblIncome.getValueAt(i, 2) + "")));
                }
            }
            document.add(t);
            float totalIncome = 0;
            for (int i = 0; i < rows; i++) {
                if (tblIncome.getValueAt(i, 1) != null) {
                    totalIncome = totalIncome + Float.parseFloat(tblIncome.getValueAt(i, 1).toString());
                } else {
                    totalIncome = totalIncome + 0;
                }
            }
            paragraph1 = new Paragraph("Total Income (Rs.) : " + totalIncome + "");
            document.add(paragraph1);
            float totalExpences = 0;
            for (int i = 0; i < rows; i++) {
                if (tblIncome.getValueAt(i, 2) != null) {
                    totalExpences = totalExpences + Float.parseFloat(tblIncome.getValueAt(i, 2).toString());
                } else {
                    totalExpences = totalExpences + 0;
                }
            }
            DecimalFormat roundValue = new DecimalFormat("###.##");
            float expense = Float.parseFloat(roundValue.format(totalExpences));
            paragraph1 = new Paragraph("Total Expence (Rs.) : " + expense + "");
            document.add(paragraph1);
            float profit = 0;
            profit = totalIncome - expense;
            totProfit = profit;
            trigger1 = 1;
            paragraph1 = new Paragraph("Total Profit (Rs.) : " + profit + "" + "\n\n");
            document.add(paragraph1);
            String name = dbOps.getName(name1.getText());
            paragraph1 = new Paragraph("Report Generated By : " + name);
            document.add(paragraph1);
            //view report
            int reply1 = JOptionPane.showConfirmDialog(null,
                    "Finalized Accounts Report named ACCReportToday'sDate successfully generated.\nDo you want to view the report?",
                    "", JOptionPane.YES_NO_OPTION);
            if (reply1 == JOptionPane.YES_OPTION) {
                if ((new File("C:\\#SIMZ\\Account Reports\\ACCReport" + date + "" + ".pdf")).exists()) {

                    Process p = Runtime.getRuntime()
                            .exec("rundll32 url.dll,FileProtocolHandler C:\\#SIMZ\\Account Reports\\ACCReport"
                                    + date + "" + ".pdf");
                    p.waitFor();
                }
            }
        } catch (Exception ex) {
            System.out.println(ex);
            JOptionPane.showMessageDialog(this, "File already exists!!!");
        }
        document.close();
    }
}

From source file:simz1.ManagerHomeScreen.java

private void btnFinalReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFinalReportActionPerformed
    int reply = JOptionPane.showConfirmDialog(null, "Do you wish to fianlize Products Report now?", "",
            JOptionPane.YES_NO_OPTION);
    if (reply == JOptionPane.YES_OPTION) {
        Document document = new Document(PageSize.A4);
        try {/*from  w ww  . j a v  a 2  s.c  o m*/
            String date = today.replace(":", "_");
            //New PDF File will be created as ProReport2016_01_01 //today's date
            PdfWriter.getInstance(document,
                    new FileOutputStream("C:\\#SIMZ\\Product Reports\\ProReport" + date + "" + ".pdf"));
            document.open();
            Image image2 = Image.getInstance("C:\\#SIMZ\\logo1.jpg");
            document.add(image2);
            Paragraph paragraph1 = new Paragraph(
                    "Perera and Sons Bakers(pvt)Ltd.\nAddress: 1/52, Galle Road,Colombo 03.\nT.P:0112552225\n\n");
            document.add(paragraph1);
            //Following blank space is for the alignment of the topic
            paragraph1 = new Paragraph("                Finalized Products Report - " + today + "",
                    FontFactory.getFont(FontFactory.HELVETICA, 18));
            document.add(paragraph1);
            //adding a table
            PdfPTable t = new PdfPTable(3);
            t.setSpacingBefore(25);
            t.setSpacingAfter(25);
            t.addCell(new PdfPCell(new Phrase("Product Name")));
            t.addCell(new PdfPCell(new Phrase("Received Quantity")));
            t.addCell(new PdfPCell(new Phrase("Remained Quantity")));
            int rows = tblReports.getRowCount();
            for (int i = 0; i < rows; i++) {
                t.addCell(new PdfPCell(new Phrase(tblReports.getValueAt(i, 0) + "")));
                if (tblReports.getValueAt(i, 1) == null) {
                    t.addCell(new PdfPCell(new Phrase("-")));
                } else {
                    t.addCell(new PdfPCell(new Phrase(tblReports.getValueAt(i, 1) + "")));
                }
                if (tblReports.getValueAt(i, 2) == null) {
                    t.addCell(new PdfPCell(new Phrase("-")));
                } else {
                    t.addCell(new PdfPCell(new Phrase(tblReports.getValueAt(i, 2) + "")));
                }
            }
            document.add(t);
            paragraph1 = new Paragraph("Expired Item Details");
            document.add(paragraph1);
            PdfPTable t2 = new PdfPTable(2);
            t2.setSpacingBefore(25);
            t2.setSpacingAfter(25);
            t2.addCell(new PdfPCell(new Phrase("Product Name")));
            t2.addCell(new PdfPCell(new Phrase("Remained Quantity")));
            String dateToday = today.replace(":", "-");
            ResultSet rs = dbOps.getExpiredItemList(dateToday);
            while (rs.next()) {
                t2.addCell(new PdfPCell(new Phrase(rs.getString(1))));
                t2.addCell(new PdfPCell(new Phrase(rs.getString(3))));
            }
            document.add(t2);
            String user = dbOps.getName(name1.getText());
            paragraph1 = new Paragraph("Report Generated By : " + user);
            document.add(paragraph1);
            //view report
            int reply1 = JOptionPane.showConfirmDialog(null,
                    "Finalized Products Report named ProReportToday'sDate successfully generated.\nDo you want to view the report?",
                    "", JOptionPane.YES_NO_OPTION);
            trigger2 = 1;
            if (reply1 == JOptionPane.YES_OPTION) {
                if ((new File("C:\\#SIMZ\\Product Reports\\ProReport" + date + "" + ".pdf")).exists()) {

                    Process p = Runtime.getRuntime()
                            .exec("rundll32 url.dll,FileProtocolHandler C:\\#SIMZ\\Product Reports\\ProReport"
                                    + date + "" + ".pdf");
                    p.waitFor();
                }
            }

        } catch (SQLException | HeadlessException | IOException | InterruptedException | DocumentException ex) {
            System.out.println(ex);
            JOptionPane.showMessageDialog(this, "File already exists!!!");
        }
        document.close();
    }
}

From source file:src.GUI.FONTS.java

License:Open Source License

public static Font Font() {
    Font font = FontFactory.getFont("Helvetica", 12);
    return font;
}

From source file:storybook.export.ExportPDF.java

void writeText(String str) {
    SbApp.trace("ExportPDF.writeText(" + str + ")");
    try {//from ww w.j  av a 2s . c  om
        outDoc.add(new Phrase(str + "\n", FontFactory.getFont(FontFactory.HELVETICA, 10)));
    } catch (DocumentException ex) {
        SbApp.error("ExportPDF.writeText(" + str + ")", ex);
    }
}