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

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

Introduction

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

Prototype

public PdfPCell getDefaultCell() 

Source Link

Document

Gets the default PdfPCell that will be used as reference for all the addCell methods except addCell(PdfPCell).

Usage

From source file:SessionBean.ReportMgt.ReportMgtBean.java

License:Open Source License

public void createMonthlyReport(Integer startYear, Integer startMonth, Integer endYear, Integer endMonth) {
    try {/*from www .  j a va 2 s. c  o  m*/
        String RESULT;
        System.out.print("start");
        if (startYear.equals(endYear) && startMonth.equals(endMonth)) {
            RESULT = "d:/GeneralReport-" + startYear + "." + startMonth + ".pdf";
        } else {
            RESULT = "d:/GeneralReport-" + startYear + "." + startMonth + "-" + endYear + "." + endMonth
                    + ".pdf";
        }
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        Document document = new Document();
        PdfWriter.getInstance(document, baos);
        document.open();
        Image image = Image.getInstance("d:/logo-4227.png");
        image.scaleAbsolute(150, 50);
        document.add(new Paragraph(""));
        document.add(image);
        Calendar targetPeriod = Calendar.getInstance();
        int month = targetPeriod.get(Calendar.MONTH) + 1;
        int year = targetPeriod.get(Calendar.YEAR);
        String reportTile;
        document.add(new Paragraph("WineXpress General Sales Report",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.BLACK)));

        if (startYear.equals(endYear) && startMonth.equals(endMonth)) {
            reportTile = startYear + "." + startMonth;
            document.add(new Paragraph(reportTile,
                    FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED)));
        } else {
            reportTile = startYear + "." + startMonth + "-" + endYear + "." + endMonth;
            document.add(new Paragraph(reportTile,
                    FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED)));
        }

        document.add(new Paragraph("Generated Time: " + new Date().toString(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.PLAIN, BaseColor.BLACK)));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(
                "--------------------------------------------------------------------------------------------------------------------------"));

        PdfPTable table = new PdfPTable(6);
        table.getDefaultCell().setBorder(0);
        //            PdfPCell cell= new PdfPCell(new Paragraph("Wine Name"));
        //           cell.setColspan(4);
        //            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        //            cell.setBackgroundColor(BaseColor.BLACK);
        //           table.addCell(cell);
        table.addCell("Item ID");
        table.addCell("Item Name");
        table.addCell("Sales   (bottle)");
        table.addCell("Revenue (SGD)");
        table.addCell("Cost    (SGD)");
        table.addCell("Profit  (SGD)");

        Integer totalSales = 0;
        Double totalRevenue = 0D;
        Double totalCost = 0D;
        Double totalProfit = 0D;

        Query q1;
        q1 = em.createQuery("select i from PurchaseEntity i");
        Query q2;
        q2 = em.createQuery("select i from ItemEntity i");
        System.out.print("2");
        List<ItemEntity> itemList = q2.getResultList();
        List<PurchaseEntity> purchaseList = q1.getResultList();
        System.out.print("3");
        startMonth -= 1;
        endMonth -= 1;
        for (ItemEntity i : itemList) {
            Integer sales = 0;
            Double revenue = 0D;
            Double cost = 0D;

            for (PurchaseEntity p : purchaseList) {

                if ((p.getPurchasedDate().get(Calendar.YEAR) >= startYear)
                        && (p.getPurchasedDate().get(Calendar.YEAR) <= endYear)
                        && (p.getPurchasedDate().get(Calendar.MONTH) >= startMonth)
                        && (p.getPurchasedDate().get(Calendar.MONTH) <= endMonth)) {
                    System.out.print("looploop1");
                    Long orderId = p.getOrderId();
                    OrderEntity order = em.find(OrderEntity.class, orderId);
                    ItemEntity item = em.find(ItemEntity.class, order.getItemId());
                    System.out.print("looploop2");
                    if (item.getId().equals(i.getId())) {
                        sales += p.getQuantity();
                        revenue += p.getTotalPrice();
                        cost += p.getQuantity() * item.getCost();
                        System.out.print("looploop3");
                    }
                }
            }
            Double profit = revenue - cost;
            totalSales += sales;
            totalRevenue += revenue;
            totalCost += cost;
            totalProfit += profit;
            table.addCell(i.getId().toString());
            table.addCell(i.getItemName());
            table.addCell(sales.toString());
            table.addCell(revenue.toString());
            table.addCell(cost.toString());
            table.addCell(profit.toString());
        }

        document.add(table);

        document.add(new Paragraph(
                "--------------------------------------------------------------------------------------------------------------------------"));

        PdfPTable table2 = new PdfPTable(6);
        table2.getDefaultCell().setBorder(0);

        table2.addCell(" ");
        table2.addCell(" ");
        table2.addCell(totalSales.toString());
        table2.addCell(totalRevenue.toString());
        table2.addCell(totalCost.toString());
        table2.addCell(totalProfit.toString());

        document.add(table2);
        document.add(new Paragraph(
                "--------------------------------------------------------------------------------------------------------------------------"));

        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));

        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph("Copyright  2015 All rights reserved | WineXpress",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, BaseColor.BLACK)));
        document.close();
        FileOutputStream fos = new FileOutputStream(RESULT);
        fos.write(baos.toByteArray());
        fos.close();
        System.out.println("created");

        Calendar generatedTime = Calendar.getInstance();

        ReportEntity report = new ReportEntity("GeneralReport-" + reportTile, "G", RESULT, generatedTime);
        em.persist(report);
        em.flush();

    } catch (Exception e) {
    }
}

