Example usage for com.itextpdf.text.pdf PdfPTable setHeaderRows

List of usage examples for com.itextpdf.text.pdf PdfPTable setHeaderRows

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable setHeaderRows.

Prototype

public void setHeaderRows(int headerRows) 

Source Link

Document

Sets the number of the top rows that constitute the header.

Usage

From source file:Tables.PrinterClass.java

/**
 * heading ends//ww  w.  ja v  a2 s. c om
 * @param tabId
 * @param col1
 * @param col2
 * @param tHeading
 * @param fileName
 * @param tTitle
 */
public void print(TableView tabId, TableColumn col1, TableColumn col2, String fileName, String tTitle,
        String[] tHeading) {
    dNow = new Date();
    System.out.println("printing with 2 cols");
    try {
        String completeFileName = this.saveDir + fileName + this.datForFile.format(dNow) + ".pdf";
        completeFileName = System.getProperties().getProperty("user.home") + completeFileName;
        fs = new FileOutputStream(completeFileName); //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

        Document doc = new Document(PageSize.A4, 20, 20, 20, 20);
        PdfWriter writer = PdfWriter.getInstance(doc, fs);

        //specify column widths    
        float[] columnWidths = { 5f, 5f };
        PdfPTable table = new PdfPTable(columnWidths);

        table.setWidthPercentage(90f);

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

        makeCompanyHeading(doc);

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

        for (String tHeading1 : tHeading) {
            insertTableHeading(table, tHeading1, Element.ALIGN_CENTER, 1, this.tHeadingFont);
        }
        table.setHeaderRows(1);

        /*Now i have to fill the table  */
        for (int i = 0; i < tabId.getItems().size(); i++) {
            insertCell(table, col1.getCellData(i).toString(), Element.ALIGN_LEFT, 1, this.tBodyFont);
            insertCell(table, col2.getCellData(i).toString(), Element.ALIGN_LEFT, 1, this.tBodyFont);
        }

        doc.add(table);

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

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

        Dialogs.create().title("Printing complete").masthead("The printing process was completed succesfully")
                .message("See : " + completeFileName).showInformation();
    } catch (Exception sd) {
        sd.printStackTrace();
        Dialogs.create().title("Printer Error").masthead("Errro In Printing File")
                .message("There was an error while trying to print. ").showError();
    } finally {
    }
}

From source file:Tables.PrinterClass.java

/**
 * heading ends/*www .j  av a2 s .  co  m*/
 * @param tabId
 * @param col1
 * @param col2
 * @param tHeading
 * @param fileName
 * @param tTitle
 */
public void print(TableView tabId, TableColumn col1, TableColumn col2, TableColumn col3, String fileName,
        String tTitle, String[] tHeading) {
    dNow = new Date();
    System.out.println("printing with 2 cols");
    try {
        String completeFileName = this.saveDir + fileName + this.datForFile.format(dNow) + ".pdf";
        completeFileName = System.getProperties().getProperty("user.home") + completeFileName;
        fs = new FileOutputStream(completeFileName); //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

        Document doc = new Document(PageSize.A4, 20, 20, 20, 20);
        PdfWriter writer = PdfWriter.getInstance(doc, fs);

        //specify column widths    
        float[] columnWidths = { 4f, 4f, 4f };
        PdfPTable table = new PdfPTable(columnWidths);

        table.setWidthPercentage(90f);

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

        makeCompanyHeading(doc);

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

        for (String tHeading1 : tHeading) {
            insertTableHeading(table, tHeading1, Element.ALIGN_CENTER, 1, this.tHeadingFont);
        }
        table.setHeaderRows(1);

        /*Now i have to fill the table  */
        for (int i = 0; i < tabId.getItems().size(); i++) {
            insertCell(table, col1.getCellData(i).toString(), Element.ALIGN_LEFT, 1, this.tBodyFont);
            insertCell(table, col2.getCellData(i).toString(), Element.ALIGN_LEFT, 1, this.tBodyFont);
            insertCell(table, col3.getCellData(i).toString(), Element.ALIGN_LEFT, 1, this.tBodyFont);
        }

        doc.add(table);

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

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

        Dialogs.create().title("Printing complete").masthead("The printing process was completed succesfully")
                .message("See : " + completeFileName).showInformation();
    } catch (Exception sd) {
        sd.printStackTrace();
        Dialogs.create().title("Printer Error").masthead("Errro In Printing File")
                .message("There was an error while trying to print. ").showError();
    } finally {
    }
}

