Example usage for com.itextpdf.text BaseColor BaseColor

List of usage examples for com.itextpdf.text BaseColor BaseColor

Introduction

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

Prototype

public BaseColor(final float red, final float green, final float blue) 

Source Link

Document

Construct a BaseColor with float values.

Usage

From source file:scrum.server.common.APdfCreator.java

License:Open Source License

private void tasks(APdfContainerElement container, Collection<Task> tasks) {
    for (Task task : tasks) {
        container.nl(miniLabelFont);/*from  w  ww .  j  a  v a 2  s. c  o m*/
        ATable table = container.table(3, 20);

        ARow rowHeader = table.row().setDefaultBackgroundColor(new BaseColor(223, 223, 223));
        rowHeader.cell().setFontStyle(referenceFont).text(task.getReference());
        rowHeader.cell().setFontStyle(new FontStyle(defaultFont).setBold(true)).text(task.getLabel());

        if (task.isDescriptionSet())
            richtextRow(table, "Description", task.getDescription());

        Impediment impediment = task.getImpediment();
        if (impediment != null && !impediment.isClosed()) {
            AParagraph p = richtextRow(table, null, null).paragraph();
            p.text("Blocked by ", fieldLabelFont);
            p.text(impediment.getReference(), referenceFont);
            p.text(" " + impediment.getLabel(), defaultFont);
        }

        table.createCellBorders(BaseColor.LIGHT_GRAY, 0.2f);
    }

}

From source file:Server.Server.java

/**
 * Dado o parmetro day, cria um relatrio de vendas do sistema nesse dia.
 * @param day/* w  w  w . j a  va2s .  c o  m*/
 * @throws Exception 
 */
public void generateDayReport(String day) throws Exception {
    ObservableList<Sale> list = searchSalesByDay(day);

    Document dayReport = new Document();
    PdfWriter.getInstance(dayReport, new FileOutputStream(day + " report. C4 Supermarket.pdf"));

    PdfPTable table = new PdfPTable(5);

    table.addCell("User ID");
    table.addCell("Product Name");
    table.addCell("Sale Date");
    table.addCell("Qtd");
    table.addCell("Sale Total Cost");

    for (Sale sl : list) {
        table.addCell(sl.getUserID());
        table.addCell(sl.getProductName());
        table.addCell(sl.getDate());
        table.addCell(sl.getQtd());
        table.addCell(sl.getTotalCost());
    }

    dayReport.open();
    Paragraph header = new Paragraph("\t\tCARRO&4 SUPERMARKET\n" + day + " sales report.\n\n\n",
            new Font(FontFamily.COURIER, 30, Font.BOLD, new BaseColor(0, 0, 255)));
    dayReport.add(header);
    dayReport.add(table);

    dayReport.close();
}

From source file:Server.Server.java

/**
 * Dados os parmetros month e year, cria uma relatrio de vendas realizadas
 * no ms do ano informado./*from   w ww . j a v  a 2 s  . c o  m*/
 * @param month
 * @param year
 * @throws Exception 
 */
public void generateMonthReport(String month, String year) throws Exception {
    ObservableList<Sale> list = searchSalesByMonth(month, year);
    String date = month + "-" + year;

    Document dayReport = new Document();
    PdfWriter.getInstance(dayReport, new FileOutputStream(date + " report. C4 Supermarket.pdf"));

    PdfPTable table = new PdfPTable(5);

    table.addCell("User ID");
    table.addCell("Product Name");
    table.addCell("Sale Date");
    table.addCell("Qtd");
    table.addCell("Sale Total Cost");

    for (Sale sl : list) {
        table.addCell(sl.getUserID());
        table.addCell(sl.getProductName());
        table.addCell(sl.getDate());
        table.addCell(sl.getQtd());
        table.addCell(sl.getTotalCost());
    }

    dayReport.open();
    Paragraph header = new Paragraph("\t\tCARRO&4 SUPERMARKET\n" + date + " sales report.\n\n\n",
            new Font(FontFamily.COURIER, 30, Font.BOLD, new BaseColor(0, 0, 255)));
    dayReport.add(header);
    dayReport.add(table);

    dayReport.close();
}

