Example usage for com.itextpdf.text FontFactory defaultEncoding

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

Introduction

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

Prototype

String defaultEncoding

To view the source code for com.itextpdf.text FontFactory defaultEncoding.

Click Source Link

Document

This is the default encoding to use.

Usage

From source file:model.PDFModel.java

License:Open Source License

public PdfPTable createTablePDFTable(int counter, String raportDate) {

    JTable resultTable = query.getProductsInTablePDFTable(raportDate, counter);

    PdfPTable[] tableTable = new PdfPTable[11];
    PdfPCell cell, productNameCell, paymentCell, countCell, priceCell;

    tableTable[counter] = new PdfPTable(4);
    tableTable[counter].setSpacingBefore(5f);
    tableTable[counter].setSpacingAfter(5f);

    totalTablePayment[counter] = 0.00;//from   w ww. j a  va 2 s  .  c  om
    if (resultTable != null) {
        DefaultTableModel resultTableModel = (DefaultTableModel) resultTable.getModel();
        if (resultTableModel.getRowCount() > 0) {
            cell = new PdfPCell(new Phrase("Stolik " + (counter)));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBackgroundColor(new BaseColor(80, 255, 50));
            tableTable[counter].addCell(cell);
            cell = new PdfPCell();
            cell.setBorder(Rectangle.NO_BORDER);
            tableTable[counter].addCell(cell);
            cell = new PdfPCell();
            cell.setBorder(Rectangle.NO_BORDER);
            tableTable[counter].addCell(cell);
            cell = new PdfPCell();
            cell.setBorder(Rectangle.NO_BORDER);
            tableTable[counter].addCell(cell);

            cell = new PdfPCell(new Phrase("Produkt"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBackgroundColor(new BaseColor(80, 172, 8));
            tableTable[counter].addCell(cell);
            cell = new PdfPCell(new Phrase("Ilosc"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBackgroundColor(new BaseColor(80, 172, 8));
            tableTable[counter].addCell(cell);
            cell = new PdfPCell(new Phrase("Cena jednostkowa"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBackgroundColor(new BaseColor(80, 172, 8));
            tableTable[counter].addCell(cell);
            cell = new PdfPCell(new Phrase("Zaplata"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBackgroundColor(new BaseColor(80, 172, 8));
            tableTable[counter].addCell(cell);

            for (int i = 0; i < resultTableModel.getRowCount(); i++) {
                productNameCell = new PdfPCell(new Phrase(resultTableModel.getValueAt(i, 0).toString(),
                        FontFactory.getFont(FontFactory.defaultEncoding, 10, Font.NORMAL, BaseColor.BLACK)));
                productNameCell.setHorizontalAlignment(Element.ALIGN_CENTER);
                productNameCell.setBackgroundColor(new BaseColor(80, 135, 8));
                tableTable[counter].addCell(productNameCell);
                countCell = new PdfPCell(new Phrase(String.valueOf(resultTableModel.getValueAt(i, 2))));
                countCell.setHorizontalAlignment(Element.ALIGN_CENTER);
                tableTable[counter].addCell(countCell);
                double payment = Double.parseDouble(resultTableModel.getValueAt(i, 1).toString())
                        * Double.parseDouble(resultTableModel.getValueAt(i, 2).toString());
                totalTablePayment[counter] += payment;
                paymentCell = new PdfPCell(new Phrase(String.valueOf(resultTableModel.getValueAt(i, 1))));
                paymentCell.setHorizontalAlignment(Element.ALIGN_CENTER);
                tableTable[counter].addCell(paymentCell);
                priceCell = new PdfPCell(new Phrase(String.valueOf(payment)));
                priceCell.setHorizontalAlignment(Element.ALIGN_CENTER);
                priceCell.setBackgroundColor(new BaseColor(255, 160, 160));
                tableTable[counter].addCell(priceCell);
            }
        }
    }
    if (totalTablePayment[counter] > 0.00) {
        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        tableTable[counter].addCell(cell);
        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        tableTable[counter].addCell(cell);
        cell = new PdfPCell(new Phrase("SUMA:",
                FontFactory.getFont(FontFactory.defaultEncoding, 12, Font.NORMAL, BaseColor.BLACK)));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        tableTable[counter].addCell(cell);
        cell = new PdfPCell(new Phrase(String.valueOf(totalTablePayment[counter]),
                FontFactory.getFont(FontFactory.defaultEncoding, 12, Font.BOLD, BaseColor.BLACK)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(new BaseColor(255, 50, 50));
        tableTable[counter].addCell(cell);
    }

    return tableTable[counter];
}