From source file:timeclock.reports.EmployeeListReport.java

@Override
public PdfPTable createTable(List list) {
    PdfPTable table = new PdfPTable(new float[] { 2, 3, 4, 1, 1 });
    table.setWidthPercentage(100f);/*  ww w  . j  a  v  a  2 s . c o  m*/
    PdfPCell dCell = table.getDefaultCell();
    dCell.setUseAscender(true);
    dCell.setUseDescender(true);
    dCell.setPadding(3);
    dCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    dCell.setBackgroundColor(BaseColor.DARK_GRAY);

    table.addCell(new Phrase("Employee ID", MyFonts.font.get("header")));
    table.addCell(new Phrase("First Name", MyFonts.font.get("header")));
    table.addCell(new Phrase("Last Name", MyFonts.font.get("header")));
    table.addCell(new Phrase("Salary", MyFonts.font.get("header")));
    table.addCell(new Phrase("Admin", MyFonts.font.get("header")));

    dCell.setBackgroundColor(null);
    table.setHeaderRows(1);
    table.setFooterRows(0);

    // used for alternating row color
    int rowCount = 0;
    // Display all employees
    for (Object obj : list) {
        Employee emp = (Employee) obj;
        rowCount++;
        dCell.setBackgroundColor((rowCount % 2 == 0 ? BaseColor.LIGHT_GRAY : null));

        table.addCell(new Paragraph(Integer.toString(emp.getEmployeeID()), MyFonts.font.get("normal")));
        table.addCell(new Paragraph(emp.getFirstName(), MyFonts.font.get("normal")));
        table.addCell(new Paragraph(emp.getLastName(), MyFonts.font.get("normal")));
        table.addCell(new Paragraph(emp.getIsSalary_bool() ? "Yes" : "No", MyFonts.font.get("normal")));
        table.addCell(new Paragraph(emp.getIsAdmin_bool() ? "Yes" : "No", MyFonts.font.get("normal")));
    }

    return table;
}

From source file:timeclock.reports.EmployeeTimeReport.java

@Override
public PdfPTable createTable(List list) {
    // Create table and set basic table properties
    PdfPTable table = new PdfPTable(new float[] { 1, 4, 4, 3 });
    table.setWidthPercentage(100f);//from  w  w w .  ja va2  s .c o m
    PdfPCell dCell = table.getDefaultCell();
    dCell.setUseAscender(true);
    dCell.setUseDescender(true);
    dCell.setPadding(3);
    dCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    // Set header background color
    dCell.setBackgroundColor(BaseColor.DARK_GRAY);

    // Display the employee first in header
    table.addCell(new Phrase(Integer.toString(employee.getEmployeeID()), MyFonts.font.get("header")));
    table.addCell(new Phrase(employee.getFirstName(), MyFonts.font.get("header")));
    table.addCell(new Phrase(employee.getLastName(), MyFonts.font.get("header")));
    table.addCell(new Phrase("", MyFonts.font.get("header")));
    // Display the column names in header
    table.addCell(new Phrase("", MyFonts.font.get("header")));
    table.addCell(new Phrase("Time In", MyFonts.font.get("header")));
    table.addCell(new Phrase("Time Out", MyFonts.font.get("header")));
    table.addCell(new Phrase("Time Worked", MyFonts.font.get("header")));

    // Reset the cell background color
    dCell.setBackgroundColor(null);
    // Set the number of rows included in the header and footer
    table.setHeaderRows(2);
    table.setFooterRows(0);

    // Make a variable to hold the total of all time worked            
    long totalTimeDiff = 0;
    // used for alternating row color
    int rowCount = 0;
    // Display all time punches
    for (Object obj : list) {
        TimePunch tp = (TimePunch) obj;
        rowCount++;
        dCell.setBackgroundColor((rowCount % 2 == 0 ? BaseColor.LIGHT_GRAY : null));

        Timestamp ts1, ts2;
        ts1 = tp.getPunchInTimestamp();
        ts2 = tp.getPunchOutTimestamp();
        totalTimeDiff += ts2.getTime() - ts1.getTime();
        String id = Integer.toString(tp.getPunchId());
        String in = DateUtils.getDateTimeFromTimestamp(ts1);
        String out = DateUtils.getDateTimeFromTimestamp(ts2);
        String diff = DateUtils.getTimestampDiff_Str(ts1, ts2);
        // Add information to row
        table.addCell(new Paragraph("", MyFonts.font.get("normal")));
        table.addCell(new Paragraph(in, MyFonts.font.get("normal")));
        table.addCell(new Paragraph(out, MyFonts.font.get("normal")));
        table.addCell(new Paragraph(diff, MyFonts.font.get("normal")));
    }

    // Set background to null
    dCell.setBackgroundColor(null);
    // Get total time worked and create a totals row
    table.addCell(new Paragraph("", MyFonts.font.get("normal")));
    table.addCell(new Paragraph("", MyFonts.font.get("normal")));
    table.addCell(new Paragraph("Total:", MyFonts.font.get("bold")));
    table.addCell(new Paragraph(DateUtils.getTimeStrFromLong(totalTimeDiff), MyFonts.font.get("bold")));

    return table;
}