From source file:src.servlets.ManageAdmin.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*w  ww .  j av  a  2 s .c o m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    Map m = request.getParameterMap();
    if (m.containsKey("GetPDF")) {
        try {
            String Report = getServletContext().getRealPath("") + "admin\\PDF_Report.pdf";

            FileOutputStream file = new FileOutputStream(Report);
            Document document = new Document();
            document.addAuthor("K00140908");
            PdfWriter.getInstance(document, file);
            ///////////////////////ADDING THE FILES TO PDF////////////////////
            //Inserting Image in PDF
            String uploadPath = getServletContext().getRealPath("") + "images\\logo.gif";

            Image img = Image.getInstance(uploadPath);

            img.scaleAbsolute(120f, 60f);// width,height of image in float

            //            Inserting Title in PDF  ORIGINAL
            //            Font fontTitle=new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.WHITE);
            //            Chunk title=new Chunk("PDF GENERATION in Java with iText", fontTitle);
            //            title.setBackground(new BaseColor(255,102,0), 1f, 1f, 1f, 3f);
            //            title.setLineHeight(30f);
            //            title.setUnderline(BaseColor.BLACK,5f,0.5f,2f,0.5f,PdfContentByte.LINE_CAP_ROUND);
            Font fontTitle = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.BLACK);
            Chunk title = new Chunk("Lit Realty System Report", fontTitle);
            title.setLineHeight(30f);

            //Inserting Table in PDF
            PdfPTable table = new PdfPTable(3);
            table.setWidthPercentage(100); // Sets the width percentage that the table will occupy in the page
            table.setSpacingAfter(10f);
            table.setSpacingBefore(15f);
            table.setWidths(new float[] { 2f, 2f, 2f }); // Sets relative width of table

            Font fontHeader = new Font(Font.FontFamily.HELVETICA, 15, Font.BOLD, BaseColor.BLUE);
            PdfPCell headercell = new PdfPCell(new Phrase("Property Photo", fontHeader)); // Creates new cell in table
            headercell.setBackgroundColor(new BaseColor(230, 230, 243));
            headercell.setPaddingBottom(5f);
            table.addCell(headercell);

            headercell = new PdfPCell(new Phrase("Property ID", fontHeader));
            headercell.setBackgroundColor(new BaseColor(233, 233, 233));
            headercell.setPaddingBottom(5f);
            table.addCell(headercell);

            headercell = new PdfPCell(new Phrase("Price", fontHeader));
            headercell.setBackgroundColor(new BaseColor(233, 233, 233));
            headercell.setPaddingBottom(5f);
            table.addCell(headercell);

            PdfPCell cell1 = new PdfPCell(img, false);

            table.addCell(cell1);
            table.addCell("134000");
            table.addCell("213445");
            table.addCell("134000");

            //Inserting List
            com.itextpdf.text.List list = new com.itextpdf.text.List(true, 30);
            list.add(new ListItem("Example1"));
            list.add(new ListItem("Example2"));
            list.add(new ListItem("Example3"));

            //Adding elements into PDF Document
            document.open();

            document.add(img);
            document.add(title);

            document.add(Chunk.NEWLINE);
            document.add(table);

            document.newPage();
            document.add(new Chunk("List of Examples").setUnderline(+1f, -5f));
            document.add(list);

            document.newPage();
            document.add(new Chunk("List of Examples").setUnderline(+1f, -5f));
            document.add(list);

            document.newPage();
            document.add(new Chunk("List of Properts By Agent X").setUnderline(+1f, -5f));
            //////////////////////GET Propertys From Entity///////////////
            List<Properties> allPropertiesList = PropertiesDB.getAllProperties();

            PdfPTable propertyTable = new PdfPTable(3);
            PdfPCell propertyHeadingcell1 = new PdfPCell(new Phrase("Photo"));
            PdfPCell propertyHeadingcell2 = new PdfPCell(new Phrase("Property ID"));
            PdfPCell propertyHeadingcell3 = new PdfPCell(new Phrase("Price"));

            propertyHeadingcell1.setBorder(Rectangle.NO_BORDER);
            propertyHeadingcell2.setBorder(Rectangle.NO_BORDER);
            propertyHeadingcell3.setBorder(Rectangle.NO_BORDER);

            propertyTable.addCell(propertyHeadingcell1);
            propertyTable.addCell(propertyHeadingcell2);
            propertyTable.addCell(propertyHeadingcell3);

            document.add(Chunk.NEWLINE);

            String uploadPathforPropertyPhoto = getServletContext().getRealPath("")
                    + "images\\properties\\thumbnails\\";

            Image propertyThumbnail;

            img.scaleAbsolute(120f, 60f);// width,height of image in float

            for (Properties anProperty : allPropertiesList) {
                propertyThumbnail = Image.getInstance(uploadPathforPropertyPhoto + anProperty.getPhoto());
                PdfPCell propertycell1 = new PdfPCell(propertyThumbnail, false);
                propertycell1.setPaddingBottom(20);
                PdfPCell propertycell2 = new PdfPCell(new Phrase(anProperty.getListingNum().toString()));
                PdfPCell propertycell3 = new PdfPCell(new Phrase(anProperty.getPrice().toString()));

                propertycell1.setBorder(Rectangle.NO_BORDER);
                propertycell2.setBorder(Rectangle.NO_BORDER);
                propertycell3.setBorder(Rectangle.NO_BORDER);

                propertyTable.addCell(propertycell1);
                propertyTable.addCell(propertycell2);
                propertyTable.addCell(propertycell3);

            }
            document.add(Chunk.NEWLINE);
            document.add(propertyTable);
            //////////////////////GET Propertys From Entity///////////////

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

            System.out.println("Pdf created successfully ! :)");

            String filePath = Report;
            File downloadFile = new File(filePath);
            FileInputStream inStream = new FileInputStream(downloadFile);

            // if you want to use a relative path to context root:
            String relativePath = getServletContext().getRealPath("");
            System.out.println("relativePath = " + relativePath);

            // obtains ServletContext
            ServletContext context = getServletContext();

            // gets MIME type of the file
            String mimeType = context.getMimeType(filePath);
            if (mimeType == null) {
                // set to binary type if MIME mapping not found
                mimeType = "application/octet-stream";
            }
            System.out.println("MIME type: " + mimeType);

            // modifies response
            response.setContentType(mimeType);
            response.setContentLength((int) downloadFile.length());

            // forces download
            String headerKey = "Content-Disposition";
            String headerValue = String.format("attachment; filename=\"%s\"", downloadFile.getName());
            response.setHeader(headerKey, headerValue);

            // obtains response's output stream
            OutputStream outStream = response.getOutputStream();

            byte[] buffer = new byte[4096];
            int bytesRead = -1;

            while ((bytesRead = inStream.read(buffer)) != -1) {
                outStream.write(buffer, 0, bytesRead);
            }

            inStream.close();
            outStream.close();
            /////////////////

            processRequest(request, response);
        } catch (DocumentException ex) {
            Logger.getLogger(ManageAdmin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:Tables.Printer.java

public Printer() {
    this.companyNameFont = new Font(Font.FontFamily.TIMES_ROMAN, 17, Font.BOLD, new BaseColor(0, 0, 128));
    this.reportTitleFont = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.BOLD, new BaseColor(51, 102, 13));
    bigHeading = new Font(FontFamily.TIMES_ROMAN, 16, Font.BOLD, new BaseColor(34, 90, 148));
    smallFooter = new Font(FontFamily.TIMES_ROMAN, 12, Font.ITALIC, new BaseColor(0, 0, 0));
    unpaid = new Font(FontFamily.TIMES_ROMAN, 13, Font.BOLD, new BaseColor(98, 45, 46));

    datOnly = new SimpleDateFormat("yyyy-MM-dd");
    timOnly = new SimpleDateFormat("hh:mm:ss");
    datTim = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    datForFile = new SimpleDateFormat("yyyy-MM-dd __ hh mm ss");

}

From source file:Tables.Printer.java

public void genTrans(TableView gentab, TableColumn name, TableColumn desc, TableColumn amt, TableColumn date,
        long total, String incOrExp) {
    try {/*from   ww  w  .  j a va  2 s .c  o  m*/
        //            Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png");
        //            im.scaleAbsolute(150f, 150f);
        //            im.setAbsolutePosition(25,50);
        //            im.setBackgroundColor(BaseColor.PINK);

        dNow = new Date();
        String app = this.datForFile.format(dNow);
        String file = "\\Documents\\NjieAB_receipts\\general transactions\\GenTransRec" + app + ".pdf";
        System.out.println("file is " + file);
        fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea
        //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf");

        Document doc = new Document(PageSize.A4, 20, 20, 20, 20);
        PdfWriter writer = PdfWriter.getInstance(doc, fs);
        //specify column widths    
        float[] columnWidths = { 4f, 5f, 1.5f, 2f };
        PdfPTable table = new PdfPTable(columnWidths);

        //special font sizes    
        Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0));
        Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10);
        // set table width a percentage of the page width    
        table.setWidthPercentage(90f);

        PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR "));
        cell.setColspan(6);
        cell.setHorizontalAlignment(2);
        doc.open();
        //doc.add(im);

        header(doc, "General " + incOrExp + " Transaction Table");

        doc.add(cell);
        System.out.println(doc.leftMargin());

        //insert column headings    
        insertTableHeading(table, "Transaction Name ", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Description of Transaction", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Amount", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Date ", Element.ALIGN_MIDDLE, 1, bfBold12);
        table.setHeaderRows(1);

        /*Now i have to fill the table  */

        for (int i = 0; i < gentab.getItems().size(); i++) {
            insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, desc.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, amt.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, date.getCellData(i).toString(), Element.ALIGN_RIGHT, 1, bf12);
        }

        insertCell(table, "Total ", Element.ALIGN_RIGHT, 2, bfBold12);
        insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 3, bfBold12);
        insertCell(table, "", Element.ALIGN_RIGHT, 4, bfBold12);
        doc.add(table);

        footer(doc); // this is rgw footer of the page

        doc.addCreationDate();
        doc.close();
        System.out.println("finished the printing job");

        //Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"));
        try {
            Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file));
        } catch (IOException iOException) {
            System.out.println("failed opening the file");
            iOException.printStackTrace();
        }
    } catch (Exception sd) {
        sd.printStackTrace();
        Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message(
                sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString())
                .showError();
    } finally {
    }
}