From source file:SessionBean.ReportMgt.ReportMgtBean.java

License:Open Source License

public void createProductReport(Long productId, Integer startYear, Integer startMonth, Integer endYear,
        Integer endMonth) {/*from w  w w  .jav  a  2s . c  o m*/
    try {
        System.out.print("start");
        ItemEntity item = em.find(ItemEntity.class, productId);
        String RESULT;
        String reportTitle;

        if (startYear.equals(endYear) && startMonth.equals(endMonth)) {
            RESULT = "d:/ProductReport-" + item.getId() + "-" + startYear + "." + startMonth + ".pdf";
            reportTitle = startYear + "." + startMonth;
        } else {
            RESULT = "d:/ProductReport-" + item.getId() + "-" + startYear + "." + startMonth + "-" + endYear
                    + "." + endMonth + ".pdf";
            reportTitle = startYear + "." + startMonth + "-" + endYear + "." + endMonth;
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Document document = new Document();
        PdfWriter.getInstance(document, baos);
        document.open();
        Image image = Image.getInstance("d:/logo-4227.png");
        image.scaleAbsolute(150, 50);
        document.add(image);

        document.add(new Paragraph("WineXpress Product Sales Report",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.BLACK)));
        document.add(new Paragraph("Item " + item.getId() + ": " + item.getItemName() + ", " + item.getVitage(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED)));
        document.add(new Paragraph("Generated Time: " + new Date().toString(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.PLAIN, BaseColor.BLACK)));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(
                "--------------------------------------------------------------------------------------------------------------------------"));

        PdfPTable table = new PdfPTable(5);
        table.getDefaultCell().setBorder(0);
        //            PdfPCell cell= new PdfPCell(new Paragraph("Wine Name"));
        //           cell.setColspan(4);
        //            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        //            cell.setBackgroundColor(BaseColor.BLACK);
        //           table.addCell(cell);
        table.addCell("Period");
        table.addCell("Sales");
        table.addCell("Revenue");
        table.addCell("Cost");
        table.addCell("Profit");
        table.addCell(" ");
        table.addCell("(bottle)");
        table.addCell("(SGD)");
        table.addCell("(SGD)");
        table.addCell("(SGD)");

        Integer totalSales = 0;
        Double totalRevenue = 0D;
        Double totalCost = 0D;
        Double totalProfit = 0D;

        Query q1;
        q1 = em.createQuery("select i from PurchaseEntity i");
        Query q2;
        q2 = em.createQuery("select i from ItemEntity i");
        System.out.print("2");
        List<ItemEntity> itemList = q2.getResultList();
        List<PurchaseEntity> purchaseList = q1.getResultList();
        System.out.print("3");

        for (int y = startYear; y <= endYear; y++) {

            for (int m = startMonth - 1; m <= endMonth - 1; m++) {
                Integer sales = 0;
                Double revenue = 0D;
                Double cost = 0D;
                System.out.print("loop");
                for (PurchaseEntity p : purchaseList) {
                    System.out.print("looploop1");
                    Long orderId = p.getOrderId();
                    OrderEntity order = em.find(OrderEntity.class, orderId);
                    ItemEntity item1 = em.find(ItemEntity.class, order.getItemId());
                    System.out.print("looploop2");
                    if (item1.getId().equals(item.getId()) && p.getPurchasedDate().get(Calendar.MONTH) == m
                            && p.getPurchasedDate().get(Calendar.YEAR) == y) {
                        sales += p.getQuantity();
                        revenue += p.getTotalPrice();
                        cost += p.getQuantity() * item.getCost();
                        System.out.print("looploop3");
                    }
                }
                Double profit = revenue - cost;
                totalSales += sales;
                totalRevenue += revenue;
                totalCost += cost;
                totalProfit += profit;
                int n = m + 1;
                table.addCell(y + "-" + n);
                table.addCell(sales.toString());
                table.addCell(revenue.toString());
                table.addCell(cost.toString());
                table.addCell(profit.toString());
            }
        }
        document.add(table);

        document.add(new Paragraph(
                "--------------------------------------------------------------------------------------------------------------------------"));

        PdfPTable table2 = new PdfPTable(5);
        table2.getDefaultCell().setBorder(0);

        table2.addCell(" ");
        table2.addCell(totalSales.toString());
        table2.addCell(totalRevenue.toString());
        table2.addCell(totalCost.toString());
        table2.addCell(totalProfit.toString());

        document.add(table2);
        document.add(new Paragraph(
                "--------------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));

        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph("Copyright  2015 All rights reserved | WineXpress",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, BaseColor.BLACK)));
        document.close();
        FileOutputStream fos = new FileOutputStream(RESULT);
        fos.write(baos.toByteArray());
        fos.close();
        System.out.println("created");

        Calendar generatedTime = Calendar.getInstance();
        ReportEntity report = new ReportEntity("ProductReport-" + item.getId() + "-" + reportTitle,
                item.getId().toString(), RESULT, generatedTime);
        em.persist(report);
        em.flush();

    } catch (Exception e) {
    }
}