From source file:tn.com.hitechart.eds.Util.pdfRpport.FirstPdf.java

private void createTable(Section subCatPart) throws BadElementException {

    //-------------------------- TAB POINTAGE -------------------//
    PdfPTable table = new PdfPTable(8);
    table.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    table.setLockedWidth(true);//from w  w w  .j  av a  2s. c  om
    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);
    //----------- C1 --------------//
    PdfPCell c1 = new PdfPCell(new Phrase("Date Rapport"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C2 --------------//
    c1 = new PdfPCell(new Phrase("Technicien"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C3 --------------//
    c1 = new PdfPCell(new Phrase("Poinatge"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    //----------- C4 --------------//
    c1 = new PdfPCell(new Phrase("Matin"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    //----------- C5 --------------//
    c1 = new PdfPCell(new Phrase("Aprs-Midi"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    //----------- C6 --------------//
    c1 = new PdfPCell(new Phrase("Rapport Journalier", catFont));
    c1.setBorder(Rectangle.NO_BORDER);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setColspan(3);
    table.addCell(c1);
    //----------- C7 --------------//

    //----------- C8 --------------//

    table.setHeaderRows(1);

    //----------- R2 --------------//
    //----------- C1 --------------//
    c1 = new PdfPCell(new Phrase(tabDatapointage[0], dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setRowspan(2);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(user.getLogin(), dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setRowspan(2);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Arrive"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(tabDatapointage[1], dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(tabDatapointage[2], dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C7 --------------//

    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C8 --------------//

    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);

    //----------- R3 --------------//

    c1 = new PdfPCell(new Phrase("Sortie"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(tabDatapointage[3], dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(tabDatapointage[4], dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C7 --------------//
    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C8 --------------//
    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    table.setSpacingAfter(10);
    subCatPart.add(table);

    //-------------------------- END TAB POINTAGE -------------------//
    // TODO: 20/01/2017
    //--------------------------------- TASK ---------------------//
    PdfPTable tableTask = new PdfPTable(5);

    tableTask.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    tableTask.setLockedWidth(true);

    PdfPCell c2 = new PdfPCell(new Phrase("Dossiers Traits", catFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    c2.setColspan(5);
    c2.setBorder(Rectangle.NO_BORDER);
    tableTask.addCell(c2);

    tableTask.setHeaderRows(1);

    c2 = new PdfPCell(new Phrase("NDoss.", dataFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableTask.addCell(c2);

    c2 = new PdfPCell(new Phrase("Client", dataFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableTask.addCell(c2);

    c2 = new PdfPCell(new Phrase("Dure", dataFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableTask.addCell(c2);

    c2 = new PdfPCell(new Phrase("Mission", dataFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableTask.addCell(c2);

    c2 = new PdfPCell(new Phrase("Resultat", dataFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableTask.addCell(c2);
    if (tasks.isEmpty()) {
        c2 = new PdfPCell(new Phrase("Aucune  Tache a t trait", catFontempty));
        c2.setHorizontalAlignment(Element.ALIGN_CENTER);
        c2.setColspan(5);
        tableTask.addCell(c2);
    } else {

        if (!dossiers.isEmpty()) {
            for (Dossier d : dossiers) {

                tableTask.addCell(d.getNumDoss());
                tableTask.addCell(d.getClient());
                tableTask.addCell(convertLongtoDurationfr(d.getTimeDuration()));
                tableTask.addCell(td.getTaskById(d.get_idTask()).getType());
                tableTask.addCell(td.getTaskById(d.get_idTask()).getRes());
            }
        }

    }

    tableTask.setSpacingAfter(10);

    subCatPart.add(tableTask);

    //-------------------------- END TAB TASK -------------------//
    // TODO: 20/01/2017  tab achat
    //-------------------------- TAB ACHAT -------------------//

    PdfPTable tableAchat = new PdfPTable(3);

    tableAchat.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    tableAchat.setLockedWidth(true);

    PdfPCell c3 = new PdfPCell(new Phrase("Frais Engags", catFont));
    c3.setHorizontalAlignment(Element.ALIGN_CENTER);
    c3.setColspan(3);
    c3.setBorder(Rectangle.NO_BORDER);
    tableAchat.addCell(c3);

    tableAchat.setHeaderRows(1);
    c3 = new PdfPCell(new Phrase("N.Doss.", dataFont));
    c3.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableAchat.addCell(c3);

    c3 = new PdfPCell(new Phrase("Dsignation", dataFont));
    c3.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableAchat.addCell(c3);

    c3 = new PdfPCell(new Phrase("Montant TCC", dataFont));
    c3.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableAchat.addCell(c3);
    if (achats.isEmpty()) {
        c3 = new PdfPCell(new Phrase("la liste des achats est vide", catFontempty));
        c3.setHorizontalAlignment(Element.ALIGN_CENTER);
        c3.setColspan(3);
        tableAchat.addCell(c3);
    } else {

        for (Achat achat : achats) {

            tableAchat.addCell(String.valueOf(achat.getNumDoss()));
            tableAchat.addCell(achat.getDesignation());
            tableAchat.addCell(String.valueOf(achat.getPrix()));
        }
    }
    tableAchat.setSpacingAfter(10);
    subCatPart.add(tableAchat);
    //-------------------------- END TAB ACHAT -------------------//

    // TODO: 20/01/2017  tab composant
    //-------------------------- TAB COMPOSANT -------------------//

    PdfPTable tableComp = new PdfPTable(3);

    tableComp.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    tableComp.setLockedWidth(true);

    PdfPCell c4 = new PdfPCell(new Phrase("Composants", catFont));
    c4.setHorizontalAlignment(Element.ALIGN_CENTER);
    c4.setColspan(3);
    c4.setBorder(Rectangle.NO_BORDER);
    tableComp.addCell(c4);
    tableComp.setHeaderRows(1);

    c4 = new PdfPCell(new Phrase("N.Doss.", dataFont));
    c4.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableComp.addCell(c4);

    c4 = new PdfPCell(new Phrase("Dsignation", dataFont));
    c4.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableComp.addCell(c4);

    c4 = new PdfPCell(new Phrase("Quantit", dataFont));
    c4.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableComp.addCell(c4);

    if (comps.isEmpty()) {
        c4 = new PdfPCell(new Phrase("la liste des composants est vide", catFontempty));
        c4.setHorizontalAlignment(Element.ALIGN_CENTER);
        c4.setColspan(3);
        tableComp.addCell(c4);
    } else {
        for (Composant comp : comps) {

            tableComp.addCell(String.valueOf(comp.getNumDoss()));
            tableComp.addCell(comp.getName());
            tableComp.addCell(String.valueOf(comp.getQte()));
        }
    }
    tableComp.setSpacingAfter(10);
    subCatPart.add(tableComp);
    //-------------------------- END TAB COMPOSANT -------------------//

    // TODO: 20/01/2017  tab message
    //-------------------------- TAB MESSAGE -------------------//

    PdfPTable tableMsg = new PdfPTable(2);

    tableMsg.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    tableMsg.setLockedWidth(true);

    PdfPCell c5 = new PdfPCell(new Phrase("Message  Transmettre", catFont));
    c5.setHorizontalAlignment(Element.ALIGN_CENTER);
    c5.setColspan(3);
    c5.setBorder(Rectangle.NO_BORDER);
    tableMsg.addCell(c5);

    c5 = new PdfPCell(new Phrase("N.Doss.", dataFont));
    c5.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableMsg.addCell(c5);

    tableMsg.setHeaderRows(1);
    c5 = new PdfPCell(new Phrase("Message", dataFont));
    c5.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableMsg.addCell(c5);

    tableMsg.setHeaderRows(1);
    if (msgs.isEmpty()) {
        c5 = new PdfPCell(new Phrase("Aucun message", catFontempty));
        c5.setHorizontalAlignment(Element.ALIGN_CENTER);
        c5.setColspan(3);
        tableMsg.addCell(c5);
    } else {
        for (Message msg : msgs) {

            tableMsg.addCell(String.valueOf(msg.getNumDoss()));
            tableMsg.addCell(msg.getMsg());
        }
    }
    tableMsg.setSpacingAfter(10);
    subCatPart.add(tableMsg);
    //-------------------------- END TAB MESSAGE -------------------//

    // TODO: 20/01/2017  tab Activitee
    //-------------------------- TAB ACTIVITEE -------------------//

    PdfPTable tableAct = new PdfPTable(2);

    tableAct.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    tableAct.setLockedWidth(true);

    PdfPCell c6 = new PdfPCell(new Phrase("Autre Activites", catFont));
    c6.setHorizontalAlignment(Element.ALIGN_CENTER);
    c6.setColspan(2);
    c6.setBorder(Rectangle.NO_BORDER);
    tableAct.addCell(c6);

    tableAct.setHeaderRows(1);

    c6 = new PdfPCell(new Phrase("N.Doss.", dataFont));
    c6.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableAct.addCell(c6);

    c6 = new PdfPCell(new Phrase("Dure", dataFont));
    c6.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableAct.addCell(c6);
    if (autreActs.isEmpty()) {
        c6 = new PdfPCell(new Phrase("Aucune autre Activite a t effectu", catFontempty));
        c6.setHorizontalAlignment(Element.ALIGN_CENTER);
        c6.setColspan(3);
        tableAct.addCell(c6);
    } else {

        for (Task autreA : autreActs) {

            tableAct.addCell(String.valueOf(autreA.getType()));
            tableAct.addCell(autreA.getNumDoss());
        }

    }
    tableAct.setSpacingAfter(10);
    subCatPart.add(tableAct);
    //-------------------------- END TAB MESSAGE -------------------//
}

From source file:uk.ac.openmf.utils.OpenMFPDFGenerator.java

private static void createLAOTable(Section subCatPart, String clientId) throws DocumentException {
    PdfPTable table = new PdfPTable(5);

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);

    PdfPCell c1 = new PdfPCell(new Phrase("Loan Acc#"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);//from w ww .java 2s.  c om

    c1 = new PdfPCell(new Phrase("Loan Code"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Approved Amount"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("OutStd Amount"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Start Date"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    float[] columnWidths = new float[] { 10f, 10f, 15f, 15f, 10f };
    table.setWidths(columnWidths);
    table.setHeaderRows(1);

    ArrayList<OpenMFLoanAccount> loanAccounts = OMFUtils.getLoanAccountsByClientList(clientId);
    //ArrayList<OpenMFSavingsAccount> savingsAccounts = OMFUtils.getSavingsAccountsByClientList(clientId);
    for (OpenMFLoanAccount openMFLoanAccount : loanAccounts) {
        table.addCell(openMFLoanAccount.getLoanaccountnumber());
        table.addCell(openMFLoanAccount.getLoancode());
        table.addCell(openMFLoanAccount.getApprovedamount());
        table.addCell(openMFLoanAccount.getBalanceoutstandingamount());
        table.addCell(openMFLoanAccount.getLoanstartdate());
    }

    subCatPart.add(table);

}

From source file:uk.ac.openmf.utils.OpenMFPDFGenerator.java

private static void createSAOTable(Section subCatPart, String clientId) throws DocumentException {
    PdfPTable table = new PdfPTable(5);

    PdfPCell c1 = new PdfPCell(new Phrase("Savings Acc#"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);/*from ww w  .j a v  a  2s .c o  m*/

    c1 = new PdfPCell(new Phrase("Savings Code"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Available Balance"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Total# Deposits"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Matures On"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    float[] columnWidths = new float[] { 10f, 10f, 15f, 15f, 10f };
    table.setWidths(columnWidths);
    table.setHeaderRows(1);

    ArrayList<OpenMFSavingsAccount> savingsAccounts = OMFUtils.getSavingsAccountsByClientList(clientId);
    for (OpenMFSavingsAccount openMFSavingsAccount : savingsAccounts) {
        table.addCell(openMFSavingsAccount.getSavingsaccountnumber());
        table.addCell(openMFSavingsAccount.getSavingscode());
        table.addCell(openMFSavingsAccount.getAvailablebalance());
        table.addCell(openMFSavingsAccount.getTotalnumdeposits());
        table.addCell(openMFSavingsAccount.getMatureson());
    }

    subCatPart.add(table);

}

From source file:uk.ac.openmf.utils.OpenMFPDFGenerator.java

private static void createTasksTable(Section subCatPart, String omfuId) throws DocumentException {
    PdfPTable table = new PdfPTable(5);

    PdfPCell c1 = new PdfPCell(new Phrase("Task#"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);//from w  w  w .  j  av  a 2s  . c om

    c1 = new PdfPCell(new Phrase("Date Assigned"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Amount"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Acc#"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Type"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    float[] columnWidths = new float[] { 10f, 10f, 15f, 15f, 10f };
    table.setWidths(columnWidths);
    table.setHeaderRows(1);

    OpenMFUser omfuser = null;
    if (omfuId != null) {
        omfuser = AppContext.getAppContext().getUserManager().getUser(ServletUtils.validateEventId(omfuId));
    }

    ArrayList<OpenMFTask> tasks = OMFUtils.getTasksByUsername(omfuser.getUsername(), false);
    for (OpenMFTask task : tasks) {
        table.addCell(task.getTaskId());
        table.addCell(task.getDateassigned());
        table.addCell(task.getAmount());
        table.addCell(task.getAccountnumber());
        table.addCell(task.getCollectiontype());
    }

    subCatPart.add(table);

}

From source file:Utility.PDFDemo.java

public PdfPTable reports() {
    //specify column widths
    float[] columnWidths = { .2f, .2f, .2f, .2f, .2f, .2f };

    //create PDF table with the given widths
    PdfPTable table = new PdfPTable(columnWidths);
    //PdfPTable table = new PdfPTable(10);

    // set table width a percentage of the page width
    table.setWidthPercentage(100f);/*  w  ww  . j a  v a2  s .  co m*/

    try {

        /*
                
         IT REPORT GENERATION BLOCK
                
         */
        //insert column headings
        insertCell(table, "Farmer Name", Element.ALIGN_CENTER, 1, bfBold8);
        insertCell(table, "Replante Date", Element.ALIGN_CENTER, 1, bfBold8);
        insertCell(table, "Treated farms", Element.ALIGN_CENTER, 1, bfBold8);
        insertCell(table, "District", Element.ALIGN_CENTER, 1, bfBold8);
        insertCell(table, "Number of Trees Cut", Element.ALIGN_CENTER, 1, bfBold8);
        insertCell(table, "Farmer Number ", Element.ALIGN_CENTER, 1, bfBold8);
        //insertCell(table, "Farm size Replanted", Element.ALIGN_CENTER, 1, bfBold8);

        table.setHeaderRows(1);

        ResultSet rs = manager.PDFdemos();
        int Tresscut = 0;
        float allFarmSize = 0;

        //Populating Feilds            
        while (rs.next()) {

            insertCell(table, rs.getString(3), Element.ALIGN_RIGHT, 1, bf8);
            insertCell(table, rs.getString(4), Element.ALIGN_LEFT, 1, bf8);
            insertCell(table, rs.getFloat(2) + "", Element.ALIGN_RIGHT, 1, bf8);
            insertCell(table, rs.getString(6), Element.ALIGN_LEFT, 1, bf8);
            insertCell(table, rs.getInt(5) + "", Element.ALIGN_RIGHT, 1, bf8);
            insertCell(table, rs.getString(1), Element.ALIGN_LEFT, 1, bf8);
            //insertCell(table, rs.getString(7) + "", Element.ALIGN_RIGHT, 1, bf8);

            allFarmSize += rs.getFloat(2);
            Tresscut += rs.getInt(5);
        }

        insertCell(table, "TOTAL FARMS TREATED:         " + manager.totalReports(), Element.ALIGN_CENTER, 2,
                bfBold12);
        insertCell(table, "Total Treated Farm Size:       " + String.format("%.2f", allFarmSize),
                Element.ALIGN_CENTER, 2, bfBold8);
        insertCell(table, "Total Treescut:    " + Tresscut + "", Element.ALIGN_CENTER, 2, bfBold8);
        //insertCell(table, "        ", Element.ALIGN_CENTER, 3, bfBold8);
        //insertCell(table, "         ", Element.ALIGN_CENTER, 1, bfBold8);
        //insertCell(table, "          ", Element.ALIGN_CENTER, 1, bfBold8);
        //insertCell(table,  "Total Treated Farm Size:       "+String.format("%.2f", allFarmSize), Element.ALIGN_CENTER, 1, bfBold8);

    } //Try ends here
    catch (SQLException ex) {
        Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
    }

    return table;
}

From source file:utils.PrintInvoice.java

public void getDocument() {
    try {//  w ww  . j  a v a 2s .com
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("SaleBill#" + salebill.getId() + ".pdf"));

        document.open();
        ////////////////////////////////////////////////////////////////////////////////////
        ///////////////////Start Document Here/////////////////////////////////
        PdfContentByte directContent = writer.getDirectContent();
        Paragraph p1 = new Paragraph("SALE BILL");
        p1.setFont(FONT[4]);
        p1.setAlignment(Element.ALIGN_CENTER);

        document.add(p1);
        //show the company details here.
        Phrase company = new Phrase(new Chunk("BIO PHARMA\nAKOT 444101(M.S)", FONT[3]));
        document.add(company);
        document.add(new Phrase(
                "\nLicense No : 20B : AK-88888\n                     21B : AK-88889\n       Mobile : "
                        + SessionClass.getInstance().getMobileNumber(),
                FONT[2]));

        //            Phrase mobNum  = new Phrase("    Mobile : "+SessionClass.getInstance().getMobileNumber() );
        //            mobNum.setFont(FONT[2]);
        //            ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, mobNum, 35, 710, 0);

        System.out.println(dateFormatter.format(salebill.getBillDate()));
        //show the invoice details
        //  String txt = "Bill No. : " + salebill.getId()+"\nBill Date : " + dateFormatter.format(salebill.getBillDate()) +;
        Phrase invoiceDetails = new Phrase("Bill No. : " + salebill.getId());
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 693, 0);
        invoiceDetails = new Phrase("Bill Date : " + dateFormatter2.format(salebill.getBillDate()));
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 681, 0);
        invoiceDetails = new Phrase("Mode of Payment : " + salebill.getMode());
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 668, 0);

        //show the customer details
        Customer c = salebill.getCustomerId();
        Phrase custDetails = new Phrase("SOLD TO", FONT[3]);
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 693, 0);
        custDetails = new Phrase(c.getCompanyName());
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 681, 0);
        custDetails = new Phrase(c.getSiteAddress());
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 668, 0);
        custDetails = new Phrase("Licence : " + c.getLicenceNo());
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 655, 0);

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

        //Item Particulars are shown here
        PdfPTable table = new PdfPTable(7);
        table.setTotalWidth(new float[] { 175, 80, 80, 50, 50, 50, 75 });
        table.setHeaderRows(1);

        //headers
        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell("Particulars");
        table.addCell("Batch");
        table.addCell("Expiry");
        table.addCell("MRP");
        table.addCell("Rate");
        table.addCell("Qnty");
        table.addCell("SubTotal");
        table.getDefaultCell().setBackgroundColor(null);
        table.setSpacingAfter(5.0f);

        List<SaleBillPharmaItem> items = salebill.getSaleBillPharmaItemList();
        for (int i = 0; i < items.size(); i++) {
            PdfPCell desc = new PdfPCell(new Phrase(items.get(i).getItemName()));

            table.addCell(desc);

            PdfPCell batch = new PdfPCell(new Phrase(items.get(i).getBatch()));

            table.addCell(batch);

            PdfPCell expiry = null;
            Date tDate = null;
            try {
                tDate = dateFormatter2.parse(items.get(i).getExpDate());
            } catch (ParseException ex) {
                Logger.getLogger(PrintInvoice.class.getName()).log(Level.SEVERE, null, ex);
            }

            expiry = new PdfPCell(new Phrase(dateFormatter.format(tDate)));

            table.addCell(expiry);

            PdfPCell mrp = new PdfPCell(new Phrase(items.get(i).getMrp() + ""));
            //                 //mrp.setBorderColor(BaseColor.WHITE);
            //                 mrp.setBorderColorLeft(BaseColor.BLACK);
            //                 mrp.setBorderColorRight(BaseColor.WHITE);
            table.addCell(mrp);
            PdfPCell rate = new PdfPCell(new Phrase(items.get(i).getItemRate() + ""));
            //                 //rate.setBorderColor(BaseColor.WHITE);
            //                 rate.setBorderColorLeft(BaseColor.BLACK);
            //                 rate.setBorderColorRight(BaseColor.WHITE);
            table.addCell(rate);
            PdfPCell quantity = new PdfPCell(new Phrase(items.get(i).getQnty() + ""));
            //                 //quantity.setBorderColor(BaseColor.WHITE);
            //                 quantity.setBorderColorLeft(BaseColor.BLACK);
            //                 quantity.setBorderColorRight(BaseColor.WHITE);
            table.addCell(quantity);
            PdfPCell subtotal = new PdfPCell(new Phrase(items.get(i).getAmt() + ""));
            //                 //subtotal.setBorderColor(BaseColor.WHITE);
            //                 subtotal.setBorderColorLeft(BaseColor.BLACK);
            //                 subtotal.setBorderColorRight(BaseColor.WHITE);
            table.addCell(subtotal);

        }

        //now show the sub details
        //PdfPCell finalCell = new PdfPCell(new Phrase("Total VAT Amt : Rs " + salebill.getTotalVat() + "                     Total Amount : Rs "));
        //Todo change code here to show vat amount when there is vat number
        PdfPCell finalCell = new PdfPCell(
                new Phrase("Total VAT Amt : Rs " + salebill.getTotalVat() + "           Total Amount : Rs "));
        finalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        finalCell.setColspan(6);
        table.addCell(finalCell);
        table.addCell("" + salebill.getTotalAmt());

        PdfPCell cdCell = new PdfPCell(new Phrase("Cash Discount (2 %) : (-) Rs"));
        cdCell.setColspan(6);
        cdCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cdCell);
        table.addCell("" + salebill.getDiscount());

        PdfPCell finalAmtCell = new PdfPCell(new Phrase("Final Amount : Rs"));
        finalAmtCell.setColspan(6);
        finalAmtCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(finalAmtCell);
        table.addCell("" + salebill.getFinalAmt());

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

        Paragraph sign = new Paragraph(new Chunk("Authorized signatory\n(BIO PHARMA)"));
        sign.setAlignment(Element.ALIGN_RIGHT);
        document.add(sign);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);

        document.add(Chunk.NEWLINE);

        Paragraph p = new Paragraph("THANK YOU FOR YOUR BUSINESS");
        p.setFont(FONT[4]);
        p.setAlignment(Element.ALIGN_CENTER);
        document.add(p);

        ///////////////////End Documnet here//////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////
        document.close(); // no need to close PDFwriter?

    } catch (DocumentException | FileNotFoundException e) {
        //LOGGER
        e.printStackTrace();
        Stage dialogStage = new Stage();
        dialogStage.setTitle("Printing Error");
        dialogStage.initModality(Modality.WINDOW_MODAL);
        dialogStage.setScene(new Scene(VBoxBuilder.create()
                .children(new Text(
                        "The file to be printed is already open \n. Please close the file and Print Again"))
                .alignment(Pos.CENTER).padding(new Insets(50)).build()));
        dialogStage.show();
    }

}