From source file:Tables.Printer.java

public void overdraft(TableView ovTab, TableColumn name, TableColumn amtIssued, TableColumn monthlyDeduction,
        TableColumn dateIssued, TableColumn startDeduction, TableColumn expDate, TableColumn payStatus,
        TableColumn expStatus, long totIssue, long totDeduction) {

    try {//from w  ww . j  av a  2  s  .  c  om
        //            Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png");
        //            im.scaleAbsolute(150f, 150f);
        //            im.setAbsolutePosition(25,50);
        //            im.setBackgroundColor(BaseColor.PINK);

        dNow = new Date();
        String app = this.datForFile.format(dNow);
        String file = "\\Documents\\NjieAB_receipts\\Overdraft\\GenTransRec" + app + ".pdf";
        System.out.println("file is " + file);
        fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea
        //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf");

        Document doc = new Document();
        PdfWriter writer = PdfWriter.getInstance(doc, fs);
        //specify column widths    
        float[] columnWidths = { 2f, 2f, 2f, 3f, 3f, 2f, 1.5f, 1.5f };
        PdfPTable table = new PdfPTable(columnWidths);

        //special font sizes    
        Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0));
        Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10);
        // set table width a percentage of the page width    
        table.setWidthPercentage(90f);

        PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR "));
        cell.setColspan(6);
        cell.setHorizontalAlignment(2);
        doc.open();
        //doc.add(im);

        header(doc, "Staff Overdraft Reports");

        doc.add(cell);
        System.out.println(doc.leftMargin());

        //insert column headings    
        insertTableHeading(table, "Staff Name ", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Amount Issued", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Monthly Deduction", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Date Issued ", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Start Deduction", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Expiry Date", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Pay Status", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Expiry Status", Element.ALIGN_MIDDLE, 1, bfBold12);
        table.setHeaderRows(1);

        /*Now i have to fill the table  */

        for (int i = 0; i < ovTab.getItems().size(); i++) {
            insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, amtIssued.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, monthlyDeduction.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, dateIssued.getCellData(i).toString(), Element.ALIGN_RIGHT, 1, bf12);
            insertCell(table, startDeduction.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, expDate.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, payStatus.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, expStatus.getCellData(i).toString(), Element.ALIGN_RIGHT, 1, bf12);
        }

        insertCell(table, "Total ", Element.ALIGN_RIGHT, 1, bfBold12);
        insertCell(table, String.valueOf(totIssue), Element.ALIGN_LEFT, 1, bfBold12);
        insertCell(table, String.valueOf(totDeduction), Element.ALIGN_LEFT, 1, bfBold12);
        insertCell(table, "", Element.ALIGN_LEFT, 1, bfBold12);
        insertCell(table, "", Element.ALIGN_LEFT, 1, bfBold12);
        insertCell(table, "", Element.ALIGN_LEFT, 1, bfBold12);
        insertCell(table, "", Element.ALIGN_LEFT, 1, bfBold12);
        insertCell(table, "", Element.ALIGN_LEFT, 1, bfBold12);
        doc.add(table);

        footer(doc); // this is rgw footer of the page

        doc.addCreationDate();
        doc.close();
        System.out.println("finished the printing job");

        //Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"));
        try {
            Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file));
        } catch (IOException iOException) {
            System.out.println("failed opening the file");
        }
    } catch (DocumentException | FileNotFoundException sd) {
        Action showError = Dialogs
                .create().title("Printer Error").masthead("Errro In Printing File").message(sd.getMessage()
                        + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString())
                .showError();
    } finally {
    }

}

