Example usage for com.itextpdf.text RectangleReadOnly RectangleReadOnly

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

Introduction

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

Prototype

public RectangleReadOnly(final float urx, final float ury) 

Source Link

Document

Constructs a RectangleReadOnly-object starting from the origin (0, 0).

Usage

From source file:billerfx.FXMLBillController.java

File generatePDF() {
    File fi = null;/*from   w w  w. j  a  v  a 2 s. c  om*/
    try {
        Stage gg = ((Stage) imv.getParent().getScene().getWindow());
        fi = File.createTempFile("billerfx_" + gg.getTitle(), ".pdf");
        fi.deleteOnExit();

        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(fi));
        Rectangle r = new RectangleReadOnly(207, 575);
        document.setPageSize(r);
        document.setMargins(15, 15, 0, 0);
        document.open();
        Font fontbold = FontFactory.getFont("Times-Roman", 10, Font.NORMAL);
        Font fontbold2 = FontFactory.getFont("Times-Roman", 9, Font.NORMAL);

        String[] ll = Database.getCurrentSettings();
        String ss = "-----------------------------------------------------\n";
        ss += ll[0] + "\nAddress: " + ll[1] + "\nPhone: " + ll[2] + "\n";
        String kk = Calendar.getInstance().get(Calendar.AM_PM) == Calendar.AM ? "AM"
                : (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.PM ? "PM" : "");
        ss += Calendar.getInstance().get(Calendar.DATE) + "/" + (1 + Calendar.getInstance().get(Calendar.MONTH))
                + "/" + Calendar.getInstance().get(Calendar.YEAR) + " at "
                + Calendar.getInstance().get(Calendar.HOUR) + ":" + Calendar.getInstance().get(Calendar.MINUTE)
                + " " + kk + "\n";
        ss += "Table No. " + c.getText() + "     Bill No. " + a.getText() + "\n";
        ss += "-----------------------------------------------------\n";
        Paragraph para = new Paragraph(ss, fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        float[] columnWidths = { 3f, 1f };
        table.setWidths(columnWidths);
        PdfPCell defaultCell = table.getDefaultCell();
        defaultCell.setBorder(PdfPCell.NO_BORDER);

        ObservableList ob = map.get(Integer.parseInt(gg.getTitle()));
        for (int i = 0; i < ob.size(); i++) {
            Item2 ii = (Item2) ob.get(i);
            String s1 = ii.getQuantity() + " x " + ii.getName();
            String s2 = "Rs. " + ii.getTotal();
            Paragraph para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            Paragraph para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            PdfPCell cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            PdfPCell cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }
        document.add(table);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(columnWidths);
        defaultCell = table.getDefaultCell();
        defaultCell.setBorder(PdfPCell.NO_BORDER);

        String s1 = "Total:";
        String s2 = "Rs. " + h.getText();
        Paragraph para1 = new Paragraph(s1, fontbold2);
        para1.setAlignment(Paragraph.ALIGN_LEFT);
        Paragraph para2 = new Paragraph(s2, fontbold2);
        para2.setAlignment(Paragraph.ALIGN_RIGHT);
        PdfPCell cell1 = new PdfPCell(para1);
        cell1.setBorder(PdfPCell.NO_BORDER);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        PdfPCell cell2 = new PdfPCell(para2);
        cell2.setBorder(PdfPCell.NO_BORDER);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell1);
        table.addCell(cell2);

        if (Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()) > 0.0) {
            s1 = "Discount:";
            s2 = "Rs. " + BillerFX.df.format(Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()));
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        if (ll[7].equals("1")) {
            s1 = ll[3];
            s2 = "Rs. " + k.getText();
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        if (ll[8].equals("1")) {
            s1 = ll[4];
            s2 = "Rs. " + l.getText();
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        s1 = "Grand Total:";
        s2 = "Rs. " + m.getText();
        para1 = new Paragraph(s1, fontbold2);
        para1.setAlignment(Paragraph.ALIGN_LEFT);
        para2 = new Paragraph(s2, fontbold2);
        para2.setAlignment(Paragraph.ALIGN_RIGHT);
        cell1 = new PdfPCell(para1);
        cell1.setBorder(PdfPCell.NO_BORDER);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell2 = new PdfPCell(para2);
        cell2.setBorder(PdfPCell.NO_BORDER);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell1);
        table.addCell(cell2);

        document.add(table);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        fontbold2 = FontFactory.getFont("Times-Roman", 8, Font.NORMAL);
        para = new Paragraph(
                "Thank You.\nThis invoice was created using BillerFX.\n (BillerFX Contact: ayushmaanbhav1008@gmail.com)\n",
                fontbold2);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        document.close();
    } catch (Exception mm) {
    }
    return fi;
}