Example usage for com.itextpdf.text Element ALIGN_LEFT

List of usage examples for com.itextpdf.text Element ALIGN_LEFT

Introduction

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

Prototype

int ALIGN_LEFT

To view the source code for com.itextpdf.text Element ALIGN_LEFT.

Click Source Link

Document

A possible value for paragraph alignment.

Usage

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  w  w  .ja 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\\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 {// w ww .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 {
    }

}

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 {/*from www . 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\\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 w w . j  ava 2s.  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\\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  . ja  va  2 s .  c o m*/
 * @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//from   ww  w  .  j a  v a 2  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:util.ImageExample.java

public ImageExample(Calendar date, int settings, ArrayList<String> courses, String time, String eventAddress,
        int totalPrice, String comments, boolean kunde) throws Exception {
    this.date = date;
    this.settings = settings;
    this.courses = courses;
    this.time = time;
    this.eventAddress = eventAddress;
    this.totalPrice = totalPrice;
    this.comments = comments;
    this.fileName = "";
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    ge.getAllFonts();/*w ww . j ava 2s .  com*/
    FontFactory.register("C:/Windows/Fonts/ARLRDBD.TTF", "Arial Rounded");
    Font font = FontFactory.getFont("Arial Rounded", 22, Font.NORMAL, new BaseColor(51, 102, 102));
    Document document = new Document();

    System.out.println("Pdf creation startet");
    try {
        if (kunde) {
            fileName = "grill" + new SimpleDateFormat("dd. MMMMM yyyy hhmm").format(date.getTime()) + ".pdf";
        } else {
            fileName = "grill" + new SimpleDateFormat("dd. MMMMM yyyy hhmm").format(date.getTime())
                    + "Prisliste.pdf";
        }

        FileOutputStream file = new FileOutputStream(new File("C:/Users/Mark/Desktop", fileName));
        PdfWriter writer = PdfWriter.getInstance(document, file);
        document.open();

        Image img = Image.getInstance("src/pictures/cirkles.png");
        img.scaleToFit(277, 277);
        img.setAbsolutePosition(40, PageSize.A4.getHeight() - img.getHeight());
        document.add(img);
        Chunk chunk = new Chunk("Grillmester 'Frankie'", font);
        chunk.setCharacterSpacing(3);
        Paragraph header = new Paragraph(chunk);
        header.setAlignment(Element.ALIGN_RIGHT);
        header.setSpacingBefore(15);
        document.add(header);
        Paragraph title = new Paragraph(
                "Tilbud angende d. " + new SimpleDateFormat("dd. MMMMM yyyy").format(date.getTime()) + ".",
                new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD));
        title.setAlignment(Element.ALIGN_LEFT);
        title.setIndentationLeft(235);
        title.setSpacingBefore(100);
        title.setLeading(17);
        document.add(title);
        Paragraph subtitle = new Paragraph("(Arrangement til " + settings + " personer).",
                new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.ITALIC));
        subtitle.setAlignment(Element.ALIGN_LEFT);
        subtitle.setIndentationLeft(235);
        subtitle.setLeading(17);
        document.add(subtitle);
        Paragraph body = new Paragraph("\n\nDer er aftalt:\n\n", new Font(Font.FontFamily.TIMES_ROMAN, 18));
        body.setAlignment(Element.ALIGN_LEFT);
        body.setIndentationLeft(235);
        body.setLeading(17);
        for (String course : courses) {
            body.add(course + "\n\n");
        }
        body.add("\nServeres klokken " + time + " i " + eventAddress + ".");
        document.add(body);
        Paragraph ending = new Paragraph("\n\n\nPris: " + totalPrice + ",-kr.",
                new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
        ending.setAlignment(Element.ALIGN_LEFT);
        ending.setIndentationLeft(235);
        ending.setLeading(17);
        document.add(ending);
        if (!comments.equals("null")) {
            if (!comments.equals("")) {
                Paragraph comment = new Paragraph("\n\nKommentarer\n" + comments,
                        new Font(Font.FontFamily.TIMES_ROMAN, 18));
                comment.setAlignment(Element.ALIGN_LEFT);
                comment.setIndentationLeft(235);
                comment.setLeading(17);
                document.add(comment);
            }
        }

        Image footerImg = Image.getInstance("src/pictures/grillmester.png");
        footerImg.scaleToFit(210, 210);
        footerImg.setAbsolutePosition(40, 40);
        document.add(footerImg);

        Image img2 = Image.getInstance("src/pictures/Contact.png");
        img2.scaleToFit(250, 250);
        img2.setAbsolutePosition(20, PageSize.A4.getHeight() - img.getHeight() - 250);
        document.add(img2);

        document.close();

        System.out.println("Pdf finish");
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(e.getLocalizedMessage());
    }
}

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);/*  ww w. j a  v  a  2  s.  c  o 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 {//from w w  w  .  j a v a  2 s .c  o m
        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();
    }

}

From source file:Valuacion.Autorizacion.java

private void b_pdfhActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_pdfhActionPerformed
     // TODO add your handling code here:
     h = new Herramientas(user, 0);
     h.session(sessionPrograma);/*from  w w  w .j a  va  2 s.  c o  m*/
     Session session = HibernateUtil.getSessionFactory().openSession();
     try {
         session.beginTransaction().begin();
         BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
         //Orden ord=buscaApertura();
         PDF reporte = new PDF();
         Date fecha = new Date();
         DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
         String valor = dateFormat.format(fecha);
         File folder = new File("reportes/" + ord.getIdOrden());
         folder.mkdirs();
         reporte.Abrir(PageSize.LETTER.rotate(), "Valuacin",
                 "reportes/" + ord.getIdOrden() + "/" + valor + "-autorizacion.pdf");
         Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);
         BaseColor contenido = BaseColor.WHITE;
         int centro = Element.ALIGN_CENTER;
         int izquierda = Element.ALIGN_LEFT;
         int derecha = Element.ALIGN_RIGHT;
         float tam[] = new float[] { 15, 15, 50, 150, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 100 };
         PdfPTable tabla = reporte.crearTabla(15, tam, 100, Element.ALIGN_LEFT);

         cabecera(reporte, bf, tabla);

         session.beginTransaction().begin();
         Orden ord = (Orden) session.get(Orden.class, Integer.parseInt(orden));
         //Partida resp=(Partida[]) session.createCriteria(Partida.class).add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden))).addOrder(Order.desc("idEvaluacion")).addOrder(Order.desc("subPartida"));
         //Partida[] cuentas = (Partida[]) ord.getPartidas().toArray(new Partida[0]);
         List cuentas = null;
         switch (c_filtro.getSelectedItem().toString()) {
         case "Todos":
             cuentas = session.createCriteria(Partida.class)
                     .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                     .addOrder(Order.asc("idEvaluacion")).addOrder(Order.asc("subPartida")).list();
             break;

         case "Hojalateria":
             cuentas = session.createCriteria(Partida.class)
                     .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                     .add(Restrictions.eq("espHoj", true)).addOrder(Order.asc("idEvaluacion"))
                     .addOrder(Order.asc("subPartida")).list();
             break;

         case "Mecanica":
             cuentas = session.createCriteria(Partida.class)
                     .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                     .add(Restrictions.eq("espMec", true)).addOrder(Order.asc("idEvaluacion"))
                     .addOrder(Order.asc("subPartida")).list();
             break;

         case "Suspension":
             cuentas = session.createCriteria(Partida.class)
                     .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                     .add(Restrictions.eq("espSus", true)).addOrder(Order.asc("idEvaluacion"))
                     .addOrder(Order.asc("subPartida")).list();
             break;

         case "Electricidad":
             cuentas = session.createCriteria(Partida.class)
                     .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                     .add(Restrictions.eq("espEle", true)).addOrder(Order.asc("idEvaluacion"))
                     .addOrder(Order.asc("subPartida")).list();
             break;
         }

         int ren = 0;
         if (cuentas.size() > 0) {
             DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00");
             formatoPorcentaje.setMinimumFractionDigits(2);
             for (int i = 0; i < cuentas.size(); i++) {
                 Partida Part = (Partida) cuentas.get(i);
                 tabla.addCell(reporte.celda("" + Part.getIdEvaluacion(), font, contenido, izquierda, 0, 1,
                         Rectangle.RECTANGLE));
                 tabla.addCell(reporte.celda("" + Part.getSubPartida(), font, contenido, izquierda, 0, 1,
                         Rectangle.RECTANGLE));

                 if (Part.isEspEle() == true)
                     tabla.addCell(reporte.celda("Electricidad", font, contenido, izquierda, 0, 0,
                             Rectangle.RECTANGLE));
                 else {
                     if (Part.isEspMec() == true)
                         tabla.addCell(reporte.celda("Mecanica", font, contenido, izquierda, 0, 0,
                                 Rectangle.RECTANGLE));
                     else {
                         if (Part.isEspSus() == true)
                             tabla.addCell(reporte.celda("Suspension", font, contenido, izquierda, 0, 0,
                                     Rectangle.RECTANGLE));
                         else {
                             if (Part.isEspHoj() == true)
                                 tabla.addCell(reporte.celda("Hojalateria", font, contenido, izquierda, 0, 0,
                                         Rectangle.RECTANGLE));
                             else {
                                 tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 0,
                                         Rectangle.RECTANGLE));
                             }
                         }
                     }
                 }

                 tabla.addCell(reporte.celda(Part.getCatalogo().getNombre(), font, contenido, izquierda, 0, 0,
                         Rectangle.RECTANGLE));

                 tabla.addCell(reporte.celda("" + Part.getCant(), font, contenido, izquierda, 0, 1,
                         Rectangle.RECTANGLE));
                 tabla.addCell(
                         reporte.celda(Part.getMed(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntDesm() > -1)
                     tabla.addCell(reporte.celda(formatoPorcentaje.format(Part.getIntDesm()), font, contenido,
                             izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntCamb() > -1)
                     tabla.addCell(reporte.celda(formatoPorcentaje.format(Part.getIntCamb()), font, contenido,
                             izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntRepMin() > -1)
                     tabla.addCell(reporte.celda(formatoPorcentaje.format(Part.getIntRepMin()), font, contenido,
                             izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntRepMed() > -1)
                     tabla.addCell(reporte.celda(formatoPorcentaje.format(Part.getIntRepMed()), font, contenido,
                             izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntRepMax() > -1)
                     tabla.addCell(reporte.celda(formatoPorcentaje.format(Part.getIntRepMax()), font, contenido,
                             izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntPinMin() > -1)
                     tabla.addCell(reporte.celda(formatoPorcentaje.format(Part.getIntPinMin()), font, contenido,
                             izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntPinMed() > -1)
                     tabla.addCell(reporte.celda(formatoPorcentaje.format(Part.getIntPinMed()), font, contenido,
                             izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getIntPinMax() > -1)
                     tabla.addCell(reporte.celda(formatoPorcentaje.format(Part.getIntPinMax()), font, contenido,
                             izquierda, 0, 1, Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));

                 if (Part.getInstruccion() != null)
                     tabla.addCell(reporte.celda(Part.getInstruccion(), font, contenido, izquierda, 0, 1,
                             Rectangle.RECTANGLE));
                 else
                     tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                 /*if(ren==38)
                 {
                     reporte.agregaObjeto(tabla);
                     reporte.writer.newPage();
                     tabla=reporte.crearTabla(17, tam, 100, Element.ALIGN_LEFT);
                     cabecera(reporte, bf, tabla);
                     ren=-1;
                 }*/
                 ren++;
             }

         }
         session.beginTransaction().rollback();
         tabla.setHeaderRows(3);
         reporte.agregaObjeto(tabla);
         reporte.cerrar();
         reporte.visualizar("reportes/" + ord.getIdOrden() + "/" + valor + "-autorizacion.pdf");

     } catch (Exception e) {
         System.out.println(e);
         e.printStackTrace();
         JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte");
     }
     if (session != null)
         if (session.isOpen())
             session.close();
 }