From source file:Tables.Printer.java

public void supCust_DebtIssue(TableView supIssTab, TableColumn name, TableColumn amtOwed, long total,
        String title, String fileName) {

    try {/* w ww  . j  ava2 s . c  o  m*/
        //            Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png");
        //            im.scaleAbsolute(150f, 150f);
        //            im.setAbsolutePosition(25,50);
        //            im.setBackgroundColor(BaseColor.PINK);

        dNow = new Date();
        String app = this.datForFile.format(dNow);
        String file = "\\Documents\\NjieAB_receipts\\default" + app + ".pdf";
        if (fileName == "SupplierDebt") {
            file = "\\Documents\\NjieAB_receipts\\supplier\\debt " + app + ".pdf";
        } else if (fileName == "CustumerDebt") {
            file = "\\Documents\\NjieAB_receipts\\custumer\\debt " + app + ".pdf";
        }

        System.out.println("file is " + file);
        fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea
        //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf");

        Document doc = new Document();
        PdfWriter writer = PdfWriter.getInstance(doc, fs);
        //specify column widths    
        float[] columnWidths = { 4f, 5f };
        PdfPTable table = new PdfPTable(columnWidths);

        //special font sizes    
        Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0));
        Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10);
        // set table width a percentage of the page width    
        table.setWidthPercentage(90f);

        PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR "));
        cell.setColspan(6);
        cell.setHorizontalAlignment(2);
        doc.open();
        //doc.add(im);

        header(doc, title);

        doc.add(cell);
        System.out.println(doc.leftMargin());

        //insert column headings    
        if (fileName == "SupplierDebt") {
            insertTableHeading(table, "Supplier Name ", Element.ALIGN_MIDDLE, 1, bfBold12);
            insertTableHeading(table, "Total Amount Owing", Element.ALIGN_MIDDLE, 1, bfBold12);
        } else if (fileName == "CustumerDebt") {
            insertTableHeading(table, "Custumer Name ", Element.ALIGN_MIDDLE, 1, bfBold12);
            insertTableHeading(table, "Total Amount Owing", Element.ALIGN_MIDDLE, 1, bfBold12);
        }
        table.setHeaderRows(1);

        /*Now i have to fill the table  */

        for (int i = 0; i < supIssTab.getItems().size(); i++) {
            insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, amtOwed.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
        }

        insertCell(table, "Total ", Element.ALIGN_RIGHT, 1, bfBold12);
        insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 2, bfBold12);
        doc.add(table);

        footer(doc); // this is rgw footer of the page

        doc.addCreationDate();
        doc.close();
        System.out.println("finished the printing job");

        try {
            Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file));
        } catch (IOException iOException) {
            System.out.println("failed opening the file");
        }
    } catch (Exception sd) {
        Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message(
                sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString())
                .showError();
    } finally {
    }

}

