Example usage for com.itextpdf.text Document leftMargin

List of usage examples for com.itextpdf.text Document leftMargin

Introduction

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

Prototype


public float leftMargin() 

Source Link

Document

Returns the left margin.

Usage

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 {//  w ww .ja va2 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 {/*from   w  ww.ja va 2s .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\\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 {/*from w  w  w  .  j  ava  2  s  . com*/
        //            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  .  jav  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 {
    }

}

From source file:Tables.Printer.java

public void staffSalaryPayments(TableView supIssTab, TableColumn name, TableColumn monthlySalary,
        TableColumn salaryPaid, TableColumn payDate, long total) {
    String fileName = "staffPayment";
    String title = "Staff Payment History";

    try {/*www .ja  va2  s.co 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\\pay " + 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 = { 6f, 4f, 4f, 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, "Monthly Salary ", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Salary Paid", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Payment Date", 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, monthlySalary.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, salaryPaid.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, payDate.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 supCust_PayDebt(TableView supPayTab, TableColumn name, TableColumn debtPayment,
        TableColumn paymtDate, long total, String title, String fileName) {

    try {/*w ww  .j a v a 2s  . 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 == "SupplierDebtPayment") {
            file = "\\Documents\\NjieAB_receipts\\supplier\\pay " + app + ".pdf";
        } else if (fileName == "CustumerDebtPayment") {
            file = "\\Documents\\NjieAB_receipts\\custumer\\pay " + app + ".pdf";
        } else if (fileName == "StaffBalSalaryt") {
            file = "\\Documents\\NjieAB_receipts\\staff\\balance " + 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, 3f };
        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, 12);
        // 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 == "SupplierDebtPayment") {
            insertTableHeading(table, "Supplier Name ", Element.ALIGN_MIDDLE, 1, bfBold12);
            insertTableHeading(table, "Amount Owing", Element.ALIGN_MIDDLE, 1, bfBold12);
            insertTableHeading(table, "Date Issued", Element.ALIGN_MIDDLE, 1, bfBold12);
        } else if (fileName == "CustumerDebtPayment") {
            insertTableHeading(table, "Custumer Name ", Element.ALIGN_MIDDLE, 1, bfBold12);
            insertTableHeading(table, "Amount Owing", Element.ALIGN_MIDDLE, 1, bfBold12);
            insertTableHeading(table, "Date Issued", Element.ALIGN_MIDDLE, 1, bfBold12);
        } else if (fileName == "StaffBalSalaryt") {
            insertTableHeading(table, "Staff Name ", Element.ALIGN_MIDDLE, 1, bfBold12);
            insertTableHeading(table, "Branch", Element.ALIGN_MIDDLE, 1, bfBold12);
            insertTableHeading(table, "Balance Amount", Element.ALIGN_MIDDLE, 1, bfBold12);
        }
        table.setHeaderRows(1);

        /*Now i have to fill the table  */

        for (int i = 0; i < supPayTab.getItems().size(); i++) {
            insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, debtPayment.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, paymtDate.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);
        insertCell(table, "", Element.ALIGN_RIGHT, 3, 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 (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.PrinterClass.java

/**
 * heading ends//from  w  w w. j  ava 2s  . 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/*  w w w. j av  a  2s . com*/
 * @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:utilities.Footer.java

@Override
public void onEndPage(PdfWriter writer, Document document) {
    PdfContentByte cb = writer.getDirectContent();
    Phrase header = new Phrase("ZLECENIE SERWISOWE", ffont);

    Phrase footer = new Phrase("ZLECENIE SERWISOWE", ffont);
    ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer,
            (document.right() - document.left()) / 2 + document.leftMargin(), 20, 0);

    ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, header,
            (document.right() - document.left()) / 2 + document.leftMargin(), document.top() + 10, 0);

}

From source file:windows.wzListWindow.java

private void printDocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printDocActionPerformed
    Document document = new Document();
    Footer ft = new Footer();
    companyAdress comp = new companyAdress();

    try {/*from   w  ww  . ja v  a2  s  .co m*/
        BaseFont ft1 = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
        Font ffont = new Font(ft1, 12);

        BaseFont ft3 = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
        Font bold = new Font(ft1, 12, Font.BOLD);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("test.pdf"));
        document.open();
        Paragraph pr = new Paragraph();
        pr.setFont(ffont);
        writer.setPageEvent(ft);
        ContractorEntity contractor = wz
                .getContractor(Integer.valueOf(WZTable.getValueAt(WZTable.getSelectedRow(), 2).toString()));
        pr.add(WZTable.getValueAt(WZTable.getSelectedRow(), 4).toString());
        pr.setAlignment(Element.ALIGN_RIGHT);
        document.add(pr);
        pr.clear();
        if ("SPRZT WYDANY".equals(WZTable.getValueAt(WZTable.getSelectedRow(), 11).toString())) {
            Paragraph nr = new Paragraph("WYADNIE SPRZTU NR ", ffont);
            String yearSlashnr = WZTable.getValueAt(WZTable.getSelectedRow(), 1).toString();
            nr.add(new Chunk(yearSlashnr, bold));
            nr.setAlignment(Element.ALIGN_LEFT);
            document.add(nr);
            if ("WS".equals(WZTable.getValueAt(WZTable.getSelectedRow(), 12).toString())) {
                pr.setAlignment(Element.ALIGN_LEFT);
                DocEntity docPS = wz.getDocument(wz.getPSForWs(
                        Integer.valueOf(WZTable.getValueAt(WZTable.getSelectedRow(), 0).toString())));
                pr.add("DOTYCZY: PS NR " + docPS.getDocNumber());
                document.add(pr);
                pr.clear();
                pr.setAlignment(Element.ALIGN_RIGHT);
            }
        }

        if ("SPRZT PRZYJTY".equals(WZTable.getValueAt(WZTable.getSelectedRow(), 11).toString())) {
            int rok = Timestamp.valueOf(WZTable.getValueAt(WZTable.getSelectedRow(), 4).toString()).getYear()
                    + 1900;
            Paragraph nr = new Paragraph("PRZYJCIE SPRZTU NR ", ffont);
            String yearSlashnr = rok + "/" + WZTable.getValueAt(WZTable.getSelectedRow(), 1).toString();
            nr.add(new Chunk(yearSlashnr, bold));
            nr.setAlignment(Element.ALIGN_LEFT);
            document.add(nr);
        }
        pr.clear();
        pr.add(Chunk.NEWLINE);
        pr.add(Chunk.NEWLINE);
        document.add(pr);
        pr.clear();
        pr.setAlignment(Element.ALIGN_LEFT);
        pr.add(comp.getName());
        pr.add(Chunk.NEWLINE);
        pr.add("ul. " + comp.getStreet());
        pr.add(Chunk.NEWLINE);
        pr.add(comp.getPostal() + " " + comp.getCity());
        pr.add(Chunk.NEWLINE);
        pr.add("NIP: " + comp.getNip());
        pr.add(Chunk.NEWLINE);
        pr.add("Tel: " + comp.getPhone());
        pr.add(Chunk.NEWLINE);
        pr.add("Fax: " + comp.getFax());
        pr.add(Chunk.NEWLINE);
        pr.add("E-mail: " + comp.getEmail());
        pr.add(Chunk.NEWLINE);
        pr.add(Chunk.NEWLINE);
        pr.add("KLIENT:");
        pr.add(Chunk.NEWLINE);
        pr.add(contractor.getName());
        pr.add(Chunk.NEWLINE);
        pr.add("ul. " + contractor.getStreet());
        pr.add(Chunk.NEWLINE);
        pr.add(contractor.getPostalCode() + " " + contractor.getCity());
        pr.add(Chunk.NEWLINE);
        pr.add("NIP: " + contractor.getNip());
        pr.add(Chunk.NEWLINE);
        pr.add("Tel: " + contractor.getPhone());
        pr.add(Chunk.NEWLINE);
        pr.add("E-mail: " + contractor.getEmail());
        document.add(pr);

        pr.clear();
        pr.add(Chunk.NEWLINE);
        pr.add(Chunk.NEWLINE);
        pr.add("PRZYJTE URZDZENIA:");
        document.add(pr);

        //PUT IMAGE FROM DRIVE
        java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage("C:/GIT/support/logo.jpg");
        Image img = com.itextpdf.text.Image.getInstance(awtImage, null);
        int indentation = 0;
        float scaler = ((document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin()
                - indentation) / img.getWidth()) * 20;
        img.scalePercent(scaler);
        img.setAbsolutePosition(document.right() - 90, document.top() - 150);
        document.add(new Paragraph());
        document.add(img);

        //ADD TABLE

        PdfPTable table = new PdfPTable(7); // 3 columns.
        table.setWidthPercentage(100); //Width 100%
        table.setSpacingBefore(10f); //Space before table
        table.setSpacingAfter(10f); //Space after table
        //Set Column widths
        float[] columnWidths = { 1f, 4f, 3f, 2f, 2f, 6f, 6f };
        table.setWidths(columnWidths);
        BaseFont ft2 = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
        Font headerFont = new Font(ft2, 9);
        Paragraph pos1 = new Paragraph("", headerFont);
        Paragraph pos2 = new Paragraph("", headerFont);
        Paragraph pos3 = new Paragraph("", headerFont);
        Paragraph pos4 = new Paragraph("", headerFont);
        Paragraph pos5 = new Paragraph("", headerFont);
        Paragraph pos6 = new Paragraph("", headerFont);
        Paragraph pos7 = new Paragraph("", headerFont);

        //FORMATING TABLE
        pos1.clear();
        pos1.add("LP");
        PdfPCell cell1 = new PdfPCell(pos1);
        cell1.setBorderColor(BaseColor.BLACK);
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell1);
        pos2.clear();
        pos2.add("NAZWA");
        PdfPCell cell2 = new PdfPCell(pos2);
        cell2.setBorderColor(BaseColor.BLACK);
        cell2.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell2);
        pos3.clear();
        pos3.add("NR SERYJNY");
        PdfPCell cell3 = new PdfPCell(pos3);
        cell3.setBorderColor(BaseColor.BLACK);
        cell3.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell3);
        pos4.clear();
        pos4.add("CENA NETTO");
        PdfPCell cell4 = new PdfPCell(pos4);
        cell4.setBorderColor(BaseColor.BLACK);
        cell4.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell4);
        pos5.clear();
        pos5.add("CENA BRUTTO");
        PdfPCell cell5 = new PdfPCell(pos5);
        cell5.setBorderColor(BaseColor.BLACK);
        cell5.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell5.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell5.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell5);
        pos6.clear();
        pos6.add("PROBLEM");
        PdfPCell cell6 = new PdfPCell(pos6);
        cell6.setBorderColor(BaseColor.BLACK);
        cell6.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell6.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell6.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell6);
        pos7.clear();
        pos7.add("NAPRAWA");
        PdfPCell cell7 = new PdfPCell(pos7);
        cell7.setBorderColor(BaseColor.BLACK);
        cell7.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell7.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell7.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell7);

        cell2.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell3.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell4.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell5.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell6.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell7.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setBackgroundColor(BaseColor.WHITE);
        cell2.setBackgroundColor(BaseColor.WHITE);
        cell3.setBackgroundColor(BaseColor.WHITE);
        cell4.setBackgroundColor(BaseColor.WHITE);
        cell5.setBackgroundColor(BaseColor.WHITE);
        cell6.setBackgroundColor(BaseColor.WHITE);
        cell7.setBackgroundColor(BaseColor.WHITE);
        int counter = 1;
        for (DocProductEntity prod : productToShow) {
            //col 1 (LP)
            table.addCell(createCell("" + counter, Element.ALIGN_CENTER));
            counter++;
            //col 2 (NAME)
            table.addCell(createCell(prod.getName(), Element.ALIGN_LEFT));
            //col 3 (NR SER)
            table.addCell(createCell(prod.getSerial(), Element.ALIGN_CENTER));
            //col 4 (NETTO)
            table.addCell(createCell(String.valueOf(prod.getPrice()), Element.ALIGN_RIGHT));
            //col 5 (BRUTTO)
            table.addCell(createCell(String.valueOf(prod.getPrice() + (prod.getPrice() * 0.23)),
                    Element.ALIGN_RIGHT));
            //col 6 (PROBLEM)
            table.addCell(createCell(prod.getProblem(), Element.ALIGN_LEFT));
            //col 7 (REPAIRS)
            table.addCell(createCell(prod.getRepair(), Element.ALIGN_LEFT));
        }
        document.add(table);
        pr.setAlignment(Element.ALIGN_RIGHT);
        pr.clear();
        pr.add("PRZEWIDYWANIY KOSZT NAPRAWY:");
        document.add(pr);
        pr.clear();
        pr.add("Razem netto: " + nettoLabel.getText() + " Razem brutto: " + bruttoLabel.getText());
        document.add(pr);
        pr.clear();
        pr.add("Sownie: " + amountInWords(Float.valueOf(bruttoLabel.getText().replace(",", "."))));
        document.add(pr);
        pr.clear();
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        pr.add(".................................................");
        document.add(pr);
        pr.clear();
        pr.add("Podpis i piecztka pracownika");
        document.add(pr);
        if ("SPRZT WYDANY".equals(WZTable.getValueAt(WZTable.getSelectedRow(), 11).toString())) {
            pr.clear();
            pr.add(Chunk.NEWLINE);
            pr.add(Chunk.NEWLINE);
            pr.add(".................................................");
            document.add(pr);
            pr.clear();
            pr.add("Sprzt odebraem (Podpis klienta)");
            document.add(pr);
        }
        //CLOSING DOCUMENT
        document.close();
        writer.close();

    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        StampPageXofY numeration = new StampPageXofY();
        tempName = nowTimestamp();
        numeration.manipulatePdf("test.pdf", tempName + ".pdf");
    } catch (IOException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
    }
    //OPEN READY DOCUMENT
    try {
        Desktop.getDesktop().open(new File(tempName + ".pdf"));
    } catch (IOException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
    }
}