Example usage for com.itextpdf.text Image setBackgroundColor

List of usage examples for com.itextpdf.text Image setBackgroundColor

Introduction

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

Prototype


public void setBackgroundColor(final BaseColor backgroundColor) 

Source Link

Document

Sets the backgroundcolor of the rectangle.

Usage

From source file:Sales.SalesController.java

@FXML
private void PrintReciept(MouseEvent event) {
    try {//from  w  w  w.java2  s  .  c o  m
        Image im = Image.getInstance("khamals.png");
        FileOutputStream sa = new FileOutputStream("Reciept.pdf");
        im.scaleAbsolute(150f, 150f);
        // im.setAbsolutePosition(25,50);
        im.setBackgroundColor(BaseColor.PINK);
        Document doc = new Document(PageSize.A4, 50, 50, 50, 50);
        PdfWriter writer = PdfWriter.getInstance(doc, sa);
        PdfPTable table = new PdfPTable(6);
        String sh = "                                     Date and Time Of Sale : "
                + Calendar.getInstance().getTime().toGMTString() + "\n\n";
        String header = "                                                                 KHAMALS \n"
                + "                                              DESIGNER AND SHOWROOM EXPERT \n "
                + "                                  MOLYKO BUEA  LAST FLOOR ECKO BANK BUILDING\n ";
        String metda = "    INVOICE NUMBER :" + this.RecieptId.getText() + " \n " + "  SALES PERSON ID :"
                + this.CashierName.getText() + " \n   CUSTOMER NAME :" + this.CustomerName.getText() + "\n\n";

        PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT"));
        cell.setColspan(6);
        cell.setHorizontalAlignment(2);
        doc.open();
        doc.add(im);
        doc.add(cell);
        System.out.println(doc.leftMargin());
        doc.add(new Paragraph(header));
        doc.add(new Paragraph(sh));
        doc.add(new Paragraph(metda));
        table.addCell("S/N");
        table.addCell("PRODUCT NAME");
        table.addCell("DESCRIPTION");
        table.addCell("QUANTITY");
        table.addCell("UNIT PRICE");
        table.addCell("TOTAL PRICE");
        table.setTotalWidth(1000000);
        for (int i = 0; i < Cart.getItems().size(); i++) {
            table.addCell(this.idex.getCellData(i).toString());
            table.addCell(this.p.getCellData(i).toString());
            table.addCell(this.dsc.getCellData(i).toString());
            table.addCell(this.qt.getCellData(i).toString());
            table.addCell(this.p.getCellData(i).toString());
            table.addCell(this.tp.getCellData(i).toString());
        }

        String footer = " \n                                                                                 Total Amount:         "
                + tot.getText() + ""
                + "                                                                                   SIGNATURES \n"
                + "\nCUSTOMER                                      SALES PERSON ";

        doc.add(table);
        doc.add(new Paragraph(footer));
        doc.addCreationDate();
        doc.addAuthor(this.CashierName.getText());
        doc.close();

        Desktop.getDesktop().open(new File("Reciept.pdf"));

    } catch (Exception sd) {
        System.out.println("Error Message :" + sd.getMessage());
    } finally {

    }

}