From source file:Tables.Printer.java

public void staffBalanceSalary(TableView supIssTab, TableColumn name, TableColumn branch,
        TableColumn amountLeft, long total) {
    String fileName = "StaffBalSalaryt";
    String title = "Staff Balance Salary";

    try {/*  w ww  .j  ava 2  s  .  c om*/
        //            Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png");
        //            im.scaleAbsolute(150f, 150f);
        //            im.setAbsolutePosition(25,50);
        //            im.setBackgroundColor(BaseColor.PINK);

        dNow = new Date();
        String app = this.datForFile.format(dNow);
        String file = "\\Documents\\NjieAB_receipts\\staff\\bal " + app + ".pdf";

        System.out.println("file is " + file);
        fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea
        //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf");

        Document doc = new Document();
        PdfWriter writer = PdfWriter.getInstance(doc, fs);
        //specify column widths    
        float[] columnWidths = { 4f, 5f, 4f };
        PdfPTable table = new PdfPTable(columnWidths);

        //special font sizes    
        Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0));
        Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10);
        // set table width a percentage of the page width    
        table.setWidthPercentage(90f);

        PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR "));
        cell.setColspan(6);
        cell.setHorizontalAlignment(2);
        doc.open();
        //doc.add(im);

        header(doc, title);

        doc.add(cell);
        System.out.println(doc.leftMargin());

        //insert column headings    

        insertTableHeading(table, "Staff Name ", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Branch ", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Salary Left", Element.ALIGN_MIDDLE, 1, bfBold12);

        table.setHeaderRows(1);

        /*Now i have to fill the table  */

        for (int i = 0; i < supIssTab.getItems().size(); i++) {
            insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, branch.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, amountLeft.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);

        }

        insertCell(table, "", Element.ALIGN_RIGHT, 1, bfBold12);
        insertCell(table, "Total ", Element.ALIGN_RIGHT, 1, bfBold12);
        insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 1, bfBold12);
        doc.add(table);

        footer(doc); // this is rgw footer of the page

        doc.addCreationDate();
        doc.close();
        System.out.println("finished the printing job");

        try {
            Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file));
        } catch (IOException iOException) {
            System.out.println("failed opening the file");
        }
    } catch (Exception sd) {
        Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message(
                sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString())
                .showError();
    } finally {
    }

}