From source file:timeclock.reports.EmployeeListReport.java

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

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

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

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

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

    return table;
}

From source file:timeclock.reports.EmployeeTimeReport.java

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

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

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

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

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

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

    return table;
}

From source file:tprog.web.DescargarPDF.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession session = request.getSession(false);
    URL wsdlLocation = new URL(getServletContext().getInitParameter("wsdl"));
    webservice.PublicadorService service = new webservice.PublicadorService(wsdlLocation);
    webservice.Publicador proxy = service.getPublicadorPort();
    System.out.println("Llego hasta el servlet");
    //response.setContentType("application/pdf");
    try {//from  w  ww  . j a va 2 s  .c  om
        String idReservaString = request.getParameter("idReserva");
        response.setContentType("application/pdf");
        Integer idReserva = Integer.parseInt(idReservaString);
        WrapperVerFactura wrapper = proxy.verFactura(idReserva);
        DtFacturaF dtf = wrapper.getFactura();
        Set<DtServicioF> servicios = new HashSet(dtf.getServicios());
        Set<DtPromocionF> promociones = new HashSet(dtf.getPromociones());
        String fecha = Integer.toString(dtf.getFecha().getDay()) + "-"
                + Integer.toString(dtf.getFecha().getMonth()) + "-" + Integer.toString(dtf.getFecha().getYear())
                + "\n";
        //creo el documento pdf dinmicamente : no s donde se guarda
        //pero se genera a demanda siempre
        Document document = new Document();
        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();
        document.add(new Paragraph("Detalles de la Factura",
                FontFactory.getFont("arial", 22, Font.ITALIC, BaseColor.BLACK)));
        document.add(new Paragraph(" "));
        //ingreso los datos de la factura
        document.add(new Paragraph("Id de la Reserva: " + idReservaString));
        document.add(new Paragraph("Fecha: " + fecha));
        document.add(new Paragraph("Cliente: " + dtf.getNicknameCliente()));
        document.add(new Paragraph("Monto: $" + dtf.getMonto()));
        document.add(new Paragraph(" "));
        //tabla para los servicios
        if (!servicios.isEmpty()) {
            document.add(new Paragraph("Servicios"));
            document.add(new Paragraph(" "));
            PdfPTable table = new PdfPTable(5);
            table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell("Item");
            table.addCell("Nombre");
            table.addCell("Cantidad");
            table.addCell("Precio");
            table.addCell("Proveedor");
            table.getDefaultCell().setBackgroundColor(null);
            int i = 1;
            for (DtServicioF servicio : servicios) {
                table.addCell(Integer.toString(i));
                table.addCell(servicio.getNombre());
                table.addCell(Integer.toString(servicio.getCantidad()));
                table.addCell(Double.toString(servicio.getPrecio()));
                table.addCell(servicio.getNicknameProveedor());
                i++;
            }
            document.add(table);
            document.add(new Paragraph(" "));
        }
        //tabla para las promos
        if (!promociones.isEmpty()) {
            document.add(new Paragraph("Promociones"));
            document.add(new Paragraph(" "));
            PdfPTable table = new PdfPTable(5);
            table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell("Item");
            table.addCell("Nombre");
            table.addCell("Cantidad");
            table.addCell("Precio");
            table.addCell("Proveedor");
            table.getDefaultCell().setBackgroundColor(null);
            int i = 1;
            for (DtPromocionF promocion : promociones) {
                table.addCell(Integer.toString(i));
                table.addCell(promocion.getNombre());
                table.addCell(Integer.toString(promocion.getCantidad()));
                table.addCell(Double.toString(promocion.getPrecio()));
                table.addCell(promocion.getNicknameProveedor());
                i++;
            }

            document.add(table);
            document.add(new Paragraph(" "));
        }
        document.close();
        //         session.setAttribute("descargaOK", "La descarga se complet correctamente.");
        response.sendRedirect("VerPerfil");
    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    }
}

From source file:utils.PrintInvoice.java

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

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

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

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

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

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

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

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

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

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

            table.addCell(desc);

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

            table.addCell(batch);

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

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

            table.addCell(expiry);

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

        }

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

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

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

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

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

        document.add(Chunk.NEWLINE);

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

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

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

}