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) 

Source Link

Document

Constructs a Font-object.

Usage

From source file:containers.Report.java

public void generateOrderByPayment(String type, ArrayList<String> entry, String from, String to) {
    try {//from   w  ww .ja va  2  s.com
        String path = System.getProperty("user.home") + File.separator + "Documents";
        OutputStream file = new FileOutputStream(new File(path + "\\PayTypeReport.pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();

        Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER));

        Image img = Image.getInstance(new URL(link));
        img.scalePercent(56f);
        p.add(img);

        body3 = String.format("%5s - %5s - %5s\n", "Order No.", "Order Total", "Order Date");

        double counter = 0;
        for (int i = 0; i < entry.size(); i += 3) {
            body3 += String.format("%-10s %8s %25s\n", entry.get(i), entry.get(i + 1),
                    entry.get(i + 2).substring(0, 19));
            counter += Double.parseDouble(entry.get(i + 1));
        }

        body3 += "\n\nTotal for all orders: $" + counter;

        from = from.substring(0, 10);
        to = to.substring(0, 10);

        p.add(new Date().toString());
        p.add("\n\nOrder by Payment Report\n");
        p.add("Payment Type: " + type + "\n");
        p.add("Reporting Date: \n" + from + " - " + to + "\n\n");
        p.add(body3);
        document.add(p);

        document.close();
        file.close();

        body3 = "";

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:containers.Report.java

public void generateOrderItem(String ordernum, ArrayList<String> entry) {
    try {//w w  w . j  a va2s  . co  m
        String path = System.getProperty("user.home") + File.separator + "Documents";
        OutputStream file = new FileOutputStream(new File(path + "\\OrderReport.pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();

        Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER));

        Image img = Image.getInstance(new URL(link));
        img.scalePercent(56f);
        p.add(img);

        body4 = String.format("%5s  %27s  %10s\n", "Item Name", "Base Price", "Log Total");

        double counter = 0;
        for (int i = 0; i < entry.size(); i += 3) {
            body4 += String.format("%-10s %15s %12s\n", entry.get(i), entry.get(i + 1), entry.get(i + 2));
            counter += Double.parseDouble(entry.get(i + 2));
        }

        body4 += "\n\nTotal for all orders: $" + counter;

        p.add(new Date().toString());
        p.add("\n\nItems on Order Report\n");
        p.add("Order Number: " + ordernum + "\n\n");

        p.add(body4);
        document.add(p);

        document.close();
        file.close();

        body4 = "";

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:hsa.awp.admingui.report.printer.PdfPrinter.java

License:Open Source License

@Override
public void print(ExportList list) {

    if (outputStream == null) {
        throw new IllegalArgumentException("OutputStream undefined, please use setOutputStream()");
    }/* www . j a v  a2s .  c om*/

    if (!(list instanceof PdfPrintable)) {
        throw new IllegalArgumentException("PdfPrinter can only print PdfPrintables");
    }

    PdfPrintable pdfPrintable = (PdfPrintable) list;
    Document document = setUpDocument(pdfPrintable);

    try {
        document.open();

        int numberOfColumns = pdfPrintable.getPdfProperties().getCellProperties().size();
        int numberOfRows = list.getRows().size();

        PdfPTable table = new PdfPTable(numberOfColumns);

        float[] widths = new float[numberOfColumns];

        for (int i = 0; i < widths.length; i++) {
            widths[i] = pdfPrintable.getPdfProperties().getCellProperties().get(i).getWidth();
        }

        table.setWidths(widths);

        /* header */
        for (PdfCellProperties cellProperties : pdfPrintable.getPdfProperties().getCellProperties()) {
            PdfPCell cell = new PdfPCell(
                    new Phrase(cellProperties.getHeadline(), FontFactory.getFont(FontFactory.HELVETICA_BOLD)));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
        }

        /* content */
        int rowIndex = 0;
        for (Row row : list.getRows()) {
            int columnIndex = 0;
            for (String content : row.getContent()) {
                if (content != null) {
                    PdfPCell cell = new PdfPCell(
                            new Phrase(content, FontFactory.getFont(FontFactory.HELVETICA)));
                    cell.setHorizontalAlignment(pdfPrintable.getPdfProperties().getCellProperties()
                            .get(columnIndex).getAlignment().getPdfAlign());
                    table.addCell(cell);
                } else {
                    table.addCell("");
                }
                columnIndex++;
            }
            rowIndex++;
        }

        //      /* footer */
        //      if (footerFound) {
        //        for (PdfTableColumn tableColumn : cols) {
        //          table.addCell(tableColumn.getFooter());
        //        }
        //      }

        document.add(table);

        document.add(new Phrase(" "));

        document.close();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

}

From source file:Model.MyFontSelector.java

License:Open Source License

/**
 * Inits the BaseFonts of External Fonts and gets of the internals
 * Faz a inicializao das BaseFonts das fontes externas e recupera das
 * fontes internas.//w w w  . j  a v  a2s . co  m
 */
private void initBaseFonts() {
    try {
        ArrayList<BaseFont> baseFontList = new ArrayList<>();
        ArrayList<Font> fontList = new ArrayList<>();

        /**
         * Gets Internals BaseFonts
         * Recupera as BaseFonts das fontes internas
         */
        fontList.add(FontFactory.getFont(BaseFont.TIMES_ROMAN));
        fontList.add(FontFactory.getFont(BaseFont.COURIER));
        fontList.add(FontFactory.getFont(BaseFont.SYMBOL));

        for (Font f : fontList) {
            baseFontList.add(f.getBaseFont());
        }

        /**
         * Gets external chinese traditional BaseFonts
         * Recupera as BaseFonts da fonte externa do Chins tradicional
         */

        baseFontList.add(BaseFont.createFont("MHei-Medium", "UniCNS-UCS2-H", BaseFont.EMBEDDED));
        baseFontList.add(BaseFont.createFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.EMBEDDED));

        /**
         * Gets external chinese simplified BaseFonts
         * Recupera o BaseFont da fonte externa do Chins simplificado
         */
        baseFontList.add(BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED));

        initFonts(baseFontList);
    } catch (DocumentException | IOException ex) {
        System.out.println("Error - BaseFont generation");
    }
}

From source file:net.vzurczak.timesheetgenerator.PdfGenerator.java

License:Apache License

/**
 * Adds a page for a given week./*  www  .j  a  va 2  s  . co  m*/
 * @param i the week number
 * @param doc the document to update
 * @param bean a generation bean (not null)
 * @throws DocumentException
 */
private void addPageForWeek(int weekNumber, Document doc, GenerationDataBean bean) throws DocumentException {

    doc.newPage();
    final Font boldFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD);
    final Font normalFont = FontFactory.getFont(FontFactory.HELVETICA);
    Calendar calendar = Utils.findCalendar(weekNumber);

    // Title
    Paragraph paragraph = new Paragraph("Bordereau de Dclaration des Temps", boldFont);
    paragraph.setAlignment(Element.ALIGN_CENTER);
    doc.add(paragraph);

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

    // Meta: week
    final PdfPTable metaTable = new PdfPTable(1);

    paragraph = new Paragraph();
    paragraph.add(new Chunk("Semaine : ", boldFont));
    paragraph.add(new Chunk(String.valueOf(weekNumber), normalFont));

    PdfPCell c = new PdfPCell(paragraph);
    c.setBorder(Rectangle.NO_BORDER);
    metaTable.addCell(c);

    // Meta: date
    Calendar endOfWeekCalendar = ((Calendar) calendar.clone());
    endOfWeekCalendar.add(Calendar.DATE, 4);
    String formattedDate = new SimpleDateFormat("dd/MM/yyyy").format(endOfWeekCalendar.getTime());

    paragraph = new Paragraph();
    paragraph.add(new Chunk("Date : ", boldFont));
    paragraph.add(new Chunk(formattedDate, normalFont));

    c = new PdfPCell(paragraph);
    c.setBorder(Rectangle.NO_BORDER);
    metaTable.addCell(c);

    doc.add(metaTable);
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    // Signatures
    final PdfPTable signaturesTable = new PdfPTable(2);
    paragraph = new Paragraph();
    paragraph.add(new Chunk("Nom : ", boldFont));
    paragraph.add(new Chunk(bean.getName(), normalFont));

    c = new PdfPCell(paragraph);
    c.setBorder(Rectangle.NO_BORDER);
    signaturesTable.addCell(c);

    paragraph = new Paragraph();
    paragraph.add(new Chunk("Responsable : ", boldFont));
    paragraph.add(new Chunk(bean.getManagerName(), normalFont));

    c = new PdfPCell(paragraph);
    c.setBorder(Rectangle.NO_BORDER);
    signaturesTable.addCell(c);

    c = new PdfPCell(new Paragraph("Signature : ", boldFont));
    c.setBorder(Rectangle.NO_BORDER);
    signaturesTable.addCell(c);

    c = new PdfPCell(new Paragraph("Signature : ", boldFont));
    c.setBorder(Rectangle.NO_BORDER);
    signaturesTable.addCell(c);

    doc.add(signaturesTable);
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    // Calendar
    final PdfPTable timeTable = new PdfPTable(7);
    timeTable.addCell(new PdfPCell());

    for (int i = 0; i < 5; i++) {
        final String date = this.sdf.format(calendar.getTime());
        timeTable.addCell(newCell(date, 10));
        calendar.add(Calendar.DATE, 1);
    }

    timeTable.addCell(newCell("Total", 10));
    timeTable.addCell(newCell("Heures Effectues", 20));

    for (int i = 0; i < 5; i++)
        timeTable.addCell(newCell("", 20));

    if (bean.getTotalHours() > 0)
        timeTable.addCell(newCell(bean.getTotalHours() + " h", 20));

    timeTable.completeRow();
    doc.add(timeTable);
}

From source file:org.openlmis.web.view.pdf.requisition.RequisitionCellFactory.java

License:Open Source License

public static PdfPCell categoryRow(Integer visibleColumnsSize, LineItem lineItem) {
    Chunk chunk = new Chunk(lineItem.getCategoryName(), FontFactory.getFont(FontFactory.HELVETICA_BOLD));
    PdfPCell cell = new PdfPCell(new Phrase(chunk));
    cell.setColspan(visibleColumnsSize);
    cell.setBackgroundColor(HEADER_BACKGROUND);
    cell.setPadding(CELL_PADDING);/*from  w  w  w  .  j  a  v a  2 s .co  m*/
    return cell;
}

From source file:view.AppearanceSettingsDialog.java

License:Open Source License

private void getFontsFromFolder(File folder, HashMap<com.itextpdf.text.Font, String> fontList) {
    if (folder.exists()) {
        File[] listOfFiles = folder.listFiles();

        for (File f : listOfFiles) {
            if (f.isDirectory()) {
                getFontsFromFolder(f, fontList);
            } else if (f.isFile() && f.getName().endsWith(".ttf")) {
                com.itextpdf.text.Font font = FontFactory.getFont(f.getAbsolutePath());
                boolean contains = false;
                for (com.itextpdf.text.Font ff : fontList.keySet()) {
                    if (ff.getFamilyname().equals(font.getFamilyname())) {
                        contains = true;
                        break;
                    }/*from  w  w w .  j  a  va2  s.  c o m*/
                }
                if (!font.getFamilyname().equals("unknown")) {
                    if (!contains) {
                        fontList.put(font, f.getAbsolutePath());
                    }
                }
            }
        }
    }
}

From source file:view.AppearanceSettingsDialog.java

License:Open Source License

private void updateSettings(String font, boolean bold, boolean italic) {
    ComboBoxModel model2 = (ComboBoxModel) cbFontType.getModel();
    for (int i = 0; i < model2.getSize(); i++) {
        if (cbFontType.getItemAt(i).toString().equalsIgnoreCase(FontFactory.getFont(font).getFamilyname())) {
            cbFontType.setSelectedIndex(i);
        }//from  ww w.  j  av a  2s.c o m
    }

    cbBold.setSelected(bold);
    cbItalic.setSelected(italic);
}