From source file:Tables.Printer.java

public void salarySuspension(TableView supIssTab, TableColumn name, TableColumn amount, TableColumn reason,
        TableColumn susDate, TableColumn status, long total) {
    String title = "Salary Suspension";

    try {//from   w w w  .j a v a 2  s .c  o m
        //            Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png");
        //            im.scaleAbsolute(150f, 150f);
        //            im.setAbsolutePosition(25,50);
        //            im.setBackgroundColor(BaseColor.PINK);

        dNow = new Date();
        String app = this.datForFile.format(dNow);
        String file = "\\Documents\\NjieAB_receipts\\staff\\suspension " + app + ".pdf";

        System.out.println("file is " + file);
        fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea
        //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf");

        Document doc = new Document(PageSize.A4, 10, 10, 5, 10);
        PdfWriter writer = PdfWriter.getInstance(doc, fs);
        //specify column widths    
        float[] columnWidths = { 6f, 3f, 8f, 3f, 2f };
        PdfPTable table = new PdfPTable(columnWidths);

        //special font sizes    
        Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0));
        Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10);
        // set table width a percentage of the page width    
        table.setWidthPercentage(90f);

        PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR "));
        cell.setColspan(6);
        cell.setHorizontalAlignment(2);
        doc.open();
        //doc.add(im);

        header(doc, title);

        doc.add(cell);
        System.out.println(doc.leftMargin());

        //insert column headings    

        insertTableHeading(table, "Staff Name ", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Amount ", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Reason", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Date ", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Status", Element.ALIGN_MIDDLE, 1, bfBold12);

        table.setHeaderRows(1);

        /*Now i have to fill the table  */

        for (int i = 0; i < supIssTab.getItems().size(); i++) {
            insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, amount.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, reason.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, susDate.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, status.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);

        }

        insertCell(table, "", Element.ALIGN_RIGHT, 1, bfBold12);
        insertCell(table, "Total ", Element.ALIGN_RIGHT, 1, bfBold12);
        insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 1, bfBold12);
        doc.add(table);

        footer(doc); // this is rgw footer of the page

        doc.addCreationDate();
        doc.close();
        System.out.println("finished the printing job");

        try {
            Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file));
        } catch (IOException iOException) {
            System.out.println("failed opening the file");
        }
    } catch (Exception sd) {
        Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message(
                sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString())
                .showError();
    } finally {
    }

}