package com.reallinkbilling.print;

import static java.awt.Color.WHITE;
import static org.apache.pdfbox.pdmodel.font.PDType1Font.HELVETICA;
import static org.vandeseer.easytable.settings.HorizontalAlignment.CENTER;
import static org.vandeseer.easytable.settings.HorizontalAlignment.LEFT;
import static org.vandeseer.easytable.settings.HorizontalAlignment.RIGHT;
import static org.vandeseer.easytable.settings.VerticalAlignment.BOTTOM;
import static org.vandeseer.easytable.settings.VerticalAlignment.MIDDLE;
import static org.vandeseer.easytable.settings.VerticalAlignment.TOP;

import java.awt.Color;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.fontbox.ttf.TTFParser;
import org.apache.fontbox.ttf.TrueTypeFont;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.SessionAware;
import org.vandeseer.easytable.TableDrawer;
import org.vandeseer.easytable.structure.Row;
import org.vandeseer.easytable.structure.Table;
import org.vandeseer.easytable.structure.Table.TableBuilder;
import org.vandeseer.easytable.structure.cell.TextCell;

import com.opensymphony.xwork2.ActionSupport;
import com.reallinkbilling.DAO.BillInformationDAO;
import com.reallinkbilling.DAO.BillProductInfoDAO;
import com.reallinkbilling.cipher.EncryptionDecryption;
import com.reallinkbilling.db.GetDBConnection;
import com.reallinkbilling.resource.GetListResource;
import com.reallinkbilling.resource.NumberToWordsConverter;
import com.reallinkbilling.utils.GetCustomerCreditAmountById;

public class BillPrintOnlyType2 extends ActionSupport implements SessionAware{

	/**
	 * 
	 */
	private static final long serialVersionUID = -1414976236123269184L;
	/**
	 * 
	 */

	
	private HttpSession session;
	private SessionMap<String,Object> sessionMap;
	private BillInformationDAO billInfoDAO = null;
	private List<BillProductInfoDAO> productInfoList = null;
	public HttpServletRequest request;
	public HttpServletResponse response;
	private String billNumber;
	private String billType;
	private String typeOfBill;
	private String key;
	private String language;
	private String billDateTime;
	
	private final static Color BLUE_DARK = new Color(76, 129, 190);
    private final static Color BLUE_LIGHT_1 = new Color(186, 206, 230);
    private final static Color BLUE_LIGHT_2 = new Color(218, 230, 242);

    private final static Color GRAY_LIGHT_1 = new Color(245, 245, 245);
    private final static Color GRAY_LIGHT_2 = new Color(240, 240, 240);
    private final static Color GRAY_LIGHT_3 = new Color(216, 216, 216);
    private static final float PADDING10 = 10f;
    private static final float PADDING20 = 20f;
    private static final float PADDING30 = 30f;
	
	
	public void printBillOnly(){
		
		
		boolean isBillNumberFound = false;
		
		//System.out.println("Bill Number : "+billNumber);
			DecimalFormat df =new DecimalFormat("##.##");
				Connection connection = null;
				PreparedStatement preparedStatement= null;
				ResultSet resultSet = null;
				
				String sql = "";
				String db = (String) this.getSessionMap().get("db");
				
				String shopId = (String) this.getSessionMap().get("shopId");
	    		String shopCode = (String) this.getSessionMap().get("shopCode");
	    		try
	    		{
	    			
	    		
	    		if(this.getKey() != null)
	    		{
	    			if(!this.getKey().equals(""))
	    			{
	    				String actualKey = EncryptionDecryption.decrypt(this.getKey());
	    				String [] keyData = actualKey.split("#");
	    				
	    				this.setBillNumber(keyData[0]);
	    				shopId = keyData[1];
	    				shopCode = keyData[2];
	    				db = "reallinkshop";
	    				
	    			}
	    		}
	    		
	    		}catch(Exception e){}
			
				String billDateTime = "";
				try
	        	{
	        		
					billInfoDAO = new BillInformationDAO();
					productInfoList = new ArrayList<BillProductInfoDAO>();
	        	      
	        
				connection = GetDBConnection.getDBConnection(db);
				
				if(this.getTypeOfBill() == null)
	        	{
	        		this.setTypeOfBill("CASH-MEMO");
	        	}
	        	
	        	sql = "SELECT "
	        			+ "DATE_FORMAT(bill_date,'%d-%m-%Y'),"
	        			+ "TIME_FORMAT(bill_time,'%h:%i %p'),"
	        			+ "payment_type,"
	        			+ "bill_type,"
	        			+ "customer_id,"
	        			+ "customer_name,"
	        			+ "transportation_charges,"
	        			+ "comments,"
	        			+ "bill_total_amount,"
	        			+ "bill_amount_received,"
	        			+ "billed_by "
	        			+ "FROM "
	        			+ "shop_bill_info_master "
	        			+ "WHERE "
	        			+ "bill_type = ? "
	        			+ "AND "
	        			+ "bill_number = ? "
	        					+ "AND "
	        					+ "shop_id = ? "
	        					+ "AND "
	        					+ "shop_code = ? "
	        					+ "AND "
	        					+ "bill_date = STR_TO_DATE(?,'%d-%m-%Y') ";
	        	
	        	
	        	
	        	preparedStatement = connection.prepareStatement(sql);
	        	preparedStatement.setString(1, this.getTypeOfBill());
	        	preparedStatement.setString(2, this.getBillNumber());
	        	preparedStatement.setString(3, shopId);
	        	preparedStatement.setString(4, shopCode);
	        	preparedStatement.setString(5, this.getBillDateTime());
	        	
	        	resultSet = preparedStatement.executeQuery();
	        	
	        	resultSet.last();
	        	int rowCount = resultSet.getRow();
	        	resultSet.beforeFirst();	        	
	        	
	        	if(rowCount>0)
	        	{
	        		Map<String,String> unitShortName = GetListResource.GetUnitShortEnglishName();
	        		
	        		
	        		isBillNumberFound = true;
	        	
	        	if(resultSet.next())
	        	{
	        		
	        			billInfoDAO.setBillType(resultSet.getString(4));
	        		
	        			
	        			
	        		billDateTime = resultSet.getString(1)+" "+resultSet.getString(2);
	        		this.getBillInfoDAO().setBillDate(resultSet.getString(1)+" "+resultSet.getString(2));
	        		this.getBillInfoDAO().setBillNumber(getBillNumber());
	        		this.getBillInfoDAO().setPaymentType(resultSet.getString(3));
	        		this.getBillInfoDAO().setCustId(resultSet.getString(5));
	        		this.getBillInfoDAO().setCustomerName(resultSet.getString(6).split("-")[1]); 
	        		this.getBillInfoDAO().setCustomerMobile(resultSet.getString(6).split("-")[2]); 
	        		this.getBillInfoDAO().setTotalBillAmount(resultSet.getString(9));
	        		this.getBillInfoDAO().setComments(resultSet.getString(8));
	        		this.getBillInfoDAO().setBilledBy(resultSet.getString(11));
	        		
	        	}
	        
	        
	        	
	        	
			        	if(resultSet != null)
			        	{
			        		resultSet.close();
			        		resultSet = null;
			        	}
			        	if(preparedStatement != null)
			        	{
			        		preparedStatement.close();
			        		preparedStatement = null;
			        	
			        	}
			        	
			        	
			        	sql = "SELECT "
			        			+ "billProductInfo.product_name,"
			        			+ "billProductInfo.product_name_in_marathi,"
			        			+ "billProductInfo.sales_unit,"
			        			+ "billProductInfo.id_tax_table,"
			        			+ "billProductInfo.sales_rate,"
			        			+ "billProductInfo.product_quantity,"
			        			+ "billProductInfo.discount_percentage,"
			        			+ "billProductInfo.discount_ruppees,"
			        			+ "billProductInfo.product_total_amount,"
			        			+ "billProductInfo.product_total_amount_aft_discount,"
			        			+ "billProductInfo.product_net_amount,"
			        			+ "billProductInfo.product_igst_amount,"
			        			+ "billProductInfo.product_cgst_amount,"
			        			+ "billProductInfo.product_sgst_amount,"
			        			+ "billProductInfo.making_labor_charge,"
			        			+ "productInfo.hsn_sac_code,"
			        			+ "productInfo.product_short_code,"
			        			+ "billProductInfo.product_batch_id,"
			        			+ "billProductInfo.product_expiry_date "
			        			+ "FROM "
			        			+ "shop_bill_product_info_master AS billProductInfo "
			        			+ "INNER JOIN "
			        			+ "shop_product_master AS productInfo "
			        			+ "ON "
			        			+ "billProductInfo.product_id = productInfo.product_id "
			        			+ "where "
			        			+ "billProductInfo.bill_type = ? "
			        			+ "AND "
			        			+ "billProductInfo.bill_number = ? "
			        			+ "AND "
			        			+ "billProductInfo.shop_id = ? "
			        			+ "AND "
			        			+ "billProductInfo.shop_code = ? "
			        			+ "AND "
			        			+ "productInfo.shop_id = ? "
			        			+ "AND "
			        			+ "productInfo.shop_code = ? "
			        			+ "AND "
			        			+ "billProductInfo.bill_date = STR_TO_DATE(?,'%d-%m-%Y') "
			        			+ "ORDER BY "
			        			+ "billProductInfo.entry_id";
			        	
			        	
			        	
			        	
			        	
			        	preparedStatement = connection.prepareStatement(sql);
			        	
			        	preparedStatement.setString(1, this.getTypeOfBill());
			        	preparedStatement.setString(2, this.getBillNumber());
			        	preparedStatement.setString(3, shopId);
			        	preparedStatement.setString(4, shopCode);
			        	preparedStatement.setString(5, shopId);
			        	preparedStatement.setString(6, shopCode);
			        	preparedStatement.setString(7, this.getBillDateTime());
			        	
			        	
			        	resultSet = preparedStatement.executeQuery();
			        	
			        	while(resultSet.next())
			        	{
			        		BillProductInfoDAO billProductInfoDAO = new BillProductInfoDAO();
			        		billProductInfoDAO.setProductName(resultSet.getString(1));
			        		billProductInfoDAO.setProductNameMarathi(resultSet.getString(2));
			        		billProductInfoDAO.setSalesUnit(resultSet.getString(3));
			        		billProductInfoDAO.setTaxId(resultSet.getString(4));
			        		billProductInfoDAO.setSalesRate(resultSet.getFloat(5));
			        		billProductInfoDAO.setQuantity(resultSet.getFloat(6));
			        		billProductInfoDAO.setDiscountPecentage(resultSet.getFloat(7));
			        		billProductInfoDAO.setDiscountRupees(resultSet.getFloat(8));
			        		billProductInfoDAO.setAmount(resultSet.getFloat(9));
			        		billProductInfoDAO.setAmountAfterDiscount(resultSet.getFloat(10));
			        		billProductInfoDAO.setGrossAmount(resultSet.getFloat(11));
			        		billProductInfoDAO.setIgst(resultSet.getFloat(12));
			        		billProductInfoDAO.setCgst(resultSet.getFloat(13));
			        		billProductInfoDAO.setSgst(resultSet.getFloat(14));
			        		billProductInfoDAO.setSalesUnitShortName(unitShortName.get(resultSet.getString(3)));
			        		billProductInfoDAO.setMakingLaborCharge(resultSet.getFloat(15));
			        		billProductInfoDAO.setHsnCode(resultSet.getString(16));
			        		billProductInfoDAO.setProductCode(resultSet.getString(17));
			        		billProductInfoDAO.setBatchId(resultSet.getString(18));
			        		billProductInfoDAO.setExpiryDate(resultSet.getString(19));
			        		billProductInfoDAO.setProductTotalDiscount(resultSet.getFloat(9)-resultSet.getFloat(10));
			        		
			        		this.getProductInfoList().add(billProductInfoDAO);
			        		
			        		Map<String,String> taxInfo = GetListResource.GetTaxNamePercentage(resultSet.getString(4),this.getSessionMap());
				        	
							String taxName = taxInfo.get("TAX-NAME");
							String taxPercentage = taxInfo.get("TAX-PERCENTAGE");
							
							billProductInfoDAO.setTaxName(taxName);
							billProductInfoDAO.setTaxPercentage(Float.parseFloat(taxPercentage));
							
			        				
			        	}
			        	
	        	}
	        	
				
				if(isBillNumberFound)
				{
					
					@SuppressWarnings("unchecked")
					HashMap<String,String> shopSettingsMap = (HashMap<String, String>) this.getSessionMap().get("shop_settings");
					
					
					String addDiscountColumnString = shopSettingsMap.get("add_discount_column_to_bill");
					String addQRCodeString = shopSettingsMap.get("add_QR_code_to_bill");
					String addGSTNumberString = shopSettingsMap.get("add_gst_number_to_bill");
					String addCustCreditAmtSettings = shopSettingsMap.get("add_credit_amount_to_bill");
					String billMessageFont = shopSettingsMap.get("bill_message_font");
					String showTotalQuantitySettings = shopSettingsMap.get("show_total_quantity");
					String addMakingLaborColumn = shopSettingsMap.get("add_making_charge_column");
					String addIntroLine =  shopSettingsMap.get("add_header_intro_line");
					String addPageHeaderString = shopSettingsMap.get("add_page_header_default");
				
					//
					 boolean addCustomerCreditAmountToBill = false;		        	
					 boolean addDiscountColumn = false;
					 boolean addQRCode = false;
			         boolean addShortUnit = false;
			         boolean addGSTNumber = false;
			         boolean showTotalQuantity = false;
			         boolean addPageHeader = false;
			         
			         
			         
			         if(addPageHeaderString.equals("TRUE"))
			         {
			        	 addPageHeader = true;
			         }
			         
			         if(showTotalQuantitySettings.equals("TRUE"))
			         {
			        	 showTotalQuantity = true;
			         }
			         
			         if(addCustCreditAmtSettings.equals("TRUE"))
			         {
			        	 addCustomerCreditAmountToBill = true;
			         }
					 if(addDiscountColumnString.equals("TRUE"))
					 {
						 addDiscountColumn = true;
					 }
					 if(addQRCodeString.equals("TRUE"))
					 {
						 addQRCode = true;
					 }
					 if(addGSTNumberString.equals("TRUE"))
					 {
						 addGSTNumber = true;
					 }
	        	
				String gstNum = (String)this.getSessionMap().get("shopgstnumber");
	        	
	        	
	        	float floatTotalAmount = 0.0F;
	        	float floatTotalDiscount = 0.0F;
	        	float floatTotalAmtAfterDiscount = 0.0F;
	        	float totalQuantity = 0.0F;
	        	int listSize = this.getProductInfoList().size();
	        	

	        	for(BillProductInfoDAO infoDAO : this.getProductInfoList())
	        	{
	        		//System.out.print("Amount after discount : "+infoDAO.getProductTotalDiscount());
	        		floatTotalAmount  = floatTotalAmount+ infoDAO.getAmount();
	        		floatTotalAmtAfterDiscount = floatTotalAmtAfterDiscount + infoDAO.getAmountAfterDiscount();
	        		floatTotalDiscount = floatTotalDiscount + (infoDAO.getQuantity() * infoDAO.getDiscountRupees());
	        		totalQuantity = totalQuantity + infoDAO.getQuantity();
	        	}
	        	
	        	/*System.out.println("Total Amount : "+floatTotalAmount);
	        	System.out.println("Total Discount : "+floatTotalDiscount);
	        	System.out.println("Total amount Payble : "+floatTotalAmtAfterDiscount);*/
	        	
	        	response = ServletActionContext.getResponse();
				request = ServletActionContext.getRequest();
				
				
				String path= this.getRequest().getSession().getServletContext().getRealPath("/images/");
				
			
				
				
				 
				  
				  
		         
		         if(this.getBillInfoDAO().getBillType().equals("CASH-MEMO")
		        		 || (this.getBillInfoDAO().getBillType().equals("COMPOSITE-BILL")
		        				 && (this.getBillType() == null || !this.getBillType().equals("A5"))))
		         {
		        	 
		        	 PDDocument document = new PDDocument(); 
						PDPage page = null;
						
						float pageHeight = 320.0F+(listSize*16.2F)+22.0F;
						
						if(addQRCode)
						{
							pageHeight = pageHeight + 30;
						}
						
						PDRectangle pdRectangle = new PDRectangle(220.0F, pageHeight);
						 page = new PDPage(pdRectangle);
						 
						 document.addPage(page);
						 
						 PDImageXObject pdImageQRCode = null;
						 Blob blob = (Blob) this.getSessionMap().get("qr_image_bolb");
						 
						 if(blob != null)
						 {
						 InputStream in = blob.getBinaryStream();
						 File qrFile = new File(path+"/"+shopId+"qr.jpeg");
						 FileOutputStream out = new FileOutputStream(qrFile);
						 byte[] buffer = new byte[1024];
						    int read;
						    while ((read = in.read(buffer)) != -1) {
						        out.write(buffer, 0, read);
						    }
						    
						    in.close();
						    out.close();
						    pdImageQRCode = PDImageXObject.createFromFile(path+"/"+shopId+"qr.jpeg", document);
						 }
						 
						
					         PDImageXObject thermalPrintHeaderImage = null;
					         Blob thermalPrintHeaderImageBlob = null;
					         InputStream thermalPrintHeaderImageIS = null;
					        		 
					         if(shopSettingsMap.get("THERMALPRINTHEADER").equals("IMAGE"))
							 {
								
									
									 byte[]  thermalPrintHeaderImageBytes =(byte[]) this.getSessionMap().get("thermal_print_header_image");
									 thermalPrintHeaderImage = PDImageXObject.createFromByteArray(document, thermalPrintHeaderImageBytes, "thermalPrintHeader");
								 
								
							 }
						 
						 File fontFile  =  new File( request.getSession().getServletContext().getRealPath("/fonts/Nirmala.ttf"));
						 File fontFileBold  =  new File( request.getSession().getServletContext().getRealPath("/fonts/nirmala-bold.ttf"));
						 File fontFileKrutiBold  =  new File( request.getSession().getServletContext().getRealPath("/fonts/Kruti_Dev_100__Bold.ttf"));
							
						 TrueTypeFont ttf1 = new TTFParser().parse(fontFile);
						 PDFont fontMarathi = PDType0Font.load(document, ttf1, true);
						 
						 TrueTypeFont ttf2 = new TTFParser().parse(fontFileBold);
						 PDFont fontMarathiBold = PDType0Font.load(document, ttf2, true);
						 
						 TrueTypeFont ttf3 = new TTFParser().parse(fontFileKrutiBold);
						 PDFont fontMarathiKrutiBold = PDType0Font.load(document, ttf3, true);
						 
				         PDPageContentStream contentStream = new PDPageContentStream(document, page);
		         
		         Table header;
		         Table billInfoTable;
		         Table itemInfo;
		         Table bottomInfo;
		         
		         TableBuilder tableHeaderBuilder = Table.builder()
			                .addColumnsOfWidth(200)				                
			                .font(HELVETICA)
			                .borderColor(Color.BLACK)
			                .horizontalAlignment(CENTER);
		         
		     
		         if(shopSettingsMap.get("THERMALPRINTHEADER").equals("TEXT"))
				 {
			         
			         Row dairyNameHeader = Row.builder()
				                .add(TextCell.builder().text((String)this.getSessionMap().get("shopname2")).horizontalAlignment(CENTER).borderWidth(0).lineSpacing(0.5F).build())				               
				                .backgroundColor(WHITE)
				                .textColor(Color.BLACK)
				                .font(fontMarathiKrutiBold).fontSize(17)				              
				                .horizontalAlignment(CENTER)
				                .build();
			         
			         tableHeaderBuilder.addRow(dairyNameHeader);
				 }
		         else
		         {
		        	   
			         if(thermalPrintHeaderImage != null)
		        	 {
			        	
		        		 contentStream.drawImage(thermalPrintHeaderImage, 20, 515 , 60, 20);
		        		
		        	 }
		         }
		         
		        
		         Row addressRow1 = Row.builder()
			                .add(TextCell.builder().text((String)this.getSessionMap().get("shopbillAddress")).horizontalAlignment(CENTER).borderWidth(0).lineSpacing(0.5F).build())				               
			                .backgroundColor(WHITE)
			                .textColor(Color.BLACK)
			                .font(fontMarathiKrutiBold).fontSize(11)				              
			                .horizontalAlignment(CENTER)
			                .build();
		         
		         Row addressRow2 = Row.builder()
			                .add(TextCell.builder()
			                		.text("Mo:"+(String)this.getSessionMap().get("shopcustcarenumber"))
			                		.horizontalAlignment(CENTER).borderWidth(0).lineSpacing(0.5F).build())				               
			                .backgroundColor(WHITE)
			                .textColor(Color.BLACK)
			                .font(PDType1Font.HELVETICA_BOLD).fontSize(9)				              
			                .horizontalAlignment(CENTER)
			                .build();
		     
		         
		         
		         
		  
		         tableHeaderBuilder.addRow(addressRow1);
		         tableHeaderBuilder.addRow(addressRow2);
		        
		         
		         header = tableHeaderBuilder.build();
		         
		         
		         
		         TableBuilder tableBillInfoBuilder = Table.builder()
			                .addColumnsOfWidth(80,120)				                
			                .font(HELVETICA)
			                .borderColor(Color.BLACK)
			                .horizontalAlignment(CENTER);
		         
		         Row billInfoRow1 = Row.builder()
			                .add(TextCell.builder().text("बिल नंबर:"+this.getBillNumber()).horizontalAlignment(CENTER).borderWidthTop(0.5F).lineSpacing(0.5F).build())				               
			                .add(TextCell.builder().text("तारीख–:"+billDateTime).fontSize(8).horizontalAlignment(CENTER).borderWidthTop(0.5F).lineSpacing(0.5F).build())				               
				            .backgroundColor(WHITE)
			                .textColor(Color.BLACK)
			                .font(fontMarathiBold).fontSize(10)				              
			                .horizontalAlignment(CENTER)
			                .build();
		         
		        
		         Row billInfoRow2 = Row.builder()
			                .add(TextCell.builder().text("Type: "+this.getBillInfoDAO().getPaymentType()).horizontalAlignment(CENTER).borderWidth(0).lineSpacing(0.5F).build())				               
			                .add(TextCell.builder().text("Bill By: "+this.getBillInfoDAO().getBilledBy()).horizontalAlignment(CENTER).borderWidth(0).lineSpacing(0.5F).build())				               
				            .backgroundColor(WHITE)
			                .textColor(Color.BLACK)
			                .font(fontMarathiBold).fontSize(10)				              
			                .horizontalAlignment(CENTER)
			                .build();
		         
		         Row billInfoRow3 = Row.builder()
			                .add(TextCell.builder().text("GST No:"+gstNum).colSpan(2).horizontalAlignment(CENTER).borderWidth(0).lineSpacing(0.5F).build())				               
			                .backgroundColor(WHITE)
			                .textColor(Color.BLACK)
			                .font(fontMarathiBold).fontSize(9)				              
			                .horizontalAlignment(CENTER)
			                .build();
		         Row custName = Row.builder()
			                .add(TextCell.builder().text("Customer : "+this.getBillInfoDAO().getCustomerName()).colSpan(2).horizontalAlignment(CENTER).borderWidthTop(0.5F).lineSpacing(0.5F).build())				               
			                .backgroundColor(WHITE)
			                .textColor(Color.BLACK)
			                .fontSize(9)
			                .font(fontMarathiBold)			              
			                .horizontalAlignment(CENTER)
			                .build();
		         Row custmobile = Row.builder()
			                .add(TextCell.builder().text(this.getBillInfoDAO().getCustomerMobile()).colSpan(2).horizontalAlignment(CENTER).borderWidthTop(0F).lineSpacing(0.5F).build())				               
			                .backgroundColor(WHITE)
			                .textColor(Color.BLACK)
			                .fontSize(8)
			                .font(fontMarathiBold)			              
			                .horizontalAlignment(CENTER)
			                .build();
		        		 
		        		
		         
		         tableBillInfoBuilder.addRow(billInfoRow1);
		         tableBillInfoBuilder.addRow(billInfoRow2);
		         if(addGSTNumber)
		         {
		        	 tableBillInfoBuilder.addRow(billInfoRow3);
		         }
		         tableBillInfoBuilder.addRow(custName);
		         tableBillInfoBuilder.addRow(custmobile);
		          billInfoTable = tableBillInfoBuilder.build();
		          
		          
			         float startY = page.getMediaBox().getHeight()-2;
			         TableDrawer.builder()
		                .contentStream(contentStream)
		                .table(header)
		                .startX(5F)
		                .startY(startY)
		                .build()
		                .draw();
			         
			         float currectY = startY - 35;
			        
			         TableDrawer.builder()
		                .contentStream(contentStream)
		                .table(billInfoTable)
		                .startX(5F)
		                .startY(currectY)
		                .build()
		                .draw();
			         
			         currectY = currectY - 70;
			         float itemEndY = currectY-20;
			     
			       if(addDiscountColumn)
		          {

			          if(!addShortUnit)
			          {
				         TableBuilder tableItemInfoBuilder = Table.builder()
					                .addColumnsOfWidth(60,30,35,25,40)				                
					                .font(HELVETICA)
					                .borderColor(Color.BLACK)
					                .horizontalAlignment(CENTER);
			          
				         
				         Row itemInfoHeader = Row.builder()
					                .add(TextCell.builder().text("तपशील").fontSize(9).horizontalAlignment(LEFT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
					                .add(TextCell.builder().text("QTY").fontSize(9).horizontalAlignment(LEFT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
					                .add(TextCell.builder().text("दर").fontSize(9).horizontalAlignment(RIGHT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
					                .add(TextCell.builder().text("सूट").fontSize(9).horizontalAlignment(RIGHT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
							        .add(TextCell.builder().text("jDde").fontSize(11).font(fontMarathiKrutiBold).horizontalAlignment(RIGHT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
							        .backgroundColor(WHITE)
					                .textColor(Color.BLACK)
					                .font(fontMarathiBold)          
					                .horizontalAlignment(CENTER)
					                .build();
				         
				         
				         
				         
				         tableItemInfoBuilder.addRow(itemInfoHeader);
				     	
				        
				         
				         int size = this.getProductInfoList().size();
				         Row itemDetails = null;
							for(BillProductInfoDAO informationDAO : this.getProductInfoList())
							{
								
								 int nameLength = informationDAO.getProductNameMarathi().length();
								if(size == 1)
								{
									
									 itemDetails = Row.builder()
								                .add(TextCell.builder().text(informationDAO.getProductNameMarathi()).horizontalAlignment(LEFT).borderWidth(0.0F).borderWidthBottom(0.5F).lineSpacing(0.0F).build())				               
								                .add(TextCell.builder().text(""+informationDAO.getQuantity()).fontSize(8).horizontalAlignment(LEFT).borderWidth(0F).borderWidthBottom(0.5F).lineSpacing(0.2F).build())				               
								                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).horizontalAlignment(RIGHT).borderWidth(0.0F).lineSpacing(0.2F).borderWidthBottom(0.5F).build())				               
								                .add(TextCell.builder().text(df.format(informationDAO.getProductTotalDiscount())).horizontalAlignment(RIGHT).borderWidth(0.0F).lineSpacing(0.2F).borderWidthBottom(0.5F).build())				               
									            .add(TextCell.builder().text(df.format(informationDAO.getAmountAfterDiscount())).paddingRight(5F).horizontalAlignment(RIGHT).borderWidth(0.0F).lineSpacing(0.2F).borderWidthBottom(0.5F).build())				               
										        .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .font(fontMarathiBold).fontSize(8)	
								                .height(16F)
								                .horizontalAlignment(CENTER)
								                .build();
								}else
								{
						         itemDetails = Row.builder()
							                .add(TextCell.builder().text(informationDAO.getProductNameMarathi()).horizontalAlignment(LEFT).borderWidth(0.0F).lineSpacing(0.2F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getQuantity()).fontSize(8).horizontalAlignment(LEFT).borderWidth(0F).lineSpacing(0.2F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).horizontalAlignment(RIGHT).borderWidth(0.0F).lineSpacing(0.2F).build())				               
							                .add(TextCell.builder().text(df.format(informationDAO.getProductTotalDiscount())).horizontalAlignment(RIGHT).borderWidth(0.0F).lineSpacing(0.2F).build())				               
								            .add(TextCell.builder().text(df.format(informationDAO.getAmountAfterDiscount())).paddingRight(5F).horizontalAlignment(RIGHT).borderWidth(0.0F).lineSpacing(0.2F).build())				               
									        .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .height(16F)
							                .font(fontMarathiBold).fontSize(8)				              
							                .horizontalAlignment(CENTER)
							                .build();
								}
							
						         tableItemInfoBuilder.addRow(itemDetails);
						         
						         size--;
						       
						    		
						         
						         
								}
							itemInfo = tableItemInfoBuilder.build();
							 itemEndY = itemEndY - (itemDetails.getHeight()*productInfoList.size());
								
							}
			          else
			          {

					         TableBuilder tableItemInfoBuilder = Table.builder()
						                .addColumnsOfWidth(75,35,30,20,40)				                
						                .font(HELVETICA)
						                .borderColor(Color.BLACK)
						                .horizontalAlignment(CENTER);
				          

					         Row itemInfoHeader = Row.builder()
						                .add(TextCell.builder().text("तपशील").fontSize(9).horizontalAlignment(LEFT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
						                .add(TextCell.builder().text("QTY").fontSize(9).horizontalAlignment(LEFT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
						                .add(TextCell.builder().text("दर").fontSize(9).horizontalAlignment(RIGHT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
						                .add(TextCell.builder().text("सूट").fontSize(9).horizontalAlignment(RIGHT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
								        .add(TextCell.builder().text("रक्कम").fontSize(9).horizontalAlignment(RIGHT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
								        .backgroundColor(WHITE)
						                .textColor(Color.BLACK)
						                .font(fontMarathiBold)          
						                .horizontalAlignment(CENTER)
						                .build();
					         
					         
					         
					         
					         
					         tableItemInfoBuilder.addRow(itemInfoHeader);
					     	
					        
					         
					         int size = this.getProductInfoList().size();
					         Row itemDetails = null;
								for(BillProductInfoDAO informationDAO : this.getProductInfoList())
								{
									
									
									if(size == 1)
									{
										
										 itemDetails = Row.builder()
									                .add(TextCell.builder().text(informationDAO.getProductNameMarathi()).horizontalAlignment(LEFT).borderWidth(0.0F).borderWidthBottom(0.5F).lineSpacing(0.0F).build())				               
									                .add(TextCell.builder().text(informationDAO.getQuantity()+" "+informationDAO.getSalesUnitShortName()).fontSize(7).horizontalAlignment(LEFT).borderWidth(0F).borderWidthBottom(0.5F).lineSpacing(0.2F).build())				               
									                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).horizontalAlignment(RIGHT).borderWidth(0.0F).lineSpacing(0.2F).borderWidthBottom(0.5F).build())				               
									                .add(TextCell.builder().text(""+informationDAO.getProductTotalDiscount()).horizontalAlignment(RIGHT).borderWidth(0.0F).lineSpacing(0.2F).borderWidthBottom(0.5F).build())				               
										            .add(TextCell.builder().text(""+informationDAO.getAmountAfterDiscount()).horizontalAlignment(RIGHT).borderWidth(0.0F).lineSpacing(0.2F).borderWidthBottom(0.5F).build())				               
											        .backgroundColor(WHITE)
									                .textColor(Color.BLACK)
									                .font(fontMarathiBold).fontSize(8)				              
									                .horizontalAlignment(CENTER)
									                .build();
									}else
									{
							         itemDetails = Row.builder()
								                .add(TextCell.builder().text(informationDAO.getProductNameMarathi()).horizontalAlignment(LEFT).borderWidth(0.0F).lineSpacing(0.2F).build())				               
								                .add(TextCell.builder().text(informationDAO.getQuantity()+" "+informationDAO.getSalesUnitShortName()).fontSize(7).horizontalAlignment(LEFT).borderWidth(0F).lineSpacing(0.2F).build())				               
								                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).horizontalAlignment(RIGHT).borderWidth(0.0F).lineSpacing(0.2F).build())				               
								                .add(TextCell.builder().text(""+informationDAO.getProductTotalDiscount()).horizontalAlignment(RIGHT).borderWidth(0.0F).lineSpacing(0.2F).build())				               
									            .add(TextCell.builder().text(""+informationDAO.getAmountAfterDiscount()).horizontalAlignment(RIGHT).borderWidth(0.0F).lineSpacing(0.2F).build())				               
										        .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .font(fontMarathiBold).fontSize(8)				              
								                .horizontalAlignment(CENTER)
								                .build();
									}
								
							         tableItemInfoBuilder.addRow(itemDetails);
							         
							         size--;
							         
							   
									}
								itemInfo = tableItemInfoBuilder.build();
								
								 itemEndY = itemEndY - (itemDetails.getHeight()*productInfoList.size());
			          }
			    	  
			          
							  
							if(addQRCode)
							{
								TableBuilder tableBottomInfoBuilder = Table.builder()
						                .addColumnsOfWidth(70,50)				                
						                .font(HELVETICA)
						                .borderColor(Color.BLACK)
						                .horizontalAlignment(CENTER);
							  
								 Row itemTotalItemsInfo = null;
						          if(showTotalQuantity)
						          {
								  
							          itemTotalItemsInfo = Row.builder()
								                .add(TextCell.builder().text(",dw.k oLrw ").font(fontMarathiKrutiBold).fontSize(11).horizontalAlignment(LEFT).borderWidthTop(0.5F).borderWidthBottom(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(2F).build())				               
								                .add(TextCell.builder().text(df.format(totalQuantity)).horizontalAlignment(RIGHT).borderWidthTop(0.5F).borderWidthBottom(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(2F).build())				               
									            .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .font(fontMarathiBold)	
								                .fontSize(9)
								                .horizontalAlignment(CENTER)
								                .height(15F)
								                .build();
						          }
						          else
						          {
						        	  itemTotalItemsInfo = Row.builder()
								                .add(TextCell.builder().text(",dw.k oLrw ").font(fontMarathiKrutiBold).fontSize(11).horizontalAlignment(LEFT).borderWidthTop(0.5F).borderWidthBottom(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(2F).build())				               
								                .add(TextCell.builder().text(""+listSize).horizontalAlignment(RIGHT).borderWidthTop(0.5F).borderWidthBottom(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(2F).build())				               
									            .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .font(fontMarathiBold)	
								                .fontSize(9)
								                .horizontalAlignment(CENTER)
								                .height(15F)
								                .build();
						          }
							         Row itemTotalInfo = Row.builder()
								                .add(TextCell.builder().text("jDde").font(fontMarathiKrutiBold).fontSize(11).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(2F).build())				               
								                .add(TextCell.builder().text("" +floatTotalAmtAfterDiscount).horizontalAlignment(RIGHT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(2F).build())				               
								                .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .font(fontMarathiBold)	
								                .fontSize(9)
								                .height(15F)
								                .horizontalAlignment(CENTER)
								                .build();
							         Row discountInfo = Row.builder()
								                .add(TextCell.builder().text(",dw.k cpr").font(fontMarathiKrutiBold).fontSize(11).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(2F).build())				               
								                .add(TextCell.builder().text("" +floatTotalDiscount).horizontalAlignment(RIGHT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(2F).build())				               
									            .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .font(fontMarathiBold)
								                .fontSize(9)
								                .height(15F)
								                .horizontalAlignment(CENTER)
								                .build();
							    
							         
							       
							         tableBottomInfoBuilder.addRow(itemTotalItemsInfo);
							         tableBottomInfoBuilder.addRow(itemTotalInfo);
							         tableBottomInfoBuilder.addRow(discountInfo);
							      
							         bottomInfo = tableBottomInfoBuilder.build();
							}
							else
							{
								TableBuilder tableBottomInfoBuilder = Table.builder()
						                .addColumnsOfWidth(200)				                
						                .font(HELVETICA)
						                .borderColor(Color.BLACK)
						                .horizontalAlignment(CENTER);
								
								Row itemTotalItemsInfo = null;
								if(showTotalQuantity)
								{
									 itemTotalItemsInfo = Row.builder()
							                .add(TextCell.builder().text("एकूण वस्तू‚ :"+totalQuantity+"       |    एकूण रक्कम: " +floatTotalAmtAfterDiscount+"\u20B9").horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(2F).build())				               
							                .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .font(fontMarathiBold)	
							                .fontSize(9)
							                .horizontalAlignment(CENTER)
							                .build();
									
								}
								else
								{
						          itemTotalItemsInfo = Row.builder()
							                .add(TextCell.builder().text("एकूण वस्तू‚ :"+listSize+"       |    एकूण रक्कम : " +floatTotalAmtAfterDiscount+"\u20B9").horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(2F).build())				               
							                .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .font(fontMarathiBold)	
							                .fontSize(9)
							                .horizontalAlignment(CENTER)
							                .build();
								}
						         Row discountInfo = Row.builder()
							                .add(TextCell.builder().text("Total Discount : " +floatTotalDiscount+" \u20B9").horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(2F).build())				               
								             .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .font(fontMarathiBold)
							                .fontSize(9)
							                .horizontalAlignment(CENTER)
							                .build();
						      
						         
						    
						         
						         tableBottomInfoBuilder.addRow(itemTotalItemsInfo);
						         tableBottomInfoBuilder.addRow(discountInfo);
						       
						         bottomInfo = tableBottomInfoBuilder.build();
							}
			          
		        	  
		          }
		          else
		          {
		        	  

			          if(addQRCode)
			          {
			        	  

					         TableBuilder tableItemInfoBuilder = Table.builder()
						                .addColumnsOfWidth(70,40,40,45)				                
						                .font(HELVETICA)
						                .borderColor(Color.BLACK)
						                .horizontalAlignment(CENTER);

					         Row itemInfoHeader = Row.builder()
						                .add(TextCell.builder().text("तपशील").fontSize(9).horizontalAlignment(LEFT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
						                .add(TextCell.builder().text("QTY").fontSize(9).horizontalAlignment(LEFT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
						                .add(TextCell.builder().text("दर").fontSize(9).horizontalAlignment(RIGHT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
						                .add(TextCell.builder().text("रक्कम").fontSize(9).horizontalAlignment(RIGHT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
								        .backgroundColor(WHITE)
						                .textColor(Color.BLACK)
						                .font(fontMarathiBold).fontSize(10)				              
						                .horizontalAlignment(CENTER)
						                .build();
					       
					         tableItemInfoBuilder.addRow(itemInfoHeader);
					     	
					         int productListSize = productInfoList.size();
					         Row itemDetails = null;
								for(BillProductInfoDAO informationDAO : productInfoList)
								{
									
									 
									if(productListSize>1)
									{
							         itemDetails = Row.builder()
								                .add(TextCell.builder().text(informationDAO.getProductNameMarathi()).fontSize(9).horizontalAlignment(LEFT).borderWidth(0.0F).lineSpacing(0.5F).build())				               
								                .add(TextCell.builder().text(informationDAO.getQuantity()+" "+informationDAO.getSalesUnitShortName()).fontSize(8).horizontalAlignment(LEFT).borderWidth(0F).lineSpacing(0.5F).build())				               
								                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).fontSize(9).horizontalAlignment(RIGHT).borderWidth(0.0F).lineSpacing(0.5F).build())				               
								                .add(TextCell.builder().text(""+informationDAO.getAmountAfterDiscount()).fontSize(9).horizontalAlignment(RIGHT).borderWidth(0.0F).lineSpacing(0.5F).build())				               
										        .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .font(fontMarathiBold).fontSize(9)				              
								                .horizontalAlignment(CENTER)
								                .build();
									}
									else
									{
										 itemDetails = Row.builder()
									                .add(TextCell.builder().text(informationDAO.getProductNameMarathi()).fontSize(9).horizontalAlignment(LEFT).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
									                .add(TextCell.builder().text(informationDAO.getQuantity()+" "+informationDAO.getSalesUnitShortName()).fontSize(8).horizontalAlignment(LEFT).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
									                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).fontSize(9).horizontalAlignment(RIGHT).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
									                .add(TextCell.builder().text(""+informationDAO.getAmountAfterDiscount()).fontSize(9).horizontalAlignment(RIGHT).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
											        .backgroundColor(WHITE)
									                .textColor(Color.BLACK)
									                .font(fontMarathiBold).fontSize(9)				              
									                .horizontalAlignment(CENTER)
									                .build();
									}
							         tableItemInfoBuilder.addRow(itemDetails);
							        
							         productListSize--;
								}
					         
								 itemInfo = tableItemInfoBuilder.build();
								 itemEndY = itemEndY - (itemDetails.getHeight()*productInfoList.size());
								 
								 TableBuilder tableBottomInfoBuilder = Table.builder()
							                .addColumnsOfWidth(70,50)				                
							                .font(HELVETICA)
							                .borderColor(Color.BLACK)
							                .horizontalAlignment(CENTER);
								  
							         
									  
								 Row itemTotalItemsInfo = null;
						          if(showTotalQuantity)
						          {
								  
							          itemTotalItemsInfo = Row.builder()
								                .add(TextCell.builder().text(",dw.k oLrw ").font(fontMarathiKrutiBold).fontSize(11).horizontalAlignment(LEFT).borderWidthTop(0.5F).borderWidthBottom(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(2F).build())				               
								                .add(TextCell.builder().text(df.format(totalQuantity)).horizontalAlignment(RIGHT).borderWidthTop(0.5F).borderWidthBottom(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(2F).build())				               
									            .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .font(fontMarathiBold)	
								                .fontSize(9)
								                .horizontalAlignment(CENTER)
								                .height(15F)
								                .build();
						          }
						          else
						          {
						        	  itemTotalItemsInfo = Row.builder()
								                .add(TextCell.builder().text(",dw.k oLrw ").font(fontMarathiKrutiBold).fontSize(11).horizontalAlignment(LEFT).borderWidthTop(0.5F).borderWidthBottom(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(2F).build())				               
								                .add(TextCell.builder().text(""+listSize).horizontalAlignment(RIGHT).borderWidthTop(0.5F).borderWidthBottom(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(2F).build())				               
									            .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .font(fontMarathiBold)	
								                .fontSize(9)
								                .horizontalAlignment(CENTER)
								                .height(15F)
								                .build();
						          }
								         Row itemTotalInfo = Row.builder()
									                .add(TextCell.builder().text("jDde").font(fontMarathiKrutiBold).fontSize(11).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(2F).build())				               
									                .add(TextCell.builder().text("" +floatTotalAmtAfterDiscount).horizontalAlignment(RIGHT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(2F).build())				               
									                .backgroundColor(WHITE)
									                .textColor(Color.BLACK)
									                .font(fontMarathiBold)	
									                .fontSize(9)
									                .height(15F)
									                .horizontalAlignment(CENTER)
									                .build();
								         Row discountInfo = Row.builder()
									                .add(TextCell.builder().text(",dw.k cpr").font(fontMarathiKrutiBold).fontSize(11).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(2F).build())				               
									                .add(TextCell.builder().text("" +floatTotalDiscount).horizontalAlignment(RIGHT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(2F).build())				               
										            .backgroundColor(WHITE)
									                .textColor(Color.BLACK)
									                .font(fontMarathiBold)
									                .fontSize(9)
									                .height(15F)
									                .horizontalAlignment(CENTER)
									                .build();
								    
								         
								       
								         tableBottomInfoBuilder.addRow(itemTotalItemsInfo);
								         tableBottomInfoBuilder.addRow(itemTotalInfo);
								       //  tableBottomInfoBuilder.addRow(discountInfo);
								      
								         bottomInfo = tableBottomInfoBuilder.build();
			        	  
			          }else
			          {
				         TableBuilder tableItemInfoBuilder = Table.builder()
					                .addColumnsOfWidth(70,40,40,45)				                
					                .font(HELVETICA)
					                .borderColor(Color.BLACK)
					                .horizontalAlignment(CENTER);
				         Row itemInfoHeader = Row.builder()
					                .add(TextCell.builder().text("तपशील").fontSize(9).horizontalAlignment(LEFT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
					                .add(TextCell.builder().text("QTY").fontSize(9).horizontalAlignment(LEFT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
					                .add(TextCell.builder().text("दर").fontSize(9).horizontalAlignment(RIGHT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
					                .add(TextCell.builder().text("रक्कम").fontSize(9).horizontalAlignment(RIGHT).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
								         
					                .backgroundColor(WHITE)
					                .textColor(Color.BLACK)
					                .font(fontMarathiBold).fontSize(10)				              
					                .horizontalAlignment(CENTER)
					                .build();
				       
				         tableItemInfoBuilder.addRow(itemInfoHeader);
				         Row itemDetails = null;
							for(BillProductInfoDAO informationDAO : productInfoList)
							{
								
								 
									
						         itemDetails = Row.builder()
							                .add(TextCell.builder().text(informationDAO.getProductNameMarathi()).fontSize(9).horizontalAlignment(LEFT).borderWidth(0.0F).lineSpacing(0.5F).build())				               
							                .add(TextCell.builder().text(informationDAO.getQuantity()+" "+informationDAO.getSalesUnitShortName()).fontSize(8).horizontalAlignment(LEFT).borderWidth(0F).lineSpacing(0.5F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).fontSize(9).horizontalAlignment(RIGHT).borderWidth(0.0F).lineSpacing(0.5F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getAmountAfterDiscount()).fontSize(9).horizontalAlignment(RIGHT).borderWidth(0.0F).lineSpacing(0.5F).build())				               
									        .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .font(fontMarathiBold).fontSize(9)				              
							                .horizontalAlignment(CENTER)
							                .build();
						         tableItemInfoBuilder.addRow(itemDetails);
						         
							}
				         
							 itemInfo = tableItemInfoBuilder.build();
							 itemEndY = itemEndY - (itemDetails.getHeight()*productInfoList.size());
							 
							 itemEndY = itemEndY - 10;
							 
							 
							    TableBuilder tableBottomInfoBuilder = Table.builder()
						                .addColumnsOfWidth(200)				                
						                .font(HELVETICA)
						                .borderColor(Color.BLACK)
						                .horizontalAlignment(CENTER);
							    Row itemTotalInfo = null;
							    if(showTotalQuantity)
								{
									itemTotalInfo = Row.builder()
							                .add(TextCell.builder().text("एकूण वस्तू‚ :"+totalQuantity+"       |     रक्कम : " +floatTotalAmtAfterDiscount+"\u20B9").horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(2F).build())				               
							                .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .font(fontMarathiBold)	
							                .fontSize(9)
							                .horizontalAlignment(CENTER)
							                .build();
									
								}
								else
								{
									itemTotalInfo = Row.builder()
							                .add(TextCell.builder().text("एकूण नग‚ :"+listSize+"       |     रक्कम : " +floatTotalAmtAfterDiscount+"\u20B9").horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(2F).build())				               
							                .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .font(fontMarathiBold)	
							                .fontSize(9)
							                .horizontalAlignment(CENTER)
							                .build();
								}
					         
					         
					     
					         
					     
					         
					         tableBottomInfoBuilder.addRow(itemTotalInfo);
					      
					         bottomInfo = tableBottomInfoBuilder.build();
					       
			          }
			          
		          }
			   
				String addBillMessage = shopSettingsMap.get("add_message_to_bill");
				 Table billMessageTable = null;
			       if(addBillMessage.equals("TRUE"))
			       {
			    	   String billMessage = shopSettingsMap.get("bill_message");
			    	   
			    	  
			    	   
			    	   TableBuilder tableBillMessageTableBuilder = Table.builder()
				                .addColumnsOfWidth(200)				                
				                .font(HELVETICA)
				                .borderColor(Color.BLACK)
				                .horizontalAlignment(CENTER);
			    	   
			    	   
			    	   Row messageInfoRow1 = null;
			    	   if(billMessageFont.equals("NIRMALA"))
			    	   {
			    	   
				    	    messageInfoRow1 = Row.builder()
					                .add(TextCell.builder().text(billMessage).horizontalAlignment(CENTER).borderWidthTop(0.5F).lineSpacing(0.5F).build())				               
					                .backgroundColor(WHITE)
					                .textColor(Color.BLACK)
					                .font(fontMarathiBold)
					                .height(25F)
					                .fontSize(12)				              
					                .horizontalAlignment(CENTER)
					                .build();
				    	  
			    	   }
			    	   else
			    	   {
			    		    messageInfoRow1 = Row.builder()
					                .add(TextCell.builder().text(billMessage).horizontalAlignment(CENTER).borderWidthTop(0.5F).lineSpacing(0.5F).build())				               
					                .backgroundColor(WHITE)
					                .textColor(Color.BLACK)
					                .font(fontMarathiKrutiBold)
					                .height(25F)
					                .fontSize(12)				              
					                .horizontalAlignment(CENTER)
					                .build();
				    	  
			    	   }
			    	   tableBillMessageTableBuilder.addRow(messageInfoRow1);
			    	   billMessageTable = tableBillMessageTableBuilder.build();
			        
			       }
		          
		          Table conmpanyInfo;
		          
		         TableBuilder tableCompanyInfoBuilder = Table.builder()
			                .addColumnsOfWidth(200)				                
			                .font(HELVETICA)
			                .borderColor(Color.BLACK)
			                .horizontalAlignment(CENTER);
		         
		         Row companyInfoRow1 = Row.builder()
			                .add(TextCell.builder().text("Developed By: Real Link Infotech:8208064913").horizontalAlignment(CENTER).borderWidthTop(0.5F).lineSpacing(0.5F).build())				               
			                .backgroundColor(WHITE)
			                .textColor(Color.BLACK)
			                .font(fontMarathiBold).fontSize(8)				              
			                .horizontalAlignment(CENTER)
			                .build();
		         tableCompanyInfoBuilder.addRow(companyInfoRow1);
		         
		         conmpanyInfo = tableCompanyInfoBuilder.build();
		        
		         String cashMemoComments = this.getBillInfoDAO().getComments();
		         if(cashMemoComments == null || cashMemoComments.equals("NA"))
		         {
		        	 cashMemoComments = "";
		         }
		         TableBuilder commentsTableBuilder = Table.builder()
		                .addColumnsOfWidth(200)
		                .font(HELVETICA)
		                .borderColor(Color.BLACK)
		                .horizontalAlignment(CENTER);
		         Row cashMemoCommentsRow = Row.builder()
		                .add(TextCell.builder().text("Comments: "+cashMemoComments).horizontalAlignment(LEFT).borderWidthTop(0.5F).lineSpacing(0.5F).build())
		                .backgroundColor(WHITE)
		                .textColor(Color.BLACK)
		                .font(fontMarathiBold)
		                .height(18F)
		                .fontSize(8)
		                .horizontalAlignment(LEFT)
		                .build();
		         commentsTableBuilder.addRow(cashMemoCommentsRow);
		         Table commentsTable = commentsTableBuilder.build();
		         
		        
		           TableDrawer.builder()
	                .contentStream(contentStream)
	                .table(itemInfo)
	                .startX(5F)
	                .startY(currectY)
	                .build()
	                .draw();
		       
		        
		         if(addQRCode)
		         {
		        	 
		        	 TableDrawer.builder()
		                .contentStream(contentStream)
		                .table(bottomInfo)
		                .startX(75F)
		                .startY(itemEndY)
		                .build()
		                .draw();
		        	 if(pdImageQRCode != null)
		        	 {
		        		 contentStream.drawImage(pdImageQRCode, 15, itemEndY-50, 50, 50);
		        	 }
		        	 if(addBillMessage.equals("TRUE"))
				       {
		        		 itemEndY = itemEndY - 55; 
		        		  TableDrawer.builder()
			                .contentStream(contentStream)
			                .table(billMessageTable)
			                .startX(0F)
			                .startY(itemEndY)
			                .build()
			                .draw();
		        		  itemEndY = itemEndY - 25;
		        		  
				       }else
				       {
				    	   itemEndY = itemEndY - 55;
				       }
		        	
		        	 TableDrawer.builder()
		                .contentStream(contentStream)
		                .table(commentsTable)
		                .startX(0F)
		                .startY(itemEndY)
		                .build()
		                .draw();
		        	 itemEndY = itemEndY - 20;
		        	
			         TableDrawer.builder()
		                .contentStream(contentStream)
		                .table(conmpanyInfo)
		                .startX(0F)
		                .startY(itemEndY)
		                .build()
		                .draw();
		         }
		         else
		         {
		        	
		        	 itemEndY = itemEndY -5;
		        	 TableDrawer.builder()
		                .contentStream(contentStream)
		                .table(bottomInfo)
		                .startX(0F)
		                .startY(itemEndY)
		                .build()
		                .draw();
		        	 
		        	 	if(addBillMessage.equals("TRUE"))
				       {
		        	 		  itemEndY = itemEndY - 25;
		        		 
		        		  TableDrawer.builder()
			                .contentStream(contentStream)
			                .table(billMessageTable)
			                .startX(0F)
			                .startY(itemEndY)
			                .build()
			                .draw();
		        		  itemEndY = itemEndY - 25;
		        		  
				       }else
				       {
				    	   itemEndY = itemEndY - 35;
				       }
		        	
		        	 TableDrawer.builder()
		                .contentStream(contentStream)
		                .table(commentsTable)
		                .startX(0F)
		                .startY(itemEndY)
		                .build()
		                .draw();
		        	 itemEndY = itemEndY - 20;
		        	
			         TableDrawer.builder()
		                .contentStream(contentStream)
		                .table(conmpanyInfo)
		                .startX(0F)
		                .startY(itemEndY)
		                .build()
		                .draw();
		         }
		         
		        
		         
		      
		         contentStream.close();
				 	document.save(path+"/bill.pdf");
			        document.close();
			        
			        

					response.setHeader("Content-disposition", "inline; filename=bill.pdf");
					response.setContentType("application/pdf");
					FileInputStream fileInputStream = new FileInputStream(path+"/bill.pdf");
					PrintWriter outFile = response.getWriter();  
					int bytes;
					while ((bytes = fileInputStream.read()) != -1) {
						outFile.write(bytes);
					}
					fileInputStream.close();
					outFile.flush();
					outFile.close();
					ttf1.close();
					ttf2.close();
					ttf3.close();
					
				}
		         
		  
         
         		// BILL OF SUPPLY AND A5 SIZE  ENGLISH LANGUAGE
		         
		         
		         String a5PageOrientation = shopSettingsMap.get("default_A5_print_orientation");
         
        
		        if((this.getBillInfoDAO().getBillType().equals("BILL-OF-SUPPLY") || this.getBillInfoDAO().getBillType().equals("COMPOSITE-BILL")) && this.getLanguage().equals("ENGLISH") && this.getBillType().equals("A5") && a5PageOrientation.equals("LANDSCAPE"))
				{
		        	
		        	
		        	String custMobile = "";
		        	String custAddress = "";
		        	
		        	if(resultSet != null)
		        	{
		        		resultSet.close();
		        		resultSet = null;
		        	}
		        	
		        	if(preparedStatement != null)
		        	{
		        		preparedStatement.close();
		        		preparedStatement = null;
		        	}
		        	
		        	
		        	sql = "SELECT "
		        			+ "mobile_number,"
		        			+ "billing_address "
		        			+ "FROM "
		        			+ "shop_customer_master "
		        			+ "WHERE "
		        			+ "customer_name = ? "
		        			+ "AND "
		        			+ "customer_id = ? "
		        			+ "AND "
		        			+ "shop_id = ? "
		        			+ "AND "
		        			+ "shop_code = ?";
		        	
		        	preparedStatement = connection.prepareStatement(sql);
		        	preparedStatement.setString(1, this.getBillInfoDAO().getCustomerName());
		        	preparedStatement.setString(2, this.getBillInfoDAO().getCustId());
		        	preparedStatement.setString(3, shopId);
		        	preparedStatement.setString(4, shopCode);
		        	
		        	resultSet = preparedStatement.executeQuery();
		        	
		        	while(resultSet.next())
		        	{
		        		custMobile = resultSet.getString(1);
		        		custAddress = resultSet.getString(2);
		        	}
		        	
		        	
		        	PDDocument document = new PDDocument(); 
					PDPage page = null;
					
					int productListSize = this.getProductInfoList().size();
					
					
					if(productListSize>5)
					{
						page = new PDPage(PDRectangle.A4);
					}
					else
					{
						page = new PDPage(new PDRectangle(595.2756f,420.9449f));
					}
					 
					 document.addPage(page);
					 
						
						
					 File fontFile  =  new File( request.getSession().getServletContext().getRealPath("/fonts/Nirmala.ttf"));
					 File fontFileBold  =  new File( request.getSession().getServletContext().getRealPath("/fonts/nirmala-bold.ttf"));
					 
					 TrueTypeFont ttf1 = new TTFParser().parse(fontFile);
					 PDFont fontMarathi = PDType0Font.load(document, ttf1, true);
					 
					 TrueTypeFont ttf2 = new TTFParser().parse(fontFileBold);
					 PDFont fontMarathiBold = PDType0Font.load(document, ttf2, true);
					 
			         PDPageContentStream contentStream = new PDPageContentStream(document, page);
			         
			         
			         
			         PDImageXObject pdImageQRCode = null;
			         PDImageXObject pdImageLeftLogoImage = null;
			         PDImageXObject pdImageRightLogoImage = null;
			  		 
					 Blob blob = (Blob) this.getSessionMap().get("qr_image_bolb");
					 
					 //headintroline
					 
				
					 String headIntroLineContent = (String)this.getSessionMap().get("headintroline");
					 if(shopSettingsMap.get("add_left_side_logo").equals("TRUE"))
					 {
						
							
							 byte[] leftLogoBytes =(byte[]) this.getSessionMap().get("left_logo_image_array");
							 pdImageLeftLogoImage = PDImageXObject.createFromByteArray(document, leftLogoBytes, "leftLogo");
						 
						
					 }
					 if(shopSettingsMap.get("add_right_side_logo").equals("TRUE"))
					 {

						 byte[] rightLogoBytes =(byte[]) this.getSessionMap().get("right_logo_image_array");
						 pdImageRightLogoImage = PDImageXObject.createFromByteArray(document, rightLogoBytes, "rightLogo");
					 }
					 
					 if(blob != null)
					 {
					 InputStream in = blob.getBinaryStream();
					 File qrFile = new File(path+"/"+shopId+"qr.jpeg");
					 FileOutputStream out = new FileOutputStream(qrFile);
					 byte[] buffer = new byte[1024];
					    int read;
					    while ((read = in.read(buffer)) != -1) {
					        out.write(buffer, 0, read);
					    }
					    
					    in.close();
					    out.close();
					    pdImageQRCode = PDImageXObject.createFromFile(path+"/"+shopId+"qr.jpeg", document);
					 }
	         
					 
					
	         Table header;
	         Table billInfoTable;
	         Table custInfoTable;
	         Table itemInfo;
	         
	         
	         TableBuilder tableHeaderBuilder = Table.builder()
		                .addColumnsOfWidth(560)				                
		                .font(HELVETICA)
		                .borderColor(Color.BLACK)
		                .horizontalAlignment(CENTER);
	         
	         Row billType = Row.builder()
		                .add(TextCell.builder().text("BILL-OF-SUPPLY").fontSize(10).horizontalAlignment(CENTER).borderWidthTop(0.0F).borderWidthLeft(0.0F).borderWidthRight(0.0F).borderWidthBottom(0.5F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         Row headerRow  = Row.builder()
		                .add(TextCell.builder().text(this.getHeaderShopName()).fontSize(24).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         Row addressRow  = Row.builder()
		                .add(TextCell.builder().text((String)this.getSessionMap().get("shoponelineaddress")).fontSize(10).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         Row mobileRow  = Row.builder()
		                .add(TextCell.builder().text("Contact: "+(String)this.getSessionMap().get("shopcustcarenumber")).fontSize(10).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         
	         
	         
	         tableHeaderBuilder.addRow(billType);
	         
	         tableHeaderBuilder.addRow(headerRow);
	         if(addIntroLine.equals("TRUE"))
	         {
	        	 Row headerIntroRow  = Row.builder()
			                .add(TextCell.builder().text(headIntroLineContent).fontSize(10).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
			                .backgroundColor(WHITE)
			                .font(PDType1Font.HELVETICA_BOLD)	
			                .textColor(Color.BLACK)
			                .build();
	        	 
	        	 tableHeaderBuilder.addRow(headerIntroRow);
	        	 
	         }
	         tableHeaderBuilder.addRow(addressRow);
	         tableHeaderBuilder.addRow(mobileRow);
	         
	       
	         
	         header = tableHeaderBuilder.build();
	         
	         float startY = page.getMediaBox().getHeight() - PADDING20;
	        
	         if(addPageHeader)
	         {
		         TableDrawer.builder()
	                .contentStream(contentStream)
	                .table(header)
	                .startX(PADDING20)
	                .startY(startY)
	                .build()
	                .draw();
	         }
	         
	         TableBuilder tableBillInfoBuilder = Table.builder()
		                .addColumnsOfWidth(50,50,60,80)				                
		                .font(HELVETICA)
		                .borderColor(Color.BLACK)
		                .horizontalAlignment(CENTER);
	         
	         
	         Row billInfoRow1  = Row.builder()
		                .add(TextCell.builder().text("Bill No:"+this.getBillNumber()).colSpan(2).fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text("Billed By").fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text(this.getBillInfoDAO().getBilledBy()).fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         
	         Row billInfoRow2  = Row.builder()
	        		 	.add(TextCell.builder().text("Date:"+this.getBillInfoDAO().getBillDate()).colSpan(4).fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	        		 	.backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();

	         Row billInfoRow3  = Row.builder()
		                .add(TextCell.builder().text("Payment Type").colSpan(2).fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text(this.getBillInfoDAO().getPaymentType()).colSpan(2).fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
					    .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         tableBillInfoBuilder.addRow(billInfoRow1);
	         tableBillInfoBuilder.addRow(billInfoRow2);
	         tableBillInfoBuilder.addRow(billInfoRow3);
	         
	         billInfoTable = tableBillInfoBuilder.build();
	         
	         
	         float currentY = startY - 70;
	         
	         if(addIntroLine.equals("TRUE"))
	         {
	        	 currentY = startY - 90; 
	         }
	         
	        
	         
	         TableDrawer.builder()
             .contentStream(contentStream)
             .table(billInfoTable)
             .startX(340)
             .startY(currentY)
             .build()
             .draw();
	         
	         
	         TableBuilder tableCustInfoBuilder = Table.builder()
		                .addColumnsOfWidth(320);
	         
	         Row custInfoRow1 = Row.builder()
		                .add(TextCell.builder().text("Customer Name : "+this.getBillInfoDAO().getCustomerName()).fontSize(10).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthTop(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         Row custInfoRow2 = Row.builder()
		                .add(TextCell.builder().text("Mobile : "+custMobile).fontSize(10).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         Row custInfoRow3 = Row.builder()
		                .add(TextCell.builder().text("Address : "+custAddress).fontSize(10).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	    
	         
	         tableCustInfoBuilder.addRow(custInfoRow1);
	         tableCustInfoBuilder.addRow(custInfoRow2);
	         tableCustInfoBuilder.addRow(custInfoRow3);
	         
	         custInfoTable = tableCustInfoBuilder.build();
	         

	         
	         
	         TableDrawer.builder()
             .contentStream(contentStream)
             .table(custInfoTable)
             .startX(PADDING20)
             .startY(currentY)
             .build()
             .draw();
	         
	         TableBuilder tableItemInfoBuilder ;
	         
	         Row inteInfoHeaderRow;
	         
	         if(addMakingLaborColumn.equals("FALSE"))
	         {
	        	 tableItemInfoBuilder =  Table.builder()
        		 .addColumnsOfWidth(40,270,80,80,90);
	        	 
	        	 inteInfoHeaderRow = Row.builder()
		                .add(TextCell.builder().text("Sr No").fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text("Items").fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text("Rate").fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text("Quantity").fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
			            .add(TextCell.builder().text("Amount").fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .backgroundColor(GRAY_LIGHT_3)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         tableItemInfoBuilder.addRow(inteInfoHeaderRow);
	         
	         }
	         else
	         {
	        	 tableItemInfoBuilder =  Table.builder()
	            		 .addColumnsOfWidth(40,230,65,70,80,75);
	    	        	 
	    	        	 inteInfoHeaderRow = Row.builder()
	    		                .add(TextCell.builder().text("Sr No").fontSize(9).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .add(TextCell.builder().text("Items").fontSize(9).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .add(TextCell.builder().text("Rate").fontSize(9).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .add(TextCell.builder().text("Quantity").fontSize(9).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .add(TextCell.builder().text("Making / Labor Charges").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    			        .add(TextCell.builder().text("Amount").fontSize(9).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .backgroundColor(GRAY_LIGHT_3)
	    		                .font(PDType1Font.HELVETICA_BOLD)	
	    		                .textColor(Color.BLACK)
	    		                .build();
	    	         
	    	         tableItemInfoBuilder.addRow(inteInfoHeaderRow);
	         }

	         int srNo = 1;
	         int pageCount = 1;
	     	for(int i =0;i<listSize;i++)
				{
	     		
	     		//System.out.println("Starting Current Y :"+currentY);
					Row itemDetails = null;
					
					if(currentY  < 260)
					{
						
						Row toBeContinue =  Row.builder()
			        		 	.add(TextCell.builder().text("Page No."+pageCount+", To be continued on next page...").colSpan(5).fontSize(9).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
			        		 	.textColor(Color.BLACK)
				                .height(20F)
				                .font(fontMarathi)
				                .build();
						pageCount++;
						
						tableItemInfoBuilder.addRow(toBeContinue);
					
						itemInfo = tableItemInfoBuilder.build();
						
						float startY2 = page.getMediaBox().getHeight() - PADDING20;
			        	float currentY2 = startY2 - 120 ; 
			        	
			        	  if(addIntroLine.equals("TRUE"))
			 	         {
			 	        	 currentY = startY - 110; 
			 	         }
			 	         
						
						 TableDrawer.builder()
			             .contentStream(contentStream)
			             .table(itemInfo)
			             .startX(PADDING20)
			             .startY(currentY2)
			             .build()
			             .draw();
						
						 contentStream.close();
						 contentStream = null;
				        	PDPage newPage = new PDPage(PDRectangle.A4);
				        	 
				        	 contentStream = new PDPageContentStream(document,newPage);
				        	currentY = 20.0F;
				             document.addPage( newPage );
				             
					          startY = newPage.getMediaBox().getHeight() - PADDING20;
				             TableDrawer.builder()
				                .contentStream(contentStream)
				                .table(header)
				                .startX(PADDING20)
				                .startY(startY)
				                .build()
				                .draw();
				             
				             
					         currentY = startY - 80;
					         
					         if(addIntroLine.equals("TRUE"))
				 	         {
				 	        	 currentY = startY - 90; 
				 	         }
					         
					         TableDrawer.builder()
				             .contentStream(contentStream)
				             .table(billInfoTable)
				             .startX(PADDING20)
				             .startY(currentY)
				             .build()
				             .draw();
					         
					         currentY = currentY - 50;
					         if(addIntroLine.equals("TRUE"))
				 	         {
				 	        	 currentY = currentY - 40; 
				 	         }
					         
					         TableDrawer.builder()
				             .contentStream(contentStream)
				             .table(custInfoTable)
				             .startX(PADDING20)
				             .startY(currentY)
				             .build()
				             .draw();
					         
					         itemInfo = null;
					         tableItemInfoBuilder = null;
					         if(addMakingLaborColumn.equals("FALSE"))
					         {
					         tableItemInfoBuilder = Table.builder()
					        		 .addColumnsOfWidth(40,270,80,80,90);
					         }else
					         {
					        	 tableItemInfoBuilder =  Table.builder()
					            		 .addColumnsOfWidth(40,230,65,70,80,75);
					        	 
					         }
					       
					         
					         tableItemInfoBuilder.addRow(inteInfoHeaderRow);
					}
					
					
						BillProductInfoDAO informationDAO = this.getProductInfoList().get(i);
					
						if(informationDAO != null)
						{
						
							 if(addMakingLaborColumn.equals("FALSE"))
					         {
								
						         itemDetails = Row.builder()
						        		 	.add(TextCell.builder().text(""+srNo).fontSize(9).horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())				               
						        		 	.add(TextCell.builder().text(informationDAO.getProductName()).fontSize(8).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getQuantity()+" "+informationDAO.getSalesUnitShortName()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
								            .add(TextCell.builder().text(""+informationDAO.getAmountAfterDiscount()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
									        .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .height(20F)
							                .font(fontMarathi).fontSize(12)				              
							                .horizontalAlignment(CENTER)
							                .build();
						         srNo++;
					         }
							 else
							 {
								 itemDetails = Row.builder()
						        		 	.add(TextCell.builder().text(""+srNo).fontSize(9).horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())				               
						        		 	.add(TextCell.builder().text(informationDAO.getProductName()).fontSize(8).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getQuantity()+" "+informationDAO.getSalesUnitShortName()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getMakingLaborCharge()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getAmountAfterDiscount()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
									        .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .height(20F)
							                .font(fontMarathi).fontSize(12)				              
							                .horizontalAlignment(CENTER)
							                .build();
						         srNo++;
							 }
						}
						else
						{
							 if(addMakingLaborColumn.equals("FALSE"))
					         {
						         itemDetails = Row.builder()
						        		 	.add(TextCell.builder().text("").fontSize(9).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
						        		 	.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
						        			.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
								     	    .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
								            .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
									        .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .height(20F)
							                .font(fontMarathi).fontSize(12)				              
							                .horizontalAlignment(CENTER)
							                .build();
					         }else
					         {
					        	 itemDetails = Row.builder()
						        		 	.add(TextCell.builder().text("").fontSize(9).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
						        		 	.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
						        			.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
								     	    .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
								     	    .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
									        .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
									        .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .height(20F)
							                .font(fontMarathi).fontSize(12)				              
							                .horizontalAlignment(CENTER)
							                .build();
					         }
						}
					
			         tableItemInfoBuilder.addRow(itemDetails);
			        
			         currentY = (float) (currentY - 20.0F);
					//System.out.println("Inner : "+currentY);
					
				}
				DecimalFormat df2 = new DecimalFormat("#.#");
	     	 if(addCustomerCreditAmountToBill)
	         {
	     		float custCreditAmount = GetCustomerCreditAmountById.getCustomerCreditAmountById(this.getBillInfoDAO().getCustId(), this.getSessionMap());
	        	int colSpanCount = 2;
	     		if(addMakingLaborColumn.equals("TRUE"))
		         {
	     			colSpanCount = 3;
		         }
				Row totalInfoRow = Row.builder()
							.add(TextCell.builder().text("Total OutStanding Amount: Rs. "+df2.format(custCreditAmount)).colSpan(2).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(0.5F).build())				                
			             	.add(TextCell.builder().text("Total Bill Amount (in Rs.)").colSpan(colSpanCount).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
		        		 	.add(TextCell.builder().text(df2.format(floatTotalAmtAfterDiscount)).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
		        		 	.backgroundColor(WHITE)
			                .textColor(Color.BLACK)
			                .height(20F)
			                .font(fontMarathiBold).fontSize(10)				              
			                .horizontalAlignment(CENTER)
			                .build();
				tableItemInfoBuilder.addRow(totalInfoRow);
				
	         }
	     	 else
	     	 {
	     		int colSpanCount = 4;
	     		if(addMakingLaborColumn.equals("TRUE"))
		         {
	     			colSpanCount = 5;
		         }
	     		
	     		Row totalInfoRow = Row.builder()
	        		 	.add(TextCell.builder().text("Total Bill Amount(in Rs.)").colSpan(colSpanCount).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
	        		 	.add(TextCell.builder().text(df2.format(floatTotalAmtAfterDiscount)).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
	        		 	.backgroundColor(WHITE)
		                .textColor(Color.BLACK)
		                .height(20F)
		                .font(fontMarathiBold).fontSize(12)				              
		                .horizontalAlignment(CENTER)
		                .build();
	     			tableItemInfoBuilder.addRow(totalInfoRow);
	     	 }
				
				 
	     	int colSpanCountBottom = 5;
     		if(addMakingLaborColumn.equals("TRUE"))
	         {
     			colSpanCountBottom = 6;
	         }
				
				  String convertedAmount = new NumberToWordsConverter().getConverted(""+floatTotalAmtAfterDiscount);
		      
				  Row amtInwordsRow = Row.builder()
		        		 	.add(TextCell.builder().text("Amount in Words : "+convertedAmount).colSpan(colSpanCountBottom).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
		        		 	.backgroundColor(WHITE)
			                .textColor(Color.BLACK)
			                .height(20F)
			                .font(fontMarathi).fontSize(12)				              
			                .horizontalAlignment(CENTER)
			                .build();
				tableItemInfoBuilder.addRow(amtInwordsRow);
				String comm = this.getBillInfoDAO().getComments();
				
				if(comm == null)
				{
					comm = "";
				}
				Row commentsRow = Row.builder()
	        		 	.add(TextCell.builder().text("Comments:"+comm).colSpan(colSpanCountBottom).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
	        		 	.backgroundColor(WHITE)
		                .textColor(Color.BLACK)
		                .height(15F)
		                .font(fontMarathi).fontSize(9)				              
		                .horizontalAlignment(LEFT)
		                .build();
			tableItemInfoBuilder.addRow(commentsRow);
	         
	         itemInfo = tableItemInfoBuilder.build();
	         
	         
	         TableBuilder signatureBuiler = Table.builder()
		                .addColumnsOfWidth(245,135,180)				                
		                .font(HELVETICA)
		                .borderColor(Color.BLACK)
		                .horizontalAlignment(CENTER);
	         
	         Row signRow1 = Row.builder()
	        		 	.add(TextCell.builder().text("").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())
		                .add(TextCell.builder().text("").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())
		                .add(TextCell.builder().text("For "+this.getHeaderShopName()).verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())
		                .backgroundColor(Color.WHITE)
		                .textColor(Color.BLACK)
		                .font(PDType1Font.HELVETICA_BOLD)
		                .fontSize(9)				              
		                .horizontalAlignment(CENTER)
		                .height(20F)	
		                .build();
	         signatureBuiler.addRow(signRow1);
	         
	         Row signRow2 = Row.builder()
	        		 	.add(TextCell.builder().text("").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.0F).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(10F).build())
		                .add(TextCell.builder().text("Customer Signature").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.0F).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(10F).build())
		                .add(TextCell.builder().text("Authorized Signature").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.0F).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(10F).build())					               
		                .backgroundColor(Color.WHITE)
		                .textColor(Color.BLACK)
		                .font(PDType1Font.HELVETICA_BOLD)
		                .fontSize(9)				              
		                .horizontalAlignment(CENTER)
		                .height(60F)	
		                .build();
	         signatureBuiler.addRow(signRow2);
	       
	         
	         Table signature = signatureBuiler.build();   
	         
	      
	         itemInfo = tableItemInfoBuilder.build();
	         
        	float startY2 = page.getMediaBox().getHeight() - PADDING20;
        	float currentY2 = startY2 - 120 ; 
        	
        	
        	if(addIntroLine.equals("TRUE"))
 	         {
        		currentY2 = startY2 - 140; 
 	         }
        	 
      	 TableDrawer.builder()
             .contentStream(contentStream)
             .table(itemInfo)
             .startX(PADDING20)
             .startY(currentY2)
             .build()
             .draw();
			
	        
	     
	         
	         TableDrawer.builder()
             .contentStream(contentStream)
             .table(signature)
             .startX(PADDING20)
             .startY(currentY-120)
             .build()
             .draw();
	         
	         
	         if(addPageHeader)
	         {
	         
		         if(pdImageLeftLogoImage != null)
	        	 {
		        	
	        		 contentStream.drawImage(pdImageLeftLogoImage, 30, 335 , 45, 45);
	        		
	        	 }
	
		         if(pdImageRightLogoImage != null)
	        	 {
		        	
	        		 contentStream.drawImage(pdImageRightLogoImage, 525, 335 , 45, 45);
	        		
	        	 }
	         }
			 
	         	contentStream.close();
			 	document.save(path+"/bill.pdf");
		        document.close();
		        
		        

				response.setHeader("Content-disposition", "inline; filename=bill.pdf");
				response.setContentType("application/pdf");
				FileInputStream fileInputStream = new FileInputStream(path+"/bill.pdf");
				PrintWriter out = response.getWriter();  
				int bytes;
				while ((bytes = fileInputStream.read()) != -1) {
					out.write(bytes);
				}
				fileInputStream.close();
				out.flush();
				out.close();
				ttf1.close();
				ttf2.close();
			
	         
	        
				}
		        
		        
		        
		        
		        if((this.getBillInfoDAO().getBillType().equals("BILL-OF-SUPPLY") || this.getBillInfoDAO().getBillType().equals("COMPOSITE-BILL")) && this.getLanguage().equals("ENGLISH") && this.getBillType().equals("A5") && a5PageOrientation.equals("PORTRAIT"))
		        {

		        	
		        	
		        	String custMobile = "";
		        	String custAddress = "";
		        	float totalDiscountAmt = 0.0F;
		        	
		        	if(resultSet != null)
		        	{
		        		resultSet.close();
		        		resultSet = null;
		        	}
		        	
		        	if(preparedStatement != null)
		        	{
		        		preparedStatement.close();
		        		preparedStatement = null;
		        	}
		        	
		        	
		        	sql = "SELECT "
		        			+ "mobile_number,"
		        			+ "billing_address "
		        			+ "FROM "
		        			+ "shop_customer_master "
		        			+ "WHERE "
		        			+ "customer_name = ? "
		        			+ "AND "
		        			+ "customer_id = ? "
		        			+ "AND "
		        			+ "shop_id = ? "
		        			+ "AND "
		        			+ "shop_code = ?";
		        	
		        	preparedStatement = connection.prepareStatement(sql);
		        	preparedStatement.setString(1, this.getBillInfoDAO().getCustomerName());
		        	preparedStatement.setString(2, this.getBillInfoDAO().getCustId());
		        	preparedStatement.setString(3, shopId);
		        	preparedStatement.setString(4, shopCode);
		        	
		        	resultSet = preparedStatement.executeQuery();
		        	
		        	while(resultSet.next())
		        	{
		        		custMobile = resultSet.getString(1);
		        		custAddress = resultSet.getString(2);
		        	}
		        	
		        	
		        	PDDocument document = new PDDocument(); 
					PDPage page = null;
					
					int productListSize = this.getProductInfoList().size();
					
					
						page = new PDPage(new PDRectangle(420.9449f,595.2756f));
					
					 
					 document.addPage(page);
					 
						
						
					 File fontFile  =  new File( request.getSession().getServletContext().getRealPath("/fonts/Nirmala.ttf"));
					 File fontFileBold  =  new File( request.getSession().getServletContext().getRealPath("/fonts/nirmala-bold.ttf"));
					 
					 TrueTypeFont ttf1 = new TTFParser().parse(fontFile);
					 PDFont fontMarathi = PDType0Font.load(document, ttf1, true);
					 
					 TrueTypeFont ttf2 = new TTFParser().parse(fontFileBold);
					 PDFont fontMarathiBold = PDType0Font.load(document, ttf2, true);
					 
			         PDPageContentStream contentStream = new PDPageContentStream(document, page);
			         
			         
			         
			         PDImageXObject pdImageQRCode = null;
			         PDImageXObject pdImageLeftLogoImage = null;
			         PDImageXObject pdImageRightLogoImage = null;
			         Blob leftLogoImageBlob = null;
			         Blob rightLogoImageBlob = null;
			         InputStream leftLogoIS = null;
			         InputStream rightLogoIS = null;
			        		 
					 Blob blob = (Blob) this.getSessionMap().get("qr_image_bolb");
					 
					 //headintroline
					 
				
					 String headIntroLineContent = (String)this.getSessionMap().get("headintroline");
					 
					 if(shopSettingsMap.get("add_left_side_logo").equals("TRUE"))
					 {
						
							
							 byte[] leftLogoBytes =(byte[]) this.getSessionMap().get("left_logo_image_array");
							 pdImageLeftLogoImage = PDImageXObject.createFromByteArray(document, leftLogoBytes, "leftLogo");
						 
						
					 }
					 if(shopSettingsMap.get("add_right_side_logo").equals("TRUE"))
					 {

						 byte[] rightLogoBytes =(byte[]) this.getSessionMap().get("right_logo_image_array");
						 pdImageRightLogoImage = PDImageXObject.createFromByteArray(document, rightLogoBytes, "rightLogo");
					 }
					 
					 if(blob != null)
					 {
					 InputStream in = blob.getBinaryStream();
					 File qrFile = new File(path+"/"+shopId+"qr.jpeg");
					 FileOutputStream out = new FileOutputStream(qrFile);
					 byte[] buffer = new byte[1024];
					    int read;
					    while ((read = in.read(buffer)) != -1) {
					        out.write(buffer, 0, read);
					    }
					    
					    in.close();
					    out.close();
					    pdImageQRCode = PDImageXObject.createFromFile(path+"/"+shopId+"qr.jpeg", document);
					 }
	         
					 
					
	         Table header;
	         Table billInfoTable;
	         Table custInfoTable;
	         Table itemInfo;
	         
	         
	         TableBuilder tableHeaderBuilder = Table.builder()
		                .addColumnsOfWidth(380)				                
		                .font(HELVETICA)
		                .borderColor(Color.BLACK)
		                .horizontalAlignment(CENTER);
	         
	         Row billType = Row.builder()
		                .add(TextCell.builder().text("BILL-OF-SUPPLY").fontSize(10).horizontalAlignment(CENTER).borderWidthTop(0.0F).borderWidthLeft(0.0F).borderWidthRight(0.0F).borderWidthBottom(0.5F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         Row headerRow  = Row.builder()
		                .add(TextCell.builder().text(this.getHeaderShopName()).fontSize(20).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         Row addressRow  = Row.builder()
		                .add(TextCell.builder().text((String)this.getSessionMap().get("shoponelineaddress")).fontSize(9).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         Row mobileRow  = Row.builder()
		                .add(TextCell.builder().text("Contact: "+(String)this.getSessionMap().get("shopcustcarenumber")).fontSize(9).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         
	         
	         
	         tableHeaderBuilder.addRow(billType);
	         
	         tableHeaderBuilder.addRow(headerRow);
	         if(addIntroLine.equals("TRUE"))
	         {
	        	 Row headerIntroRow  = Row.builder()
			                .add(TextCell.builder().text(headIntroLineContent).fontSize(9).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
			                .backgroundColor(WHITE)
			                .font(PDType1Font.HELVETICA_BOLD)	
			                .textColor(Color.BLACK)
			                .build();
	        	 
	        	 tableHeaderBuilder.addRow(headerIntroRow);
	        	 
	         }
	         tableHeaderBuilder.addRow(addressRow);
	         tableHeaderBuilder.addRow(mobileRow);
	         
	       
	         
	         header = tableHeaderBuilder.build();
	         
	         float startY = page.getMediaBox().getHeight() - PADDING20;
	         
	         if(addPageHeader)
	         {
		         TableDrawer.builder()
	                .contentStream(contentStream)
	                .table(header)
	                .startX(PADDING20)
	                .startY(startY)
	                .build()
	                .draw();
	         }
	         
	         TableBuilder tableBillInfoBuilder = Table.builder()
		                .addColumnsOfWidth(30,30,40,60)				                
		                .font(HELVETICA)
		                .borderColor(Color.BLACK)
		                .horizontalAlignment(CENTER);
	         
	         
	         Row billInfoRow1  = Row.builder()
		                .add(TextCell.builder().text("Bill No:"+this.getBillNumber()).colSpan(2).fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text("Billed By").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text(this.getBillInfoDAO().getBilledBy()).fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         
	         Row billInfoRow2  = Row.builder()
	        		 	.add(TextCell.builder().text("Date:"+this.getBillInfoDAO().getBillDate()).colSpan(4).fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	        		 	.backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();

	         Row billInfoRow3  = Row.builder()
		                .add(TextCell.builder().text("Payment Type").colSpan(3).fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text(this.getBillInfoDAO().getPaymentType()).fontSize(7).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
					    .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         tableBillInfoBuilder.addRow(billInfoRow1);
	         tableBillInfoBuilder.addRow(billInfoRow2);
	         tableBillInfoBuilder.addRow(billInfoRow3);
	         
	         billInfoTable = tableBillInfoBuilder.build();
	         
	         
	         float currentY = startY - 70;
	         
	         if(addIntroLine.equals("TRUE"))
	         {
	        	 currentY = startY - 90; 
	         }
	          
	      	 if(!addPageHeader)
        	 {
	      		currentY = startY - 140;
        	 }
 	         
	         
	         TableDrawer.builder()
             .contentStream(contentStream)
             .table(billInfoTable)
             .startX(240)
             .startY(currentY)
             .build()
             .draw();
	         
	         
	         TableBuilder tableCustInfoBuilder = Table.builder()
		                .addColumnsOfWidth(220);
	         
	         Row custInfoRow1 = Row.builder()
		                .add(TextCell.builder().text("Customer Name : "+this.getBillInfoDAO().getCustomerName()).fontSize(8).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthTop(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         Row custInfoRow2 = Row.builder()
		                .add(TextCell.builder().text("Mobile : "+custMobile).fontSize(8).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         Row custInfoRow3 = Row.builder()
		                .add(TextCell.builder().text("Address : "+custAddress).fontSize(8).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	    
	         
	         tableCustInfoBuilder.addRow(custInfoRow1);
	         tableCustInfoBuilder.addRow(custInfoRow2);
	         tableCustInfoBuilder.addRow(custInfoRow3);
	         
	         custInfoTable = tableCustInfoBuilder.build();
	         

	         
	         
	         TableDrawer.builder()
             .contentStream(contentStream)
             .table(custInfoTable)
             .startX(PADDING20)
             .startY(currentY)
             .build()
             .draw();
	         
	         TableBuilder tableItemInfoBuilder ;
	         
	         Row inteInfoHeaderRow;
	         
	         if(addMakingLaborColumn.equals("FALSE"))
	         {
	        	 if(addDiscountColumn)
	        	 {
			        	 tableItemInfoBuilder =  Table.builder()
		        		 .addColumnsOfWidth(25,155,45,45,45,65);
			        	 
			        	 inteInfoHeaderRow = Row.builder()
				                .add(TextCell.builder().text("Sr No").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
				                .add(TextCell.builder().text("Items").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
				                .add(TextCell.builder().text("Rate").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
				                .add(TextCell.builder().text("Quantity").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
				                .add(TextCell.builder().text("Discount").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
					            .add(TextCell.builder().text("Amount").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
				                .backgroundColor(GRAY_LIGHT_3)
				                .font(PDType1Font.HELVETICA_BOLD)	
				                .textColor(Color.BLACK)
				                .build();
			         
			         tableItemInfoBuilder.addRow(inteInfoHeaderRow);
	        	 }
	        	 else
	        	 {
	        		
	        			 tableItemInfoBuilder =  Table.builder()
				        		 .addColumnsOfWidth(25,165,55,55,80);
					        	 
					        	 inteInfoHeaderRow = Row.builder()
						                .add(TextCell.builder().text("Sr No").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
						                .add(TextCell.builder().text("Items").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
						                .add(TextCell.builder().text("Rate").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
						                .add(TextCell.builder().text("Quantity").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
							            .add(TextCell.builder().text("Amount").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
						                .backgroundColor(GRAY_LIGHT_3)
						                .font(PDType1Font.HELVETICA_BOLD)	
						                .textColor(Color.BLACK)
						                .build();
					         
					         tableItemInfoBuilder.addRow(inteInfoHeaderRow); 
		        	
	        	 }
	         
	         }
	         else
	         {
	        	 if(addDiscountColumn)
	        	 {
	        		 tableItemInfoBuilder =  Table.builder()
		            		 .addColumnsOfWidth(25,120,45,45,45,45,55);
		    	        	 
		    	        	 inteInfoHeaderRow = Row.builder()
		    		                .add(TextCell.builder().text("Sr No").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    		                .add(TextCell.builder().text("Items").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    		                .add(TextCell.builder().text("Rate").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    		                .add(TextCell.builder().text("Quantity").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    		                .add(TextCell.builder().text("Making / Labor Charges").fontSize(5).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    		                .add(TextCell.builder().text("Discount").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    		                .add(TextCell.builder().text("Amount").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    		                .backgroundColor(GRAY_LIGHT_3)
		    		                .font(PDType1Font.HELVETICA_BOLD)	
		    		                .textColor(Color.BLACK)
		    		                .build();
		    	         
		    	         tableItemInfoBuilder.addRow(inteInfoHeaderRow);
	        	 }
	        	 else
	        	 {
	        	 tableItemInfoBuilder =  Table.builder()
	            		 .addColumnsOfWidth(25,135,55,55,55,55);
	    	        	 
	    	        	 inteInfoHeaderRow = Row.builder()
	    		                .add(TextCell.builder().text("Sr No").fontSize(7).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .add(TextCell.builder().text("Items").fontSize(7).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .add(TextCell.builder().text("Rate").fontSize(7).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .add(TextCell.builder().text("Quantity").fontSize(7).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .add(TextCell.builder().text("Making / Labor Charges").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    			        .add(TextCell.builder().text("Amount").fontSize(7).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .backgroundColor(GRAY_LIGHT_3)
	    		                .font(PDType1Font.HELVETICA_BOLD)	
	    		                .textColor(Color.BLACK)
	    		                .build();
	    	         
	    	         tableItemInfoBuilder.addRow(inteInfoHeaderRow);
	        	 }
	         }

	         int srNo = 1;
	         int pageCount = 1;
	         int listCount = this.getProductInfoList().size();
	         
	         if(listCount < 10)
	         {
	        	 listCount = 10;
	         }
	         
	     	for(int i =0;i<listCount;i++)
				{
	     		
	     		//System.out.println("Starting Current Y :"+currentY);
					Row itemDetails = null;
					
					if(currentY  < 250)
					{
						int colSpan = 5;
						 if(addDiscountColumn)
			        	 {
							 colSpan = 6;
			        	 }
						
						Row toBeContinue =  Row.builder()
			        		 	.add(TextCell.builder().text("Page No."+pageCount+", To be continued on next page...").colSpan(colSpan).fontSize(9).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
			        		 	.textColor(Color.BLACK)
				                .height(20F)
				                .font(fontMarathi)
				                .build();
						pageCount++;
						
						tableItemInfoBuilder.addRow(toBeContinue);
					
						itemInfo = tableItemInfoBuilder.build();
						
						float startY2 = page.getMediaBox().getHeight() - PADDING20;
						
			        	float currentY2 = startY2 - 135 ; 
			        	
			        	 if(addIntroLine.equals("TRUE"))
			 	         {
			 	        	 currentY = startY - 110; 
			 	         }
			        	 
			        	 if(!addPageHeader)
			        	 {
			        		 currentY2 = startY2 - 210;  
			        	 }
			        	 
			        	 if(addPageHeader)
				         {
				         
					         
					         if(pdImageLeftLogoImage != null)
				        	 {
					        	
				        		 contentStream.drawImage(pdImageLeftLogoImage, 30, 515 , 35, 35);
				        		
				        	 }
				
					         if(pdImageRightLogoImage != null)
				        	 {
					        	
				        		 contentStream.drawImage(pdImageRightLogoImage, 425, 435 , 35, 35);
				        		
				        	 }
				         }
						 
			 	         
			        	
						
						 TableDrawer.builder()
			             .contentStream(contentStream)
			             .table(itemInfo)
			             .startX(PADDING20)
			             .startY(currentY2)
			             .build()
			             .draw();
						
						 contentStream.close();
						 contentStream = null;
				        	PDPage newPage = new PDPage(new PDRectangle(420.9449f,595.2756f));
							
				        	 
				        	 contentStream = new PDPageContentStream(document,newPage);
				        	currentY = 20.0F;
				             document.addPage( newPage );
				             
					          startY = newPage.getMediaBox().getHeight() - PADDING20;
				             TableDrawer.builder()
				                .contentStream(contentStream)
				                .table(header)
				                .startX(PADDING20)
				                .startY(startY)
				                .build()
				                .draw();
				             
				             
					         currentY = startY - 80;
					         
					         if(addIntroLine.equals("TRUE"))
				 	         {
				 	        	 currentY = startY - 90; 
				 	         }
					         
					         
				        	 TableDrawer.builder()
				             .contentStream(contentStream)
				             .table(custInfoTable)
				             .startX(PADDING20)
				             .startY(currentY)
				             .build()
				             .draw();
				        	 
					         TableDrawer.builder()
				             .contentStream(contentStream)
				             .table(billInfoTable)
				             .startX(240)
				             .startY(currentY)
				             .build()
				             .draw();
					         
					         currentY = currentY - 50;
					         if(addIntroLine.equals("TRUE"))
				 	         {
				 	        	 currentY = currentY - 40; 
				 	         }
					       
					         itemInfo = null;
					         tableItemInfoBuilder = null;
					         if(addMakingLaborColumn.equals("FALSE"))
					         {
					        	 if(addDiscountColumn)
					        	 {
					        		 tableItemInfoBuilder = Table.builder()
					        				 .addColumnsOfWidth(25,155,45,45,45,65);
					        	 }
					        	 else
					        	 {
					        		 tableItemInfoBuilder = Table.builder()
					        				 .addColumnsOfWidth(25,165,55,55,80);
						        	 
					        	 }
					         }else
					         {
					        	 if(addDiscountColumn)
					        	 {
					        		 tableItemInfoBuilder =  Table.builder()
					        				 .addColumnsOfWidth(25,120,45,45,45,45,55);
					        	 }
					        	 else
					        	 {
					        		 tableItemInfoBuilder =  Table.builder()
					        				 .addColumnsOfWidth(25,135,55,55,55,55);
				    	        	 
					        	 }
					        	 
					         }
					       
					         
					         tableItemInfoBuilder.addRow(inteInfoHeaderRow);
					}
					
					
						BillProductInfoDAO informationDAO = null;
						
						try						
						{
							informationDAO = this.getProductInfoList().get(i);
						}catch (Exception e) {}
						if(informationDAO != null)
						{
						
							 if(addMakingLaborColumn.equals("FALSE"))
					         {
								
								 if(addDiscountColumn)
					        	 {
									 itemDetails = Row.builder()
							        		 	.add(TextCell.builder().text(""+srNo).fontSize(9).horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())				               
							        		 	.add(TextCell.builder().text(informationDAO.getProductName()).fontSize(8).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
								                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
								                .add(TextCell.builder().text(""+informationDAO.getQuantity()+" "+informationDAO.getSalesUnitShortName()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
								                .add(TextCell.builder().text(""+informationDAO.getDiscountRupees()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
										        .add(TextCell.builder().text(""+informationDAO.getAmountAfterDiscount()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
										        .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .height(20F)
								                .font(fontMarathi).fontSize(9)				              
								                .horizontalAlignment(CENTER)
								                .build();
							         srNo++;
							         
							         totalDiscountAmt = totalDiscountAmt + informationDAO.getDiscountRupees();
					        	 }
								 else
								 {
						         itemDetails = Row.builder()
						        		 	.add(TextCell.builder().text(""+srNo).fontSize(9).horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())				               
						        		 	.add(TextCell.builder().text(informationDAO.getProductName()).fontSize(8).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getQuantity()+" "+informationDAO.getSalesUnitShortName()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
								            .add(TextCell.builder().text(""+informationDAO.getAmountAfterDiscount()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
									        .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .height(20F)
							                .font(fontMarathi).fontSize(9)				              
							                .horizontalAlignment(CENTER)
							                .build();
						         srNo++;
								 }
					         }
							 else
							 {
								 itemDetails = Row.builder()
						        		 	.add(TextCell.builder().text(""+srNo).fontSize(9).horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())				               
						        		 	.add(TextCell.builder().text(informationDAO.getProductName()).fontSize(8).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getQuantity()+" "+informationDAO.getSalesUnitShortName()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getMakingLaborCharge()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getAmountAfterDiscount()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
									        .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .height(20F)
							                .font(fontMarathi).fontSize(9)				              
							                .horizontalAlignment(CENTER)
							                .build();
						         srNo++;
							 }
						}
						else
						{
							 if(addMakingLaborColumn.equals("FALSE"))
					         {
								 
								 if(addDiscountColumn)
					        	 {
									 itemDetails = Row.builder()
							        		 	.add(TextCell.builder().text("").fontSize(9).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							        		 	.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							        			.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							        			.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
										     	.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
									            .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
										        .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .height(20F)
								                .font(fontMarathi).fontSize(9)				              
								                .horizontalAlignment(CENTER)
								                .build();
									 
									 
					        	 }
								 else
								 {
						         itemDetails = Row.builder()
						        		 	.add(TextCell.builder().text("").fontSize(9).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
						        		 	.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
						        			.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
								     	    .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
								            .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
									        .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .height(20F)
							                .font(fontMarathi).fontSize(9)				              
							                .horizontalAlignment(CENTER)
							                .build();
								 }
					         }else
					         {
					        	 if(addDiscountColumn)
					        	 {
					        		 itemDetails = Row.builder()
							        		 	.add(TextCell.builder().text("").fontSize(9).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							        		 	.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							        			.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
									     	    .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
									     	    .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
										     	.add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
										        .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
										        .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .height(20F)
								                .font(fontMarathi).fontSize(9)				              
								                .horizontalAlignment(CENTER)
								                .build();
					        	 }
					        	 else
					        	 {
					        		 
					        	 
						        	 itemDetails = Row.builder()
							        		 	.add(TextCell.builder().text("").fontSize(9).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							        		 	.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							        			.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
									     	    .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
									     	    .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
										        .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
										        .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .height(20F)
								                .font(fontMarathi).fontSize(9)				              
								                .horizontalAlignment(CENTER)
								                .build();
					        	 }
					         }
						}
					
			         tableItemInfoBuilder.addRow(itemDetails);
			        
			         currentY = (float) (currentY - 20.0F);
					//System.out.println("Inner : "+currentY);
					
				}
				DecimalFormat df2 = new DecimalFormat("#.#");
	     	
			if(addCustomerCreditAmountToBill)
	         {
	     		float custCreditAmount = GetCustomerCreditAmountById.getCustomerCreditAmountById(this.getBillInfoDAO().getCustId(), this.getSessionMap());
	        	int colSpanCount = 2;
	     		if(addMakingLaborColumn.equals("TRUE"))
		         {
	     			colSpanCount = 3;
		         }
	     		
	     		
	     		if(addDiscountColumn && addMakingLaborColumn.equals("TRUE"))
	        	 {
	     			colSpanCount = 4;
	        	 }
	     		
	     		if(addDiscountColumn)
	     		{
	     			colSpanCount = 3;
	     		}
	     		
				Row totalInfoRow = Row.builder()
							.add(TextCell.builder().text("Total OutStanding Amount: Rs. "+df2.format(custCreditAmount)).colSpan(2).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(0.5F).build())				                
			             	.add(TextCell.builder().text("Total Bill Amount (in Rs.)").colSpan(colSpanCount).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
		        		 	.add(TextCell.builder().text(df2.format(floatTotalAmtAfterDiscount)).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
		        		 	.backgroundColor(WHITE)
			                .textColor(Color.BLACK)
			                .height(20F)
			                .font(fontMarathiBold).fontSize(8)				              
			                .horizontalAlignment(CENTER)
			                .build();
				tableItemInfoBuilder.addRow(totalInfoRow);
				
	         }
	     	 else
	     	 {
	     		int colSpanCount = 4;
	     		int colSpanAddTotalDisc = 3;
	     		
	     		if(addMakingLaborColumn.equals("TRUE"))
		         {
	     			colSpanCount = 5;
	     			colSpanAddTotalDisc = 4;
		         }
	     		
	     		if(addDiscountColumn && addMakingLaborColumn.equals("TRUE"))
	        	 {
	     			colSpanCount = 6;
	     			colSpanAddTotalDisc = 5;
	        	 }
	     		
	     		if(addDiscountColumn)
	     		{
	     			colSpanCount = 5;
	     			colSpanAddTotalDisc = 4;
	     		}
	     		
	     		
	     		Row totalMoneySavedInfoRow = Row.builder()
	        		 	.add(TextCell.builder().text("Total Savings:").colSpan(colSpanAddTotalDisc).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
	        		 	.add(TextCell.builder().text(df2.format(totalDiscountAmt)).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
	        			.add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
		        		 .backgroundColor(WHITE)
		                .textColor(Color.BLACK)
		                .height(20F)
		                .font(fontMarathiBold).fontSize(9)				              
		                .horizontalAlignment(CENTER)
		                .build();
	     			tableItemInfoBuilder.addRow(totalMoneySavedInfoRow);
	     			
	     		Row totalInfoRow = Row.builder()
	        		 	.add(TextCell.builder().text("Total Bill Amount(in Rs.)").colSpan(colSpanCount).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
	        		 	.add(TextCell.builder().text(df2.format(floatTotalAmtAfterDiscount)).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
	        		 	.backgroundColor(WHITE)
		                .textColor(Color.BLACK)
		                .height(20F)
		                .font(fontMarathiBold).fontSize(9)				              
		                .horizontalAlignment(CENTER)
		                .build();
	     			tableItemInfoBuilder.addRow(totalInfoRow);
	     	 }
				
				 
	     	int colSpanCountBottom = 5;
     		if(addMakingLaborColumn.equals("TRUE"))
	         {
     			colSpanCountBottom = 6;
	         }
     		
     		
     		if(addDiscountColumn && addMakingLaborColumn.equals("TRUE"))
	       	 {
	     			colSpanCountBottom = 7;
	       	 }
    		
    		if(addDiscountColumn)
    		{
    			colSpanCountBottom = 6;
    		}
				
				  String convertedAmount = new NumberToWordsConverter().getConverted(""+floatTotalAmtAfterDiscount);
		      
				  Row amtInwordsRow = Row.builder()
		        		 	.add(TextCell.builder().text("Amount in Words : "+convertedAmount).colSpan(colSpanCountBottom).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
		        		 	.backgroundColor(WHITE)
			                .textColor(Color.BLACK)
			                .height(20F)
			                .font(fontMarathi).fontSize(8)				              
			                .horizontalAlignment(CENTER)
			                .build();
				tableItemInfoBuilder.addRow(amtInwordsRow);
				String comm = this.getBillInfoDAO().getComments();
				
				if(comm == null)
				{
					comm = "";
				}
				Row commentsRow = Row.builder()
	        		 	.add(TextCell.builder().text("Comments:"+comm).colSpan(colSpanCountBottom).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
	        		 	.backgroundColor(WHITE)
		                .textColor(Color.BLACK)
		                .height(15F)
		                .font(fontMarathi).fontSize(8)				              
		                .horizontalAlignment(LEFT)
		                .build();
			tableItemInfoBuilder.addRow(commentsRow);
	         
	         itemInfo = tableItemInfoBuilder.build();
	         
	         
	         TableBuilder signatureBuiler = Table.builder()
		                .addColumnsOfWidth(145,90,145)				                
		                .font(HELVETICA)
		                .borderColor(Color.BLACK)
		                .horizontalAlignment(CENTER);
	         
	         Row signRow1 = Row.builder()
	        		 	.add(TextCell.builder().text("").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())
		                .add(TextCell.builder().text("").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())
		                .add(TextCell.builder().text("For "+this.getHeaderShopName()).verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())
		                .backgroundColor(Color.WHITE)
		                .textColor(Color.BLACK)
		                .font(PDType1Font.HELVETICA_BOLD)
		                .fontSize(9)				              
		                .horizontalAlignment(CENTER)
		                .height(20F)	
		                .build();
	         signatureBuiler.addRow(signRow1);
	         
	         Row signRow2 = Row.builder()
	        		 	.add(TextCell.builder().text("").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.0F).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(1F).build())
		                .add(TextCell.builder().text("Customer Signature").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.0F).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(1F).build())
		                .add(TextCell.builder().text("Authorized Signature").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.0F).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(1F).build())					               
		                .backgroundColor(Color.WHITE)
		                .textColor(Color.BLACK)
		                .font(PDType1Font.HELVETICA_BOLD)
		                .fontSize(9)				              
		                .horizontalAlignment(CENTER)
		                .height(60F)	
		                .build();
	         signatureBuiler.addRow(signRow2);
	       
	         
	         Table signature = signatureBuiler.build();   
	         
	      
	         itemInfo = tableItemInfoBuilder.build();
	         
        	float startY2 = page.getMediaBox().getHeight() - PADDING20;
        	float currentY2 = startY2 - 120 ; 
        	
        	
        	if(addIntroLine.equals("TRUE"))
 	         {
        		currentY2 = startY2 - 140; 
 	         }
        	
        	if(!addPageHeader)
        	{
        		currentY2 = startY2 - 185; 
        	}
        	 
      	 TableDrawer.builder()
             .contentStream(contentStream)
             .table(itemInfo)
             .startX(PADDING20)
             .startY(currentY2)
             .build()
             .draw();
			
	        
	     
	         
	         TableDrawer.builder()
             .contentStream(contentStream)
             .table(signature)
             .startX(PADDING20)
             .startY(currentY-120)
             .build()
             .draw();
	         
	         
	         if(addPageHeader)
	         {
	         
		         
		         if(pdImageLeftLogoImage != null)
	        	 {
		        	
	        		 contentStream.drawImage(pdImageLeftLogoImage, 30, 515 , 35, 35);
	        		
	        	 }
	
		         if(pdImageRightLogoImage != null)
	        	 {
		        	
	        		 contentStream.drawImage(pdImageRightLogoImage, 425, 435 , 35, 35);
	        		
	        	 }
	         }
			 
	         	contentStream.close();
			 	document.save(path+"/bill.pdf");
		        document.close();
		        
		        

				response.setHeader("Content-disposition", "inline; filename=bill.pdf");
				response.setContentType("application/pdf");
				FileInputStream fileInputStream = new FileInputStream(path+"/bill.pdf");
				PrintWriter out = response.getWriter();  
				int bytes;
				while ((bytes = fileInputStream.read()) != -1) {
					out.write(bytes);
				}
				fileInputStream.close();
				out.flush();
				out.close();
				ttf1.close();
				ttf2.close();
			
	         
	        
				
		        }
		        
		        
		        
		        if(this.getBillInfoDAO().getBillType().equals("ESTIMATE") && this.getLanguage().equals("ENGLISH") && this.getBillType().equals("A5") && a5PageOrientation.equals("PORTRAIT"))
		        {


		        	
		        	
		        	String custMobile = "";
		        	String custAddress = "";
		        	float totalDiscountAmt = 0.0F;
		        	
		        	if(resultSet != null)
		        	{
		        		resultSet.close();
		        		resultSet = null;
		        	}
		        	
		        	if(preparedStatement != null)
		        	{
		        		preparedStatement.close();
		        		preparedStatement = null;
		        	}
		        	
		        	
		        	sql = "SELECT "
		        			+ "mobile_number,"
		        			+ "billing_address "
		        			+ "FROM "
		        			+ "shop_customer_master "
		        			+ "WHERE "
		        			+ "customer_name = ? "
		        			+ "AND "
		        			+ "customer_id = ? "
		        			+ "AND "
		        			+ "shop_id = ? "
		        			+ "AND "
		        			+ "shop_code = ?";
		        	
		        	preparedStatement = connection.prepareStatement(sql);
		        	preparedStatement.setString(1, this.getBillInfoDAO().getCustomerName());
		        	preparedStatement.setString(2, this.getBillInfoDAO().getCustId());
		        	preparedStatement.setString(3, shopId);
		        	preparedStatement.setString(4, shopCode);
		        	
		        	resultSet = preparedStatement.executeQuery();
		        	
		        	while(resultSet.next())
		        	{
		        		custMobile = resultSet.getString(1);
		        		custAddress = resultSet.getString(2);
		        	}
		        	
		        	
		        	PDDocument document = new PDDocument(); 
					PDPage page = null;
					
					int productListSize = this.getProductInfoList().size();
					
					
						page = new PDPage(new PDRectangle(420.9449f,595.2756f));
					
					 
					 document.addPage(page);
					 
						
						
					 File fontFile  =  new File( request.getSession().getServletContext().getRealPath("/fonts/Nirmala.ttf"));
					 File fontFileBold  =  new File( request.getSession().getServletContext().getRealPath("/fonts/nirmala-bold.ttf"));
					 
					 TrueTypeFont ttf1 = new TTFParser().parse(fontFile);
					 PDFont fontMarathi = PDType0Font.load(document, ttf1, true);
					 
					 TrueTypeFont ttf2 = new TTFParser().parse(fontFileBold);
					 PDFont fontMarathiBold = PDType0Font.load(document, ttf2, true);
					 
			         PDPageContentStream contentStream = new PDPageContentStream(document, page);
			         
			         
			         
			         PDImageXObject pdImageQRCode = null;
			         PDImageXObject pdImageLeftLogoImage = null;
			         PDImageXObject pdImageRightLogoImage = null;
			         Blob leftLogoImageBlob = null;
			         Blob rightLogoImageBlob = null;
			         InputStream leftLogoIS = null;
			         InputStream rightLogoIS = null;
			        		 
					 Blob blob = (Blob) this.getSessionMap().get("qr_image_bolb");
					 
					 //headintroline
					 
				
					 String headIntroLineContent = (String)this.getSessionMap().get("headintroline");
					 
					 if(shopSettingsMap.get("add_left_side_logo").equals("TRUE"))
					 {
						
							
							 byte[] leftLogoBytes =(byte[]) this.getSessionMap().get("left_logo_image_array");
							 pdImageLeftLogoImage = PDImageXObject.createFromByteArray(document, leftLogoBytes, "leftLogo");
						 
						
					 }
					 if(shopSettingsMap.get("add_right_side_logo").equals("TRUE"))
					 {

						 byte[] rightLogoBytes =(byte[]) this.getSessionMap().get("right_logo_image_array");
						 pdImageRightLogoImage = PDImageXObject.createFromByteArray(document, rightLogoBytes, "rightLogo");
					 }
					 
					 if(blob != null)
					 {
					 InputStream in = blob.getBinaryStream();
					 File qrFile = new File(path+"/"+shopId+"qr.jpeg");
					 FileOutputStream out = new FileOutputStream(qrFile);
					 byte[] buffer = new byte[1024];
					    int read;
					    while ((read = in.read(buffer)) != -1) {
					        out.write(buffer, 0, read);
					    }
					    
					    in.close();
					    out.close();
					    pdImageQRCode = PDImageXObject.createFromFile(path+"/"+shopId+"qr.jpeg", document);
					 }
	         
					 
					
	         Table header;
	         Table billInfoTable;
	         Table custInfoTable;
	         Table itemInfo;
	         
	         
	         TableBuilder tableHeaderBuilder = Table.builder()
		                .addColumnsOfWidth(380)				                
		                .font(HELVETICA)
		                .borderColor(Color.BLACK)
		                .horizontalAlignment(CENTER);
	         
	         Row billType = Row.builder()
		                .add(TextCell.builder().text("ESTIMATE").fontSize(10).horizontalAlignment(CENTER).borderWidthTop(0.0F).borderWidthLeft(0.0F).borderWidthRight(0.0F).borderWidthBottom(0.5F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         Row headerRow  = Row.builder()
		                .add(TextCell.builder().text(this.getHeaderShopName()).fontSize(20).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         Row addressRow  = Row.builder()
		                .add(TextCell.builder().text((String)this.getSessionMap().get("shoponelineaddress")).fontSize(9).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         Row mobileRow  = Row.builder()
		                .add(TextCell.builder().text("Contact: "+(String)this.getSessionMap().get("shopcustcarenumber")).fontSize(9).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         
	         
	         
	         tableHeaderBuilder.addRow(billType);
	         
	         tableHeaderBuilder.addRow(headerRow);
	         if(addIntroLine.equals("TRUE"))
	         {
	        	 Row headerIntroRow  = Row.builder()
			                .add(TextCell.builder().text(headIntroLineContent).fontSize(9).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
			                .backgroundColor(WHITE)
			                .font(PDType1Font.HELVETICA_BOLD)	
			                .textColor(Color.BLACK)
			                .build();
	        	 
	        	 tableHeaderBuilder.addRow(headerIntroRow);
	        	 
	         }
	         tableHeaderBuilder.addRow(addressRow);
	         tableHeaderBuilder.addRow(mobileRow);
	         
	       
	         
	         header = tableHeaderBuilder.build();
	         
	         float startY = page.getMediaBox().getHeight() - PADDING20;
	         
	         if(addPageHeader)
	         {
		         TableDrawer.builder()
	                .contentStream(contentStream)
	                .table(header)
	                .startX(PADDING20)
	                .startY(startY)
	                .build()
	                .draw();
	         }
	         
	         TableBuilder tableBillInfoBuilder = Table.builder()
		                .addColumnsOfWidth(30,30,40,60)				                
		                .font(HELVETICA)
		                .borderColor(Color.BLACK)
		                .horizontalAlignment(CENTER);
	         
	         
	         Row billInfoRow1  = Row.builder()
		                .add(TextCell.builder().text("Bill No:"+this.getBillNumber()).colSpan(2).fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text("Billed By").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text(this.getBillInfoDAO().getBilledBy()).fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         
	         Row billInfoRow2  = Row.builder()
	        		 	.add(TextCell.builder().text("Date:"+this.getBillInfoDAO().getBillDate()).colSpan(4).fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	        		 	.backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();

	         Row billInfoRow3  = Row.builder()
		                .add(TextCell.builder().text("Payment Type").colSpan(3).fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text(this.getBillInfoDAO().getPaymentType()).fontSize(7).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
					    .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         tableBillInfoBuilder.addRow(billInfoRow1);
	         tableBillInfoBuilder.addRow(billInfoRow2);
	         tableBillInfoBuilder.addRow(billInfoRow3);
	         
	         billInfoTable = tableBillInfoBuilder.build();
	         
	         
	         float currentY = startY - 70;
	         
	         if(addIntroLine.equals("TRUE"))
	         {
	        	 currentY = startY - 90; 
	         }
	          
	      	 if(!addPageHeader)
        	 {
	      		currentY = startY - 140;
        	 }
 	         
	         
	         TableDrawer.builder()
             .contentStream(contentStream)
             .table(billInfoTable)
             .startX(240)
             .startY(currentY)
             .build()
             .draw();
	         
	         
	         TableBuilder tableCustInfoBuilder = Table.builder()
		                .addColumnsOfWidth(220);
	         
	         Row custInfoRow1 = Row.builder()
		                .add(TextCell.builder().text("Customer Name : "+this.getBillInfoDAO().getCustomerName()).fontSize(8).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthTop(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         Row custInfoRow2 = Row.builder()
		                .add(TextCell.builder().text("Mobile : "+custMobile).fontSize(8).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         Row custInfoRow3 = Row.builder()
		                .add(TextCell.builder().text("Address : "+custAddress).fontSize(8).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	    
	         
	         tableCustInfoBuilder.addRow(custInfoRow1);
	         tableCustInfoBuilder.addRow(custInfoRow2);
	         tableCustInfoBuilder.addRow(custInfoRow3);
	         
	         custInfoTable = tableCustInfoBuilder.build();
	         

	         
	         
	         TableDrawer.builder()
             .contentStream(contentStream)
             .table(custInfoTable)
             .startX(PADDING20)
             .startY(currentY)
             .build()
             .draw();
	         
	         TableBuilder tableItemInfoBuilder ;
	         
	         Row inteInfoHeaderRow;
	         
	         if(addMakingLaborColumn.equals("FALSE"))
	         {
	        	 if(addDiscountColumn)
	        	 {
			        	 tableItemInfoBuilder =  Table.builder()
		        		 .addColumnsOfWidth(25,155,45,45,45,65);
			        	 
			        	 inteInfoHeaderRow = Row.builder()
				                .add(TextCell.builder().text("Sr No").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
				                .add(TextCell.builder().text("Items").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
				                .add(TextCell.builder().text("Rate").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
				                .add(TextCell.builder().text("Quantity").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
				                .add(TextCell.builder().text("Discount").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
					            .add(TextCell.builder().text("Amount").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
				                .backgroundColor(GRAY_LIGHT_3)
				                .font(PDType1Font.HELVETICA_BOLD)	
				                .textColor(Color.BLACK)
				                .build();
			         
			         tableItemInfoBuilder.addRow(inteInfoHeaderRow);
	        	 }
	        	 else
	        	 {
	        		
	        			 tableItemInfoBuilder =  Table.builder()
				        		 .addColumnsOfWidth(25,165,55,55,80);
					        	 
					        	 inteInfoHeaderRow = Row.builder()
						                .add(TextCell.builder().text("Sr No").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
						                .add(TextCell.builder().text("Items").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
						                .add(TextCell.builder().text("Rate").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
						                .add(TextCell.builder().text("Quantity").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
							            .add(TextCell.builder().text("Amount").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
						                .backgroundColor(GRAY_LIGHT_3)
						                .font(PDType1Font.HELVETICA_BOLD)	
						                .textColor(Color.BLACK)
						                .build();
					         
					         tableItemInfoBuilder.addRow(inteInfoHeaderRow); 
		        	
	        	 }
	         
	         }
	         else
	         {
	        	 if(addDiscountColumn)
	        	 {
	        		 tableItemInfoBuilder =  Table.builder()
		            		 .addColumnsOfWidth(25,120,45,45,45,45,55);
		    	        	 
		    	        	 inteInfoHeaderRow = Row.builder()
		    		                .add(TextCell.builder().text("Sr No").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    		                .add(TextCell.builder().text("Items").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    		                .add(TextCell.builder().text("Rate").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    		                .add(TextCell.builder().text("Quantity").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    		                .add(TextCell.builder().text("Making / Labor Charges").fontSize(5).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    		                .add(TextCell.builder().text("Discount").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    		                .add(TextCell.builder().text("Amount").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    		                .backgroundColor(GRAY_LIGHT_3)
		    		                .font(PDType1Font.HELVETICA_BOLD)	
		    		                .textColor(Color.BLACK)
		    		                .build();
		    	         
		    	         tableItemInfoBuilder.addRow(inteInfoHeaderRow);
	        	 }
	        	 else
	        	 {
	        	 tableItemInfoBuilder =  Table.builder()
	            		 .addColumnsOfWidth(25,135,55,55,55,55);
	    	        	 
	    	        	 inteInfoHeaderRow = Row.builder()
	    		                .add(TextCell.builder().text("Sr No").fontSize(7).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .add(TextCell.builder().text("Items").fontSize(7).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .add(TextCell.builder().text("Rate").fontSize(7).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .add(TextCell.builder().text("Quantity").fontSize(7).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .add(TextCell.builder().text("Making / Labor Charges").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    			        .add(TextCell.builder().text("Amount").fontSize(7).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .backgroundColor(GRAY_LIGHT_3)
	    		                .font(PDType1Font.HELVETICA_BOLD)	
	    		                .textColor(Color.BLACK)
	    		                .build();
	    	         
	    	         tableItemInfoBuilder.addRow(inteInfoHeaderRow);
	        	 }
	         }

	         int srNo = 1;
	         int pageCount = 1;
	         
	         int listCount = this.getProductInfoList().size();
	         
	         if(listCount <= 13)
	         {
	        	 listCount = 13;
	         }
	         
	     	for(int i =0;i<listCount;i++)
				{
	     		
	     		//System.out.println("Starting Current Y :"+currentY);
					Row itemDetails = null;
					
					if(currentY  < 120)
					{
						int colSpan = 5;
						 if(addDiscountColumn)
			        	 {
							 colSpan = 6;
			        	 }
						
						Row toBeContinue =  Row.builder()
			        		 	.add(TextCell.builder().text("Page No."+pageCount+", To be continued on next page...").colSpan(colSpan).fontSize(9).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
			        		 	.textColor(Color.BLACK)
				                .height(20F)
				                .font(fontMarathi)
				                .build();
						pageCount++;
						
						tableItemInfoBuilder.addRow(toBeContinue);
					
						itemInfo = tableItemInfoBuilder.build();
						
						float startY2 = page.getMediaBox().getHeight() - PADDING20;
						
			        	float currentY2 = startY2 - 110 ; 
			        	
			        	if(pageCount > 1)
			        	{
			        		currentY2 = startY2 - 120 ; 
			        	}
			        	
			        	 if(addIntroLine.equals("TRUE"))
			 	         {
			 	        	 currentY = startY - 120; 
			 	         }
			        	 
			        	 if(!addPageHeader)
			        	 {
			        		 currentY2 = startY2 - 210;  
			        	 }
			        	 
			        	 if(addPageHeader)
				         {
				         
					         
					         if(pdImageLeftLogoImage != null)
				        	 {
					        	
				        		 contentStream.drawImage(pdImageLeftLogoImage, 30, 515 , 35, 35);
				        		
				        	 }
				
					         if(pdImageRightLogoImage != null)
				        	 {
					        	
				        		 contentStream.drawImage(pdImageRightLogoImage, 425, 435 , 35, 35);
				        		
				        	 }
				         }
						 
			 	         
			        	
						
						 TableDrawer.builder()
			             .contentStream(contentStream)
			             .table(itemInfo)
			             .startX(PADDING20)
			             .startY(currentY2)
			             .build()
			             .draw();
						
						 contentStream.close();
						 contentStream = null;
				        	PDPage newPage = new PDPage(new PDRectangle(420.9449f,595.2756f));
							
				        	 
				        	 contentStream = new PDPageContentStream(document,newPage);
				        	currentY = 20.0F;
				             document.addPage( newPage );
				             
					          startY = newPage.getMediaBox().getHeight() - PADDING20;
				             TableDrawer.builder()
				                .contentStream(contentStream)
				                .table(header)
				                .startX(PADDING20)
				                .startY(startY)
				                .build()
				                .draw();
				             
				             
					         currentY = startY - 70;
					         
					         if(addIntroLine.equals("TRUE"))
				 	         {
				 	        	 currentY = startY - 80; 
				 	         }
					         
					         
				        	 TableDrawer.builder()
				             .contentStream(contentStream)
				             .table(custInfoTable)
				             .startX(PADDING20)
				             .startY(currentY)
				             .build()
				             .draw();
				        	 
					         TableDrawer.builder()
				             .contentStream(contentStream)
				             .table(billInfoTable)
				             .startX(240)
				             .startY(currentY)
				             .build()
				             .draw();
					         
					         currentY = currentY - 50;
					         if(addIntroLine.equals("TRUE"))
				 	         {
				 	        	 currentY = currentY - 40; 
				 	         }
					       
					         itemInfo = null;
					         tableItemInfoBuilder = null;
					         if(addMakingLaborColumn.equals("FALSE"))
					         {
					        	 if(addDiscountColumn)
					        	 {
					        		 tableItemInfoBuilder = Table.builder()
					        				 .addColumnsOfWidth(25,155,45,45,45,65);
					        	 }
					        	 else
					        	 {
					        		 tableItemInfoBuilder = Table.builder()
					        				 .addColumnsOfWidth(25,165,55,55,80);
						        	 
					        	 }
					         }else
					         {
					        	 if(addDiscountColumn)
					        	 {
					        		 tableItemInfoBuilder =  Table.builder()
					        				 .addColumnsOfWidth(25,120,45,45,45,45,55);
					        	 }
					        	 else
					        	 {
					        		 tableItemInfoBuilder =  Table.builder()
					        				 .addColumnsOfWidth(25,135,55,55,55,55);
				    	        	 
					        	 }
					        	 
					         }
					       
					         
					         tableItemInfoBuilder.addRow(inteInfoHeaderRow);
					}
					
					
						BillProductInfoDAO informationDAO = null;
						
						try						
						{
							informationDAO = this.getProductInfoList().get(i);
						}catch (Exception e) {}
						if(informationDAO != null)
						{
						
							 if(addMakingLaborColumn.equals("FALSE"))
					         {
								
								 if(addDiscountColumn)
					        	 {
									 itemDetails = Row.builder()
							        		 	.add(TextCell.builder().text(""+srNo).fontSize(9).horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())				               
							        		 	.add(TextCell.builder().text(informationDAO.getProductName()).fontSize(8).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
								                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
								                .add(TextCell.builder().text(""+informationDAO.getQuantity()+" "+informationDAO.getSalesUnitShortName()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
								                .add(TextCell.builder().text(""+informationDAO.getDiscountRupees()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
										        .add(TextCell.builder().text(""+informationDAO.getAmountAfterDiscount()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
										        .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .height(20F)
								                .font(fontMarathi).fontSize(9)				              
								                .horizontalAlignment(CENTER)
								                .build();
							         srNo++;
							         
							         totalDiscountAmt = totalDiscountAmt + informationDAO.getDiscountRupees();
					        	 }
								 else
								 {
						         itemDetails = Row.builder()
						        		 	.add(TextCell.builder().text(""+srNo).fontSize(9).horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())				               
						        		 	.add(TextCell.builder().text(informationDAO.getProductName()).fontSize(8).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getQuantity()+" "+informationDAO.getSalesUnitShortName()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
								            .add(TextCell.builder().text(""+informationDAO.getAmountAfterDiscount()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
									        .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .height(20F)
							                .font(fontMarathi).fontSize(9)				              
							                .horizontalAlignment(CENTER)
							                .build();
						         srNo++;
								 }
					         }
							 else
							 {
								 itemDetails = Row.builder()
						        		 	.add(TextCell.builder().text(""+srNo).fontSize(9).horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())				               
						        		 	.add(TextCell.builder().text(informationDAO.getProductName()).fontSize(8).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getQuantity()+" "+informationDAO.getSalesUnitShortName()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getMakingLaborCharge()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getAmountAfterDiscount()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
									        .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .height(20F)
							                .font(fontMarathi).fontSize(9)				              
							                .horizontalAlignment(CENTER)
							                .build();
						         srNo++;
							 }
						}
						else
						{
							 if(addMakingLaborColumn.equals("FALSE"))
					         {
								 
								 if(addDiscountColumn)
					        	 {
									 itemDetails = Row.builder()
							        		 	.add(TextCell.builder().text("").fontSize(9).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							        		 	.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							        			.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							        			.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
										     	.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
									            .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
										        .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .height(20F)
								                .font(fontMarathi).fontSize(9)				              
								                .horizontalAlignment(CENTER)
								                .build();
									 
									 
					        	 }
								 else
								 {
						         itemDetails = Row.builder()
						        		 	.add(TextCell.builder().text("").fontSize(9).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
						        		 	.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
						        			.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
								     	    .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
								            .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
									        .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .height(20F)
							                .font(fontMarathi).fontSize(9)				              
							                .horizontalAlignment(CENTER)
							                .build();
								 }
					         }else
					         {
					        	 if(addDiscountColumn)
					        	 {
					        		 itemDetails = Row.builder()
							        		 	.add(TextCell.builder().text("").fontSize(9).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							        		 	.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							        			.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
									     	    .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
									     	    .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
										     	.add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
										        .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
										        .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .height(20F)
								                .font(fontMarathi).fontSize(9)				              
								                .horizontalAlignment(CENTER)
								                .build();
					        	 }
					        	 else
					        	 {
					        		 
					        	 
						        	 itemDetails = Row.builder()
							        		 	.add(TextCell.builder().text("").fontSize(9).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							        		 	.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							        			.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
									     	    .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
									     	    .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
										        .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
										        .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .height(20F)
								                .font(fontMarathi).fontSize(9)				              
								                .horizontalAlignment(CENTER)
								                .build();
					        	 }
					         }
						}
					
			         tableItemInfoBuilder.addRow(itemDetails);
			        
			         currentY = (float) (currentY - 20.0F);
					//System.out.println("Inner : "+currentY);
					
				}
				DecimalFormat df2 = new DecimalFormat("#.#");
	     	
			if(addCustomerCreditAmountToBill)
	         {
	     		float custCreditAmount = GetCustomerCreditAmountById.getCustomerCreditAmountById(this.getBillInfoDAO().getCustId(), this.getSessionMap());
	        	int colSpanCount = 2;
	     		if(addMakingLaborColumn.equals("TRUE"))
		         {
	     			colSpanCount = 3;
		         }
	     		
	     		
	     		if(addDiscountColumn && addMakingLaborColumn.equals("TRUE"))
	        	 {
	     			colSpanCount = 4;
	        	 }
	     		
	     		if(addDiscountColumn)
	     		{
	     			colSpanCount = 3;
	     		}
	     		
				Row totalInfoRow = Row.builder()
							.add(TextCell.builder().text("Total OutStanding Amount: Rs. "+df2.format(custCreditAmount)).colSpan(2).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(0.5F).build())				                
			             	.add(TextCell.builder().text("Total Bill Amount (in Rs.)").colSpan(colSpanCount).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
		        		 	.add(TextCell.builder().text(df2.format(floatTotalAmtAfterDiscount)).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
		        		 	.backgroundColor(WHITE)
			                .textColor(Color.BLACK)
			                .height(20F)
			                .font(fontMarathiBold).fontSize(8)				              
			                .horizontalAlignment(CENTER)
			                .build();
				tableItemInfoBuilder.addRow(totalInfoRow);
				
	         }
	     	 else
	     	 {
	     		int colSpanCount = 4;
	     		int colSpanAddTotalDisc = 3;
	     		
	     		if(addMakingLaborColumn.equals("TRUE"))
		         {
	     			colSpanCount = 5;
	     			colSpanAddTotalDisc = 4;
		         }
	     		
	     		if(addDiscountColumn && addMakingLaborColumn.equals("TRUE"))
	        	 {
	     			colSpanCount = 6;
	     			colSpanAddTotalDisc = 5;
	        	 }
	     		
	     		if(addDiscountColumn)
	     		{
	     			colSpanCount = 5;
	     			colSpanAddTotalDisc = 4;
	     		}
	     		
	     		
	     		Row totalMoneySavedInfoRow = Row.builder()
	        		 	.add(TextCell.builder().text("Total Savings:").colSpan(colSpanAddTotalDisc).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
	        		 	.add(TextCell.builder().text(df2.format(totalDiscountAmt)).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
	        			.add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
		        		 .backgroundColor(WHITE)
		                .textColor(Color.BLACK)
		                .height(20F)
		                .font(fontMarathiBold).fontSize(9)				              
		                .horizontalAlignment(CENTER)
		                .build();
	     			tableItemInfoBuilder.addRow(totalMoneySavedInfoRow);
	     			
	     		Row totalInfoRow = Row.builder()
	        		 	.add(TextCell.builder().text("Total Bill Amount(in Rs.)").colSpan(colSpanCount).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
	        		 	.add(TextCell.builder().text(df2.format(floatTotalAmtAfterDiscount)).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
	        		 	.backgroundColor(WHITE)
		                .textColor(Color.BLACK)
		                .height(20F)
		                .font(fontMarathiBold).fontSize(9)				              
		                .horizontalAlignment(CENTER)
		                .build();
	     			tableItemInfoBuilder.addRow(totalInfoRow);
	     	 }
				
				 
	     	int colSpanCountBottom = 5;
     		if(addMakingLaborColumn.equals("TRUE"))
	         {
     			colSpanCountBottom = 6;
	         }
     		
     		
     		if(addDiscountColumn && addMakingLaborColumn.equals("TRUE"))
	       	 {
	     			colSpanCountBottom = 7;
	       	 }
    		
    		if(addDiscountColumn)
    		{
    			colSpanCountBottom = 6;
    		}
				
				  String convertedAmount = new NumberToWordsConverter().getConverted(""+floatTotalAmtAfterDiscount);
		      
				  Row amtInwordsRow = Row.builder()
		        		 	.add(TextCell.builder().text("Amount in Words : "+convertedAmount).colSpan(colSpanCountBottom).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
		        		 	.backgroundColor(WHITE)
			                .textColor(Color.BLACK)
			                .height(20F)
			                .font(fontMarathi).fontSize(8)				              
			                .horizontalAlignment(CENTER)
			                .build();
				tableItemInfoBuilder.addRow(amtInwordsRow);
				String comm = this.getBillInfoDAO().getComments();
				
				if(comm == null)
				{
					comm = "";
				}
				Row commentsRow = Row.builder()
	        		 	.add(TextCell.builder().text("Comments:"+comm).colSpan(colSpanCountBottom).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
	        		 	.backgroundColor(WHITE)
		                .textColor(Color.BLACK)
		                .height(15F)
		                .font(fontMarathi).fontSize(8)				              
		                .horizontalAlignment(LEFT)
		                .build();
				tableItemInfoBuilder.addRow(commentsRow);
	         
	         itemInfo = tableItemInfoBuilder.build();
	         
	         
	         TableBuilder signatureBuiler = Table.builder()
		                .addColumnsOfWidth(145,90,145)				                
		                .font(HELVETICA)
		                .borderColor(Color.BLACK)
		                .horizontalAlignment(CENTER);
	         
	         Row signRow1 = Row.builder()
	        		 	.add(TextCell.builder().text("").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())
		                .add(TextCell.builder().text("").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())
		                .add(TextCell.builder().text("For "+this.getHeaderShopName()).verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())
		                .backgroundColor(Color.WHITE)
		                .textColor(Color.BLACK)
		                .font(PDType1Font.HELVETICA_BOLD)
		                .fontSize(9)				              
		                .horizontalAlignment(CENTER)
		                .height(20F)	
		                .build();
	         signatureBuiler.addRow(signRow1);
	         
	         Row signRow2 = Row.builder()
	        		 	.add(TextCell.builder().text("").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.0F).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(1F).build())
		                .add(TextCell.builder().text("Customer Signature").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.0F).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(1F).build())
		                .add(TextCell.builder().text("Authorized Signature").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.0F).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(1F).build())					               
		                .backgroundColor(Color.WHITE)
		                .textColor(Color.BLACK)
		                .font(PDType1Font.HELVETICA_BOLD)
		                .fontSize(9)				              
		                .horizontalAlignment(CENTER)
		                .height(50F)	
		                .build();
	         signatureBuiler.addRow(signRow2);
	       
	         
	         Table signature = signatureBuiler.build();   
	         
	      
	         itemInfo = tableItemInfoBuilder.build();
	         
        	float startY2 = page.getMediaBox().getHeight() - PADDING20;
        	float currentY2 = startY2 - 120 ; 
        	
        	
        	if(addIntroLine.equals("TRUE"))
 	         {
        		currentY2 = startY2 - 140; 
 	         }
        	
        	if(!addPageHeader)
        	{
        		currentY2 = startY2 - 185; 
        	}
        	 
      	 TableDrawer.builder()
             .contentStream(contentStream)
             .table(itemInfo)
             .startX(PADDING20)
             .startY(currentY2)
             .build()
             .draw();
			
	        
	     
	         if(pageCount == 1)
	         {
		         TableDrawer.builder()
	             .contentStream(contentStream)
	             .table(signature)
	             .startX(PADDING20)
	             .startY(currentY-130)
	             .build()
	             .draw();
	         }else
	         {
	        	 TableDrawer.builder()
	             .contentStream(contentStream)
	             .table(signature)
	             .startX(PADDING20)
	             .startY(currentY-95)
	             .build()
	             .draw();
	        	 
	         }
	         
	         if(addPageHeader)
	         {
	         
		         
		         if(pdImageLeftLogoImage != null)
	        	 {
		        	
	        		 contentStream.drawImage(pdImageLeftLogoImage, 30, 515 , 35, 35);
	        		
	        	 }
	
		         if(pdImageRightLogoImage != null)
	        	 {
		        	
	        		 contentStream.drawImage(pdImageRightLogoImage, 425, 435 , 35, 35);
	        		
	        	 }
	         }
			 
	         	contentStream.close();
			 	document.save(path+"/bill.pdf");
		        document.close();
		        
		        

				response.setHeader("Content-disposition", "inline; filename=bill.pdf");
				response.setContentType("application/pdf");
				FileInputStream fileInputStream = new FileInputStream(path+"/bill.pdf");
				PrintWriter out = response.getWriter();  
				int bytes;
				while ((bytes = fileInputStream.read()) != -1) {
					out.write(bytes);
				}
				fileInputStream.close();
				out.flush();
				out.close();
				ttf1.close();
				ttf2.close();
			
	         
	        
				
		        
		        }
		        
		        
		        
		        
		        if((this.getBillInfoDAO().getBillType().equals("QUOTATION") || this.getBillInfoDAO().getBillType().equals("ESTIMATE")) && this.getLanguage().equals("ENGLISH") && this.getBillType().equals("A5"))
				{
		        	
		        	
		        	String custMobile = "";
		        	String custAddress = "";
		        	
		        	if(resultSet != null)
		        	{
		        		resultSet.close();
		        		resultSet = null;
		        	}
		        	
		        	if(preparedStatement != null)
		        	{
		        		preparedStatement.close();
		        		preparedStatement = null;
		        	}
		        	
		        	
		        	sql = "SELECT "
		        			+ "mobile_number,"
		        			+ "billing_address "
		        			+ "FROM "
		        			+ "shop_customer_master "
		        			+ "WHERE "
		        			+ "customer_name = ? "
		        			+ "AND "
		        			+ "customer_id = ? "
		        			+ "AND "
		        			+ "shop_id = ? "
		        			+ "AND "
		        			+ "shop_code = ?";
		        	
		        	preparedStatement = connection.prepareStatement(sql);
		        	preparedStatement.setString(1, this.getBillInfoDAO().getCustomerName());
		        	preparedStatement.setString(2, this.getBillInfoDAO().getCustId());
		        	preparedStatement.setString(3, shopId);
		        	preparedStatement.setString(4, shopCode);
		        	
		        	resultSet = preparedStatement.executeQuery();
		        	
		        	while(resultSet.next())
		        	{
		        		custMobile = resultSet.getString(1);
		        		custAddress = resultSet.getString(2);
		        	}
		        	
		        	
		        	PDDocument document = new PDDocument(); 
					PDPage page = null;
					
					int productListSize = this.getProductInfoList().size();
					
					
					if(productListSize>5)
					{
						page = new PDPage(PDRectangle.A4);
					}
					else
					{
						page = new PDPage(new PDRectangle(595.2756f,420.9449f));
					}
					 
					 document.addPage(page);
					 
						
						
					 File fontFile  =  new File( request.getSession().getServletContext().getRealPath("/fonts/Nirmala.ttf"));
					 File fontFileBold  =  new File( request.getSession().getServletContext().getRealPath("/fonts/nirmala-bold.ttf"));
					 
					 TrueTypeFont ttf1 = new TTFParser().parse(fontFile);
					 PDFont fontMarathi = PDType0Font.load(document, ttf1, true);
					 
					 TrueTypeFont ttf2 = new TTFParser().parse(fontFileBold);
					 PDFont fontMarathiBold = PDType0Font.load(document, ttf2, true);
					 
			         PDPageContentStream contentStream = new PDPageContentStream(document, page);
			         
			         
			         
			         PDImageXObject pdImageQRCode = null;
			         PDImageXObject pdImageLeftLogoImage = null;
			         PDImageXObject pdImageRightLogoImage = null;
			         Blob leftLogoImageBlob = null;
			         Blob rightLogoImageBlob = null;
			         InputStream leftLogoIS = null;
			         InputStream rightLogoIS = null;
			        		 
					 Blob blob = (Blob) this.getSessionMap().get("qr_image_bolb");
					 
					 //headintroline
					 
				
					 String headIntroLineContent = (String)this.getSessionMap().get("headintroline");
					 if(shopSettingsMap.get("add_left_side_logo").equals("TRUE"))
					 {
						
							
							 byte[] leftLogoBytes =(byte[]) this.getSessionMap().get("left_logo_image_array");
							 pdImageLeftLogoImage = PDImageXObject.createFromByteArray(document, leftLogoBytes, "leftLogo");
						 
						
					 }
					 if(shopSettingsMap.get("add_right_side_logo").equals("TRUE"))
					 {

						 byte[] rightLogoBytes =(byte[]) this.getSessionMap().get("right_logo_image_array");
						 pdImageRightLogoImage = PDImageXObject.createFromByteArray(document, rightLogoBytes, "rightLogo");
					 }
					 
					 if(blob != null)
					 {
					 InputStream in = blob.getBinaryStream();
					 File qrFile = new File(path+"/"+shopId+"qr.jpeg");
					 FileOutputStream out = new FileOutputStream(qrFile);
					 byte[] buffer = new byte[1024];
					    int read;
					    while ((read = in.read(buffer)) != -1) {
					        out.write(buffer, 0, read);
					    }
					    
					    in.close();
					    out.close();
					    pdImageQRCode = PDImageXObject.createFromFile(path+"/"+shopId+"qr.jpeg", document);
					 }
	         
					 
					
	         Table header;
	         Table billInfoTable;
	         Table custInfoTable;
	         Table itemInfo;
	         
	         
	         TableBuilder tableHeaderBuilder = Table.builder()
		                .addColumnsOfWidth(560)				                
		                .font(HELVETICA)
		                .borderColor(Color.BLACK)
		                .horizontalAlignment(CENTER);
	         
	         Row billType = Row.builder()
		                .add(TextCell.builder().text(this.getBillInfoDAO().getBillType()).fontSize(10).horizontalAlignment(CENTER).borderWidthTop(0.0F).borderWidthLeft(0.0F).borderWidthRight(0.0F).borderWidthBottom(0.5F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         Row headerRow  = Row.builder()
		                .add(TextCell.builder().text(this.getHeaderShopName()).fontSize(24).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         Row addressRow  = Row.builder()
		                .add(TextCell.builder().text((String)this.getSessionMap().get("shoponelineaddress")).fontSize(10).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         Row mobileRow  = Row.builder()
		                .add(TextCell.builder().text("Contact: "+(String)this.getSessionMap().get("shopcustcarenumber")).fontSize(10).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         
	         
	         
	         tableHeaderBuilder.addRow(billType);
	         
	         tableHeaderBuilder.addRow(headerRow);
	         if(addIntroLine.equals("TRUE"))
	         {
	        	 Row headerIntroRow  = Row.builder()
			                .add(TextCell.builder().text(headIntroLineContent).fontSize(10).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
			                .backgroundColor(WHITE)
			                .font(PDType1Font.HELVETICA_BOLD)	
			                .textColor(Color.BLACK)
			                .build();
	        	 
	        	 tableHeaderBuilder.addRow(headerIntroRow);
	        	 
	         }
	         tableHeaderBuilder.addRow(addressRow);
	         tableHeaderBuilder.addRow(mobileRow);
	         
	       
	         
	         header = tableHeaderBuilder.build();
	         
	         float startY = page.getMediaBox().getHeight() - PADDING20;
	         TableDrawer.builder()
                .contentStream(contentStream)
                .table(header)
                .startX(PADDING20)
                .startY(startY)
                .build()
                .draw();
	         
	         TableBuilder tableBillInfoBuilder = Table.builder()
		                .addColumnsOfWidth(50,50,60,80)				                
		                .font(HELVETICA)
		                .borderColor(Color.BLACK)
		                .horizontalAlignment(CENTER);
	         
	         
	         Row billInfoRow1  = Row.builder()
		                .add(TextCell.builder().text("Bill No:"+this.getBillNumber()).colSpan(2).fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text("Billed By").fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text(this.getBillInfoDAO().getBilledBy()).fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         
	         Row billInfoRow2  = Row.builder()
	        		 	.add(TextCell.builder().text("Date:"+this.getBillInfoDAO().getBillDate()).colSpan(4).fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	        		 	.backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();

	         Row billInfoRow3  = Row.builder()
		                .add(TextCell.builder().text("Payment Type").colSpan(2).fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text(this.getBillInfoDAO().getPaymentType()).colSpan(2).fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
					    .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         tableBillInfoBuilder.addRow(billInfoRow1);
	         tableBillInfoBuilder.addRow(billInfoRow2);
	         tableBillInfoBuilder.addRow(billInfoRow3);
	         
	         billInfoTable = tableBillInfoBuilder.build();
	         
	         
	         float currentY = startY - 70;
	         
	         if(addIntroLine.equals("TRUE"))
	         {
	        	 currentY = startY - 90; 
	         }
	         
	        
	         
	         TableDrawer.builder()
             .contentStream(contentStream)
             .table(billInfoTable)
             .startX(340)
             .startY(currentY)
             .build()
             .draw();
	         
	         
	         TableBuilder tableCustInfoBuilder = Table.builder()
		                .addColumnsOfWidth(320);
	         
	         Row custInfoRow1 = Row.builder()
		                .add(TextCell.builder().text("Customer Name : "+this.getBillInfoDAO().getCustomerName()).fontSize(10).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthTop(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         Row custInfoRow2 = Row.builder()
		                .add(TextCell.builder().text("Mobile : "+custMobile).fontSize(10).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         Row custInfoRow3 = Row.builder()
		                .add(TextCell.builder().text("Address : "+custAddress).fontSize(10).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				               
		                .backgroundColor(WHITE)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	    
	         
	         tableCustInfoBuilder.addRow(custInfoRow1);
	         tableCustInfoBuilder.addRow(custInfoRow2);
	         tableCustInfoBuilder.addRow(custInfoRow3);
	         
	         custInfoTable = tableCustInfoBuilder.build();
	         

	         
	         
	         TableDrawer.builder()
             .contentStream(contentStream)
             .table(custInfoTable)
             .startX(PADDING20)
             .startY(currentY)
             .build()
             .draw();
	         
	         TableBuilder tableItemInfoBuilder ;
	         
	         Row inteInfoHeaderRow;
	         
	         if(addMakingLaborColumn.equals("FALSE"))
	         {
	        	 tableItemInfoBuilder =  Table.builder()
        		 .addColumnsOfWidth(40,270,80,80,90);
	        	 
	        	 inteInfoHeaderRow = Row.builder()
		                .add(TextCell.builder().text("Sr No").fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text("Items").fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text("Rate").fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .add(TextCell.builder().text("Quantity").fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
			            .add(TextCell.builder().text("Amount").fontSize(10).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		                .backgroundColor(GRAY_LIGHT_3)
		                .font(PDType1Font.HELVETICA_BOLD)	
		                .textColor(Color.BLACK)
		                .build();
	         
	         tableItemInfoBuilder.addRow(inteInfoHeaderRow);
	         
	         }
	         else
	         {
	        	 tableItemInfoBuilder =  Table.builder()
	            		 .addColumnsOfWidth(35,175,60,70,65,80,75);
	    	        	 
	    	        	 inteInfoHeaderRow = Row.builder()
	    		                .add(TextCell.builder().text("Sr No").fontSize(9).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .add(TextCell.builder().text("Items").fontSize(9).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .add(TextCell.builder().text("Rate").fontSize(9).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .add(TextCell.builder().text("Quantity").fontSize(9).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .add(TextCell.builder().text("Item Amount").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
			    			    .add(TextCell.builder().text("Making / Labor Charges").fontSize(6).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
		    			        .add(TextCell.builder().text("Total Amount").fontSize(8).horizontalAlignment(LEFT).borderWidth(1.0F).lineSpacing(1F).build())				               
	    		                .backgroundColor(GRAY_LIGHT_3)
	    		                .font(PDType1Font.HELVETICA_BOLD)	
	    		                .textColor(Color.BLACK)
	    		                .build();
	    	         
	    	         tableItemInfoBuilder.addRow(inteInfoHeaderRow);
	         }

	         int srNo = 1;
	         int pageCount = 1;
	     	for(int i =0;i<listSize;i++)
				{
	     		
	     		//System.out.println("Starting Current Y :"+currentY);
					Row itemDetails = null;
					
					if(currentY  < 260)
					{
						
						Row toBeContinue =  Row.builder()
			        		 	.add(TextCell.builder().text("Page No."+pageCount+", To be continued on next page...").colSpan(5).fontSize(9).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
			        		 	.textColor(Color.BLACK)
				                .height(20F)
				                .font(fontMarathi)
				                .build();
						pageCount++;
						
						tableItemInfoBuilder.addRow(toBeContinue);
					
						itemInfo = tableItemInfoBuilder.build();
						
						float startY2 = page.getMediaBox().getHeight() - PADDING20;
			        	float currentY2 = startY2 - 120 ; 
			        	
			        	  if(addIntroLine.equals("TRUE"))
			 	         {
			 	        	 currentY = startY - 110; 
			 	         }
			 	         
						
						 TableDrawer.builder()
			             .contentStream(contentStream)
			             .table(itemInfo)
			             .startX(PADDING20)
			             .startY(currentY2)
			             .build()
			             .draw();
						
						 contentStream.close();
						 contentStream = null;
				        	PDPage newPage = new PDPage(PDRectangle.A4);
				        	 
				        	 contentStream = new PDPageContentStream(document,newPage);
				        	currentY = 20.0F;
				             document.addPage( newPage );
				             
					          startY = newPage.getMediaBox().getHeight() - PADDING20;
				             TableDrawer.builder()
				                .contentStream(contentStream)
				                .table(header)
				                .startX(PADDING20)
				                .startY(startY)
				                .build()
				                .draw();
				             
				             
					         currentY = startY - 80;
					         
					         if(addIntroLine.equals("TRUE"))
				 	         {
				 	        	 currentY = startY - 90; 
				 	         }
					         
					         TableDrawer.builder()
				             .contentStream(contentStream)
				             .table(billInfoTable)
				             .startX(PADDING20)
				             .startY(currentY)
				             .build()
				             .draw();
					         
					         currentY = currentY - 50;
					         if(addIntroLine.equals("TRUE"))
				 	         {
				 	        	 currentY = currentY - 40; 
				 	         }
					         
					         TableDrawer.builder()
				             .contentStream(contentStream)
				             .table(custInfoTable)
				             .startX(PADDING20)
				             .startY(currentY)
				             .build()
				             .draw();
					         
					         itemInfo = null;
					         tableItemInfoBuilder = null;
					         if(addMakingLaborColumn.equals("FALSE"))
					         {
					         tableItemInfoBuilder = Table.builder()
					        		 .addColumnsOfWidth(40,270,80,80,90);
					         }else
					         {
					        	 tableItemInfoBuilder =  Table.builder()
					        			 .addColumnsOfWidth(35,175,60,70,65,80,75);
					        	 
					         }
					       
					         
					         tableItemInfoBuilder.addRow(inteInfoHeaderRow);
					}
					
					
						BillProductInfoDAO informationDAO = this.getProductInfoList().get(i);
					
						if(informationDAO != null)
						{
						
							 if(addMakingLaborColumn.equals("FALSE"))
					         {
								
						         itemDetails = Row.builder()
						        		 	.add(TextCell.builder().text(""+srNo).fontSize(9).horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())				               
						        		 	.add(TextCell.builder().text(informationDAO.getProductName()).fontSize(8).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getQuantity()+" "+informationDAO.getSalesUnitShortName()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
								            .add(TextCell.builder().text(""+informationDAO.getAmountAfterDiscount()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
									        .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .height(20F)
							                .font(fontMarathi).fontSize(12)				              
							                .horizontalAlignment(CENTER)
							                .build();
						         srNo++;
					         }
							 else
							 {
								 itemDetails = Row.builder()
						        		 	.add(TextCell.builder().text(""+srNo).fontSize(9).horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())				               
						        		 	.add(TextCell.builder().text(informationDAO.getProductName()).fontSize(8).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getSalesRate()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getQuantity()+" "+informationDAO.getSalesUnitShortName()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+(informationDAO.getAmountAfterDiscount()-informationDAO.getMakingLaborCharge())).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
								            .add(TextCell.builder().text(""+informationDAO.getMakingLaborCharge()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
							                .add(TextCell.builder().text(""+informationDAO.getAmountAfterDiscount()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
									        .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .height(20F)
							                .font(fontMarathi).fontSize(12)				              
							                .horizontalAlignment(CENTER)
							                .build();
						         srNo++;
							 }
						}
						else
						{
							 if(addMakingLaborColumn.equals("FALSE"))
					         {
						         itemDetails = Row.builder()
						        		 	.add(TextCell.builder().text("").fontSize(9).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
						        		 	.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
						        			.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
								     	    .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
								            .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
									        .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .height(20F)
							                .font(fontMarathi).fontSize(12)				              
							                .horizontalAlignment(CENTER)
							                .build();
					         }else
					         {
					        	 itemDetails = Row.builder()
						        		 	.add(TextCell.builder().text("").fontSize(9).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
						        		 	.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
						        			.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
						        			.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
									     	.add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
								     	    .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
									        .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
									        .backgroundColor(WHITE)
							                .textColor(Color.BLACK)
							                .height(20F)
							                .font(fontMarathi).fontSize(12)				              
							                .horizontalAlignment(CENTER)
							                .build();
					         }
						}
					
			         tableItemInfoBuilder.addRow(itemDetails);
			        
			         currentY = (float) (currentY - 20.0F);
					//System.out.println("Inner : "+currentY);
					
				}
				DecimalFormat df2 = new DecimalFormat("#.#");
	     	 if(addCustomerCreditAmountToBill)
	         {
	     		float custCreditAmount = GetCustomerCreditAmountById.getCustomerCreditAmountById(this.getBillInfoDAO().getCustId(), this.getSessionMap());
	        	int colSpanCount = 2;
	     		if(addMakingLaborColumn.equals("TRUE"))
		         {
	     			colSpanCount = 4;
		         }
				Row totalInfoRow = Row.builder()
							.add(TextCell.builder().text("Total OutStanding Amount: Rs. "+df2.format(custCreditAmount)).colSpan(2).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(0.5F).build())				                
			             	.add(TextCell.builder().text("Total Bill Amount (in Rs.)").colSpan(colSpanCount).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
		        		 	.add(TextCell.builder().text(df2.format(floatTotalAmtAfterDiscount)).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
		        		 	.backgroundColor(WHITE)
			                .textColor(Color.BLACK)
			                .height(20F)
			                .font(fontMarathiBold).fontSize(10)				              
			                .horizontalAlignment(CENTER)
			                .build();
				tableItemInfoBuilder.addRow(totalInfoRow);
				
	         }
	     	 else
	     	 {
	     		int colSpanCount = 4;
	     		if(addMakingLaborColumn.equals("TRUE"))
		         {
	     			colSpanCount = 6;
		         }
	     		
	     		Row totalInfoRow = Row.builder()
	        		 	.add(TextCell.builder().text("Total Bill Amount(in Rs.)").colSpan(colSpanCount).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
	        		 	.add(TextCell.builder().text(df2.format(floatTotalAmtAfterDiscount)).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				               
	        		 	.backgroundColor(WHITE)
		                .textColor(Color.BLACK)
		                .height(20F)
		                .font(fontMarathiBold).fontSize(12)				              
		                .horizontalAlignment(CENTER)
		                .build();
	     			tableItemInfoBuilder.addRow(totalInfoRow);
	     	 }
				
				 
	     	int colSpanCountBottom = 5;
     		if(addMakingLaborColumn.equals("TRUE"))
	         {
     			colSpanCountBottom = 7;
	         }
				
				  String convertedAmount = new NumberToWordsConverter().getConverted(""+floatTotalAmtAfterDiscount);
		      
				  Row amtInwordsRow = Row.builder()
		        		 	.add(TextCell.builder().text("Amount in Words : "+convertedAmount).colSpan(colSpanCountBottom).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
		        		 	.backgroundColor(WHITE)
			                .textColor(Color.BLACK)
			                .height(20F)
			                .font(fontMarathi).fontSize(12)				              
			                .horizontalAlignment(CENTER)
			                .build();
				tableItemInfoBuilder.addRow(amtInwordsRow);
				String comm = this.getBillInfoDAO().getComments();
				
				if(comm == null)
				{
					comm = "";
				}
				Row commentsRow = Row.builder()
	        		 	.add(TextCell.builder().text("Comments:"+comm).colSpan(colSpanCountBottom).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				               
	        		 	.backgroundColor(WHITE)
		                .textColor(Color.BLACK)
		                .height(15F)
		                .font(fontMarathi).fontSize(9)				              
		                .horizontalAlignment(LEFT)
		                .build();
			tableItemInfoBuilder.addRow(commentsRow);
	         
	         itemInfo = tableItemInfoBuilder.build();
	         
	         
	         TableBuilder signatureBuiler = Table.builder()
		                .addColumnsOfWidth(245,135,180)				                
		                .font(HELVETICA)
		                .borderColor(Color.BLACK)
		                .horizontalAlignment(CENTER);
	         
	         Row signRow1 = Row.builder()
	        		 	.add(TextCell.builder().text("").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())
		                .add(TextCell.builder().text("").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())
		                .add(TextCell.builder().text("For "+this.getHeaderShopName()).verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.5F).borderWidthLeft(0.5F).borderWidthRight(0.5F).lineSpacing(0.5F).build())
		                .backgroundColor(Color.WHITE)
		                .textColor(Color.BLACK)
		                .font(PDType1Font.HELVETICA_BOLD)
		                .fontSize(9)				              
		                .horizontalAlignment(CENTER)
		                .height(20F)	
		                .build();
	         signatureBuiler.addRow(signRow1);
	         
	         Row signRow2 = Row.builder()
	        		 	.add(TextCell.builder().text("THANK YOU. VISIT AGAIN!").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.0F).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(10F).build())
		                .add(TextCell.builder().text("Customer Signature").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.0F).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(10F).build())
		                .add(TextCell.builder().text("Authorized Signature").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidthTop(0.0F).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthBottom(0.5F).lineSpacing(10F).build())					               
		                .backgroundColor(Color.WHITE)
		                .textColor(Color.BLACK)
		                .font(PDType1Font.HELVETICA_BOLD)
		                .fontSize(9)				              
		                .horizontalAlignment(CENTER)
		                .height(60F)	
		                .build();
	         signatureBuiler.addRow(signRow2);
	       
	         
	         Table signature = signatureBuiler.build();   
	         
	      
	         itemInfo = tableItemInfoBuilder.build();
	         
        	float startY2 = page.getMediaBox().getHeight() - PADDING20;
        	float currentY2 = startY2 - 120 ; 
        	
        	
        	if(addIntroLine.equals("TRUE"))
 	         {
        		currentY2 = startY2 - 140; 
 	         }
        	 
      	 TableDrawer.builder()
             .contentStream(contentStream)
             .table(itemInfo)
             .startX(PADDING20)
             .startY(currentY2)
             .build()
             .draw();
			
	        
	     
	         
	         TableDrawer.builder()
             .contentStream(contentStream)
             .table(signature)
             .startX(PADDING20)
             .startY(currentY-120)
             .build()
             .draw();
	         
	         
	       
	         
	         if(pdImageLeftLogoImage != null)
        	 {
	        	
        		 contentStream.drawImage(pdImageLeftLogoImage, 30, 335 , 45, 45);
        		
        	 }

	         if(pdImageRightLogoImage != null)
        	 {
	        	
        		 contentStream.drawImage(pdImageRightLogoImage, 525, 335 , 45, 45);
        		
        	 }
	       
			 
	         	contentStream.close();
			 	document.save(path+"/bill.pdf");
		        document.close();
		        
		        

				response.setHeader("Content-disposition", "inline; filename=bill.pdf");
				response.setContentType("application/pdf");
				FileInputStream fileInputStream = new FileInputStream(path+"/bill.pdf");
				PrintWriter out = response.getWriter();  
				int bytes;
				while ((bytes = fileInputStream.read()) != -1) {
					out.write(bytes);
				}
				fileInputStream.close();
				out.flush();
				out.close();
				ttf1.close();
				ttf2.close();
			
	         
	        
				}
		        
		        
		        String shopType = (String)this.getSessionMap().get("shoptype");
		        
		        
		         	if(this.getBillInfoDAO().getBillType().equals("TAX-INVOICE") && this.getLanguage().equals("ENGLISH") && this.getBillType().equals("A5") && shopType.equals("MEDICAL"))
					{

			        	
			        	 
			        	 String custMobile = "";
				         String custAddress = "";
				         String custGstNumber = "";
				         String custPANNumber = "";
				         
				        	if(resultSet != null)
				        	{
				        		resultSet.close();
				        		resultSet = null;
				        	}
				        	
				        	if(preparedStatement != null)
				        	{
				        		preparedStatement.close();
				        		preparedStatement = null;
				        	}
				        	
				        	
				        	sql = "SELECT "
				        			+ "mobile_number,"
				        			+ "billing_address,"
				        			+ "gst_number,"
				        			+ "pan_number "
				        			+ "FROM "
				        			+ "shop_customer_master "
				        			+ "WHERE "
				        			+ "customer_name = ? "
				        			+ "AND "
				        			+ "customer_id = ? "
				        			+ "AND "
				        			+ "shop_id = ? "
				        			+ "AND "
				        			+ "shop_code = ?";
				        	
				        	preparedStatement = connection.prepareStatement(sql);
				        	preparedStatement.setString(1, this.getBillInfoDAO().getCustomerName());
				        	preparedStatement.setString(2, this.getBillInfoDAO().getCustId());
				        	preparedStatement.setString(3, shopId);
				        	preparedStatement.setString(4, shopCode);
				        	
				        	resultSet = preparedStatement.executeQuery();
				        	
				        	while(resultSet.next())
				        	{
				        		custMobile = resultSet.getString(1);
				        		custAddress = resultSet.getString(2);
				        		custGstNumber = resultSet.getString(3);
				        		custPANNumber = resultSet.getString(4);
				        	}
			        		PDDocument document = new PDDocument(); 
							PDPage page = null;
							
							page = new PDPage(new PDRectangle(595.2756f,420.9449f));
						 
						 document.addPage(page);
						 
					 
				         PDPageContentStream contentStream = new PDPageContentStream(document, page);
				         
				         String gstNumber = (String)this.getSessionMap().get("shopgstnumber");
				         String panNumber = (String)this.getSessionMap().get("shoppannumber");
				         String declaration = (String)this.getSessionMap().get("shopdeclaration");
				  	
						 PDImageXObject pdImageLeftLogoImage = null;
				         PDImageXObject pdImageRightLogoImage = null;
				         
				        
				         if(shopSettingsMap.get("add_left_side_logo").equals("TRUE"))
						 {
							
								
								 byte[] leftLogoBytes =(byte[]) this.getSessionMap().get("left_logo_image_array");
								 pdImageLeftLogoImage = PDImageXObject.createFromByteArray(document, leftLogoBytes, "leftLogo");
							 
							
						 }
						 if(shopSettingsMap.get("add_right_side_logo").equals("TRUE"))
						 {

							 byte[] rightLogoBytes =(byte[]) this.getSessionMap().get("right_logo_image_array");
							 pdImageRightLogoImage = PDImageXObject.createFromByteArray(document, rightLogoBytes, "rightLogo");
						 }
					
						 Table header;
				         Table billNumberTable;
				         Table customerDetails;				      
				         Table productDetails;
				         Table totalAmountDetails;
				         Table bottomInfo;
				         Table signature;
				         
				         
				         
				         
				          TableBuilder tableHeaderBuilder = Table.builder()
					                .addColumnsOfWidth(80,340,150)				                
					                .font(HELVETICA)
					                .borderColor(Color.BLACK)
					                .horizontalAlignment(CENTER);
				 
				          	Row taxInvoice = Row.builder()
					                .add(TextCell.builder().text("CASH / CREDIT MEMO").colSpan(3).padding(2).horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(0.5F).build())				               
					                .backgroundColor(WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD).fontSize(8)				              
					                .horizontalAlignment(CENTER)
					                .height(10F)
					                .build();
				         
				          
					         Row row1  = Row.builder()
					        		 	.add(TextCell.builder().text("").rowSpan(5).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.5F).borderWidthBottom(0.5F).lineSpacing(1F).build())				               
					        		 	.add(TextCell.builder().text(this.getHeaderShopName()).fontSize(12).horizontalAlignment(CENTER).borderWidthLeft(0.0F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
					        			.add(TextCell.builder().text("D.L. No :").fontSize(8).horizontalAlignment(LEFT).borderWidthLeft(0.0F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
							         	.backgroundColor(WHITE)
						                .font(PDType1Font.HELVETICA_BOLD)	
						                .textColor(Color.BLACK)
						                .build();
					         
					         Row row2 = Row.builder()
						                .add(TextCell.builder().text("Add:"+(String)this.getSessionMap().get("shoponelineaddress")).rowSpan(2).fontSize(9).horizontalAlignment(CENTER).borderWidthLeft(0.0F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())				               
						                .add(TextCell.builder().text("20-467068.21-467069").fontSize(8).horizontalAlignment(LEFT).borderWidthLeft(0.0F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
								        .backgroundColor(WHITE)
						                .font(PDType1Font.HELVETICA_BOLD)	
						                .textColor(Color.BLACK)					             
						                .fontSize(7)
						                .build();
					         
					         Row row3  = Row.builder()
						                .add(TextCell.builder().text("").fontSize(8).horizontalAlignment(LEFT).borderWidthLeft(0.0F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
						                .backgroundColor(WHITE)
						                .font(PDType1Font.HELVETICA_BOLD)	
						                .textColor(Color.BLACK)
						                .build();
					         
					         Row row4  = Row.builder()
					        		 	.add(TextCell.builder().text("Contact No.:"+(String)this.getSessionMap().get("shopcustcarenumber")).fontSize(9).horizontalAlignment(CENTER).borderWidthLeft(0.0F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
					        		 	.add(TextCell.builder().text("").fontSize(8).horizontalAlignment(LEFT).borderWidthLeft(0.0F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
						                .backgroundColor(WHITE)
						                .font(PDType1Font.HELVETICA_BOLD)	
						                .textColor(Color.BLACK)
						                .fontSize(7)
						                .build();
					         
					         Row row5  = Row.builder()
					        		 	.add(TextCell.builder().text("Maharshatra, Code-27").fontSize(7).horizontalAlignment(CENTER).borderWidthLeft(0.0F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(1F).build())				               
					        		 	.add(TextCell.builder().text("").fontSize(8).horizontalAlignment(LEFT).borderWidthLeft(0.0F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(1F).build())				               
						                .backgroundColor(WHITE)
						                .font(PDType1Font.HELVETICA_BOLD)	
						                .textColor(Color.BLACK)
						                .build();
					         
					         
					         Row row6  = Row.builder()
					        		 	.add(TextCell.builder().text("Patient  Name : "+this.getBillInfoDAO().getCustomerName()+"                                             Ref. By Dr. Kiran Kalyan Mangawade MBBS").fontSize(8).colSpan(2).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
					        		 	.add(TextCell.builder().text("Invoice Number : "+this.getBillInfoDAO().getBillNumber()).fontSize(8).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
						                .backgroundColor(WHITE)
						                .font(PDType1Font.HELVETICA_BOLD)	
						                .textColor(Color.BLACK)
						                .build();
					         
					         Row row7  = Row.builder()
					        		 	.add(TextCell.builder().text("Address              : "+custAddress).fontSize(8).colSpan(2).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
					        		 	.add(TextCell.builder().text("Invoice Date : "+this.getBillInfoDAO().getBillDate()).fontSize(8).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
						                .backgroundColor(WHITE)
						                .font(PDType1Font.HELVETICA_BOLD)	
						                .textColor(Color.BLACK)
						                .build();
					         
					         
					         float custCreditAmount = GetCustomerCreditAmountById.getCustomerCreditAmountById(this.getBillInfoDAO().getCustId(), this.getSessionMap());
					        	
					         
					         Row row8  = Row.builder()
					        		 	.add(TextCell.builder().text("Mobile No            : "+custMobile).fontSize(8).colSpan(2).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
					        		 	.add(TextCell.builder().text("Total Balance Amount : "+custCreditAmount).fontSize(8).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(1F).build())				               
						                .backgroundColor(WHITE)
						                .font(PDType1Font.HELVETICA_BOLD)	
						                .textColor(Color.BLACK)
						                .build();
					         
					         Row row9  = Row.builder()
					        		 	.add(TextCell.builder().text("State Code: Maharashtra - 27").fontSize(8).colSpan(2).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(1F).build())				               
					        		 	.add(TextCell.builder().text("").fontSize(7).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(1F).build())				               
						                .backgroundColor(WHITE)
						                .font(PDType1Font.HELVETICA_BOLD)	
						                .textColor(Color.BLACK)
						                .build();
					        
					         
					       
				          
				          
							         tableHeaderBuilder.addRow(taxInvoice);
							         tableHeaderBuilder.addRow(row1);
							         tableHeaderBuilder.addRow(row2);
							         tableHeaderBuilder.addRow(row3);
							         tableHeaderBuilder.addRow(row4);
							         tableHeaderBuilder.addRow(row5);
							         tableHeaderBuilder.addRow(row6);
							         tableHeaderBuilder.addRow(row7);
							         tableHeaderBuilder.addRow(row8);
							         tableHeaderBuilder.addRow(row9);
							        
							         header = tableHeaderBuilder.build();
				         
				         
				        
				         
				      
				        /* TableBuilder billNumberDate = Table.builder()
					                .addColumnsOfWidth(139,137,137,137)				                
					                .font(HELVETICA)
					                .borderWidth(1)
					                .borderColor(Color.BLACK);
				         
				         
				         Row billNumberDateRow1 = Row.builder()
					                .add(TextCell.builder().text("Invoice Number").horizontalAlignment(LEFT).borderWidth(0.5F).fontSize(8).lineSpacing(1F).build())				               
					                .add(TextCell.builder().text(this.getBillInfoDAO().getBillNumber()).horizontalAlignment(LEFT).fontSize(10).borderWidth(0.5F).lineSpacing(1F).build())
					                .add(TextCell.builder().text("Invoice Date").horizontalAlignment(RIGHT).borderWidth(0.5F).fontSize(8).lineSpacing(1F).build())				               
					                .add(TextCell.builder().text(this.getBillInfoDAO().getBillDate()).horizontalAlignment(LEFT).fontSize(10).borderWidth(0.5F).lineSpacing(1F).build())
					                .backgroundColor(WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD)				              
					                .horizontalAlignment(CENTER)
					                .build();
				         
				         Row billNumberDateRow2 = Row.builder()
					                .add(TextCell.builder().text("Mode Of Payment").horizontalAlignment(LEFT).borderWidth(0.5F).fontSize(8).lineSpacing(1F).build())				               
					                .add(TextCell.builder().text(this.getBillInfoDAO().getPaymentType()).horizontalAlignment(LEFT).borderWidth(0.5F).fontSize(8).lineSpacing(1F).build())				               
					                .add(TextCell.builder().text("Buyer Order Number").horizontalAlignment(RIGHT).borderWidth(0.5F).fontSize(8).lineSpacing(1F).build())				               
					                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidth(0.5F).fontSize(8).lineSpacing(1F).build())		               
						            .backgroundColor(WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD)				              
					                .horizontalAlignment(CENTER)
					                .build();
				         Row billNumberDateRow3 = Row.builder()
					                .add(TextCell.builder().text("State: Maharatshtra ").horizontalAlignment(LEFT).borderWidth(0.5F).fontSize(10).lineSpacing(1F).build())				               
					                .add(TextCell.builder().text("Code : 27").horizontalAlignment(LEFT).borderWidth(0.5F).fontSize(10).lineSpacing(1F).build())
					                .add(TextCell.builder().text("Dispatch Doc. Number").horizontalAlignment(RIGHT).borderWidth(0.5F).fontSize(8).lineSpacing(1F).build())
					                .add(TextCell.builder().text("").horizontalAlignment(LEFT).fontSize(10).borderWidth(0.5F).lineSpacing(1F).build())
					                .backgroundColor(WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD).fontSize(10)				              
					                .horizontalAlignment(CENTER)
					                .build();
				         
				         billNumberDate.addRow(billNumberDateRow1);
				         billNumberDate.addRow(billNumberDateRow2);
				         billNumberDate.addRow(billNumberDateRow3);
				         billNumberTable =billNumberDate.build();
				       
				         
				         
				         TableBuilder tableCustDetailsBuilder = Table.builder()
					                .addColumnsOfWidth(350,125)				                
					                .font(HELVETICA)
					                .borderColor(Color.BLACK)
					                .horizontalAlignment(CENTER);
				         
				         Row custDetailsRow1 = Row.builder()
					                .add(TextCell.builder().text("Details Of Receiver (Billed To)").colSpan(2).horizontalAlignment(CENTER).borderWidth(0).lineSpacing(1F).build())				                
					                .backgroundColor(WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD).fontSize(10)				              
					                .horizontalAlignment(CENTER)
					                .build();
				         
				         Row custDetailsRow2 = Row.builder()
					                .add(TextCell.builder().text("Customer Name:  "+this.getBillInfoDAO().getCustomerName()).horizontalAlignment(LEFT).borderWidth(0).borderWidthBottom(0.5F).lineSpacing(1F).build())				                
					                .add(TextCell.builder().text("State Code:  27").horizontalAlignment(LEFT).borderWidth(0).borderWidthBottom(0.5F).lineSpacing(1F).build())				                
							       .backgroundColor(WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD).fontSize(9)				              
					                .horizontalAlignment(CENTER)
					                .build();
				         
				         Row custDetailsRow3 = Row.builder()
					                .add(TextCell.builder().text("Address:  "+custAddress).horizontalAlignment(LEFT).borderWidth(0).borderWidthBottom(0.5F).lineSpacing(1F).build())
					                .add(TextCell.builder().text("GST No:  "+custGstNumber).horizontalAlignment(LEFT).borderWidth(0).borderWidthBottom(0.5F).lineSpacing(1F).build())				                
					                .backgroundColor(WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD).fontSize(8)				              
					                .horizontalAlignment(CENTER)
					                .build();
				         
				         Row custDetailsRow4 = Row.builder()
					                .add(TextCell.builder().text("Mobile:  "+custMobile).colSpan(2).horizontalAlignment(LEFT).borderWidth(0).borderWidthBottom(0.5F).lineSpacing(1F).build())				                
					                .backgroundColor(WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD).fontSize(9)				              
					                .horizontalAlignment(CENTER)
					                .build();
				         
				        
				         tableCustDetailsBuilder.addRow(custDetailsRow1);
				         tableCustDetailsBuilder.addRow(custDetailsRow2);
				         tableCustDetailsBuilder.addRow(custDetailsRow3);
				         tableCustDetailsBuilder.addRow(custDetailsRow4);
				      
				         
				         customerDetails = tableCustDetailsBuilder.build();
				        
				   */
				         TableBuilder tableproductDetailsBuilder = Table.builder()
					                .addColumnsOfWidth(20,200,55,75,55,45,50,70)				                
					                .font(HELVETICA)
					                .borderWidth(0.5F)
					                .borderColor(Color.BLACK);
				         
				         Row productDetailsRow1 = Row.builder()
					                .add(TextCell.builder().text("Sr.").horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())				                
					                .add(TextCell.builder().text("Description Of Product").horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())
					                .add(TextCell.builder().text("MFG").horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())
					                .add(TextCell.builder().text("Batch No").horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())				                
					                .add(TextCell.builder().text("Expiry").horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())
					                .add(TextCell.builder().text("Qty").horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())
					                .add(TextCell.builder().text("Rate").horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())
						            .add(TextCell.builder().text("Total Amt").horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(1F).build())
						            .backgroundColor(Color.WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD).fontSize(8)				              
					                .horizontalAlignment(CENTER)
					                .build();
				         
				         tableproductDetailsBuilder.addRow(productDetailsRow1);
				      
				         
			         int srNo = 1;
				         
				         float allUnitTotalAmount = 0.0F;
				         float totalBasicAmount = 0.0F;
				         float totalCgstAmount = 0.0F;
				         float totalSgstAmount = 0.0f;
				         for(int i =0;i<10;i++)
							{
				        	
				        	 
				        		BillProductInfoDAO informationDAO = null;
				        	 try
				        	 {
				        		 informationDAO =this.getProductInfoList().get(i);
				        	 }
				        	 catch(Exception e)
				        	 {
				        		 informationDAO = null;
				        	 }
				        			
				        	 if(informationDAO != null)
				        	 {
				        		 
				        		 float basicPrice = 0.0F;
				        		 float taxableAmount = 0.0F;
				        		 float totalUnitAmount = 0.0F;
				        		 float unitCgst = 0.0F;
				        		 float unitSgst = 0.0F;
				        		 float taxPercentage = 0.0F;
				        		 float halfTax = 0.0F;
				        		 float qty = informationDAO.getQuantity();
				        		 try
				        		 {
				        		 
				        			
				        		 basicPrice = informationDAO.getSalesRate();
				        		 unitCgst = informationDAO.getCgst();
				        		 unitSgst = informationDAO.getSgst();
				        		 taxPercentage = informationDAO.getTaxPercentage();
				        		 
				        		 totalBasicAmount = totalBasicAmount + informationDAO.getGrossAmount();
				        		 totalCgstAmount = totalCgstAmount + informationDAO.getCgst();
				        		 totalSgstAmount = totalSgstAmount + informationDAO.getSgst();
				        		 taxableAmount = basicPrice*qty;
				        		 
				        		 totalUnitAmount = informationDAO.getGrossAmount() + unitCgst + unitSgst ;
				        		 
				        		 allUnitTotalAmount = allUnitTotalAmount+ totalUnitAmount;
				        		 
				        		 halfTax  = taxPercentage/2.0F;
				        		 
				        		 }catch(NumberFormatException e)
				        		 {
				        			// e.printStackTrace();
				        		 }
				        		 
				        		// int qty = Integer.parseInt(informationDAO.getProductQuantity());
				        	
				        		 
				        		 
					        	if(i!=9)
					        	{
					        		 Row productDetailsRow = Row.builder()
								                .add(TextCell.builder().text(""+srNo).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(1F).build())				                
								                .add(TextCell.builder().text(informationDAO.getProductName().toUpperCase()).fontSize(7).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.2F).build())
								                .add(TextCell.builder().text(informationDAO.getHsnCode()).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.0F).verticalAlignment(MIDDLE).lineSpacing(1F).build())
								                .add(TextCell.builder().text(informationDAO.getBatchId()).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.0F).verticalAlignment(MIDDLE).lineSpacing(1F).build())					                
								                .add(TextCell.builder().text(informationDAO.getExpiryDate()).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.0F).verticalAlignment(MIDDLE).lineSpacing(1F).build())
								                .add(TextCell.builder().text(df.format(informationDAO.getQuantity())+" "+informationDAO.getSalesUnitShortName()).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.0F).verticalAlignment(MIDDLE).lineSpacing(1F).build())
								                .add(TextCell.builder().text(df.format(informationDAO.getSalesRate())).horizontalAlignment(RIGHT).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.0F).verticalAlignment(MIDDLE).lineSpacing(1F).build())
								                .add(TextCell.builder().text(df.format(informationDAO.getSalesRate()*informationDAO.getQuantity())).font(PDType1Font.HELVETICA_BOLD).horizontalAlignment(RIGHT).verticalAlignment(MIDDLE).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(1F).build())
								                .backgroundColor(Color.WHITE)
								                .textColor(Color.BLACK)
								                .font(PDType1Font.HELVETICA)
								                .fontSize(9)				              
								                .horizontalAlignment(CENTER)
								                .verticalAlignment(TOP)
								                .build();
							         tableproductDetailsBuilder.addRow(productDetailsRow);
					        	}else
					        	{
					        		 Row productDetailsRow = Row.builder()
								                .add(TextCell.builder().text(""+srNo).horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(1F).build())				                
								                .add(TextCell.builder().text(informationDAO.getProductName().toUpperCase()).fontSize(7).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.2F).build())
								                .add(TextCell.builder().text(informationDAO.getHsnCode()).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.5F).verticalAlignment(MIDDLE).lineSpacing(1F).build())
								                .add(TextCell.builder().text(informationDAO.getBatchId()).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.5F).verticalAlignment(MIDDLE).lineSpacing(1F).build())					                
								                .add(TextCell.builder().text(informationDAO.getExpiryDate()).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.5F).verticalAlignment(MIDDLE).lineSpacing(1F).build())
								                .add(TextCell.builder().text(df.format(informationDAO.getQuantity())+" "+informationDAO.getSalesUnitShortName()).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.5F).verticalAlignment(MIDDLE).lineSpacing(1F).build())
								                .add(TextCell.builder().text(df.format(informationDAO.getSalesRate())).horizontalAlignment(RIGHT).borderWidthLeft(0.5F).borderWidthRight(0.0F).borderWidthTop(0.0F).borderWidthBottom(0.5F).verticalAlignment(MIDDLE).lineSpacing(1F).build())
								                .add(TextCell.builder().text(df.format(informationDAO.getSalesRate()*informationDAO.getQuantity())).font(PDType1Font.HELVETICA_BOLD).horizontalAlignment(RIGHT).verticalAlignment(MIDDLE).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(1F).build())
								                .backgroundColor(Color.WHITE)
								                .textColor(Color.BLACK)
								                .font(PDType1Font.HELVETICA)
								                .fontSize(9)				              
								                .horizontalAlignment(CENTER)
								                .verticalAlignment(TOP)
								                .build();
							         tableproductDetailsBuilder.addRow(productDetailsRow);
					        	}
						         srNo++;
						         
				        	 }
				        	 
				        	 else
				        	 {

				        		 if(i!=9)
				        		 {
						        	  Row productDetailsRow = Row.builder()
								                .add(TextCell.builder().text("").horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())				                
								                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())
								                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())
								                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())
								                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())
								                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())
								                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())
								                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())
								                .backgroundColor(Color.WHITE)
								                .textColor(Color.BLACK)
								                .font(PDType1Font.HELVETICA)
								                .fontSize(8)				              
								                .horizontalAlignment(CENTER)
								                .build();
							         tableproductDetailsBuilder.addRow(productDetailsRow);
				        		 }
				        		 else
				        		 {
				        			 Row productDetailsRow = Row.builder()
								                .add(TextCell.builder().text("").horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				                
								                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())
								                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())
								                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())
								                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())
								                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())
								                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())
								                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())
								                .backgroundColor(Color.WHITE)
								                .textColor(Color.BLACK)
								                .font(PDType1Font.HELVETICA)
								                .fontSize(8)				              
								                .horizontalAlignment(CENTER)
								                .build();
							         tableproductDetailsBuilder.addRow(productDetailsRow);
				        		 }
						         
						         srNo++;
				        	 }
				         
				         }
				         
				         Row totalSCGTRow = Row.builder()
					                .add(TextCell.builder().text("").horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())				                
					                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())
					                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())						                
					                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())
					                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())
					                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())
					                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())
					                .add(TextCell.builder().text(df.format(totalSgstAmount)).horizontalAlignment(RIGHT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.0F).lineSpacing(0.5F).build())
					                .backgroundColor(Color.WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD)
					                .fontSize(8)				              
					                .horizontalAlignment(CENTER)
					                .build();
				        // tableproductDetailsBuilder.addRow(totalSCGTRow);
				         
				         Row totalCCGTRow = Row.builder()
					                .add(TextCell.builder().text("").horizontalAlignment(CENTER).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				                
					                .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())
					                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())
					                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())						                
					                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())
					                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())
					                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())
					                .add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())
					                .backgroundColor(Color.WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD)
					                .fontSize(8)				              
					                .horizontalAlignment(CENTER)
					                .build();
				        // tableproductDetailsBuilder.addRow(totalCCGTRow);
				         
				         float totalAmounttoConvert = Float.parseFloat(this.getBillInfoDAO().getTotalBillAmount());
					      DecimalFormat df2 = new DecimalFormat("##.##");
				         Row totalRow = Row.builder()
				        		  	.add(TextCell.builder().text("TOTAL").horizontalAlignment(RIGHT).colSpan(5).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())				                
				        		  	.add(TextCell.builder().text(df.format(totalQuantity)).horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())
					                .add(TextCell.builder().text("").horizontalAlignment(LEFT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())
					               .add(TextCell.builder().text("Rs. "+df2.format(totalAmounttoConvert)).horizontalAlignment(RIGHT).borderWidthLeft(0.5F).borderWidthRight(0.5F).borderWidthTop(0.0F).borderWidthBottom(0.5F).lineSpacing(0.5F).build())
					                .backgroundColor(Color.WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD)
					                .fontSize(9)				              
					                .horizontalAlignment(CENTER)
					                .build();
				         
				       	tableproductDetailsBuilder.addRow(totalRow);
				         
				         
				       
				         String convertedAmount = new NumberToWordsConverter().getConverted(""+totalAmounttoConvert);
				      
				       Row amountInWordsRow = Row.builder()
					                .add(TextCell.builder().text("Amount in words :"+convertedAmount).colSpan(8).horizontalAlignment(LEFT).borderWidth(0.5F).build())
					                .backgroundColor(Color.WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD)
					                .fontSize(9)				              
					                .horizontalAlignment(CENTER)
					                .build();
				         
				       	tableproductDetailsBuilder.addRow(amountInWordsRow);
				       	
				        Row declareRow = Row.builder()
				                .add(TextCell.builder().text("Declaration: "+declaration).colSpan(8).horizontalAlignment(LEFT).borderWidth(0.5F).verticalAlignment(TOP).lineSpacing(0.5F).build())
				                .backgroundColor(Color.WHITE)
				                .textColor(Color.BLACK)
				                .font(PDType1Font.HELVETICA)
				                .fontSize(9)				              
				                .horizontalAlignment(CENTER)
				                .height(20F)	
				                .build();
				       	tableproductDetailsBuilder.addRow(declareRow);
					       
				         productDetails = tableproductDetailsBuilder.build();
				         
				         
				       /*  
				         TableBuilder totalDetailsBuilder = Table.builder()
					                .addColumnsOfWidth(450,100)				                
					                .font(HELVETICA)
					                .borderWidth(1)
					                .borderColor(Color.BLACK);
				         
				         
				         Row totalDetailsRow1 = Row.builder()
					                .add(TextCell.builder().text("Total Taxable Amount").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(10F).build())				                
					                .add(TextCell.builder().text(df.format(totalBasicAmount)).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(10F).build())
					                .backgroundColor(Color.WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD)
					                .fontSize(9)				              
					                .horizontalAlignment(CENTER)
					                .height(23F)	
					                .build();
				         totalDetailsBuilder.addRow(totalDetailsRow1);        
				         
				        
				         
				         
				         Row totalDetailsRow2 = Row.builder()
					                .add(TextCell.builder().text("Total SGST Amount").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(10F).build())				                
					                .add(TextCell.builder().text(df.format(totalSgstAmount)).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(10F).build())
					                .backgroundColor(Color.WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD)
					                .fontSize(9)				              
					                .horizontalAlignment(CENTER)
					                .height(20F)	
					                .build();
				         totalDetailsBuilder.addRow(totalDetailsRow2);
				         
				         Row totalDetailsRow3 = Row.builder()
					                .add(TextCell.builder().text("Total CGST Amount").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(10F).build())				                
					                .add(TextCell.builder().text(df.format(totalCgstAmount)).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(10F).build())
					                .backgroundColor(Color.WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD)
					                .fontSize(9)				              
					                .horizontalAlignment(CENTER)
					                .height(20F)	
					                .build();
				         totalDetailsBuilder.addRow(totalDetailsRow3);
				         
				         
				    
				         float totalTax = totalCgstAmount + totalSgstAmount;
				         
				         Row totalDetailsRow4 = Row.builder()
					                .add(TextCell.builder().text("Total TAX Amount").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(10F).build())				                
					                .add(TextCell.builder().text(""+totalTax).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(10F).build())
					                .backgroundColor(Color.WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD)
					                .fontSize(9)				              
					                .horizontalAlignment(CENTER)
					                .height(20F)	
					                .build();
				         totalDetailsBuilder.addRow(totalDetailsRow4);
				         
				         float roundOff = allUnitTotalAmount - Float.parseFloat(this.getBillInfoDAO().getTotalBillAmount());
				         
				         
				         
				         Row totalDetailsRow6 = Row.builder()
					                .add(TextCell.builder().text("Round Off").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(10F).build())				                
					                .add(TextCell.builder().text(df.format(roundOff)).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(10F).build())
					                .backgroundColor(Color.WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD)
					                .fontSize(9)				              
					                .horizontalAlignment(CENTER)
					                .height(20F)	
					                .build();
				         totalDetailsBuilder.addRow(totalDetailsRow6);
				         
				         Row totalDetailsRow5 = Row.builder()
					                .add(TextCell.builder().text("Total Amount After TAX & Round Off").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(10F).build())				                
					                .add(TextCell.builder().text(this.getBillInfoDAO().getTotalBillAmount()).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(10F).build())
					                .backgroundColor(Color.WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD)
					                .fontSize(9)				              
					                .horizontalAlignment(CENTER)
					                .height(20F)	
					                .build();
				         totalDetailsBuilder.addRow(totalDetailsRow5);
				         
				         
				        
				         
				         totalAmountDetails = totalDetailsBuilder.build();
				         
				       
				         
				         
				         TableBuilder tableBottomInfoBuilder = Table.builder()
					                .addColumnsOfWidth(550)				                
					                .font(HELVETICA)
					                .borderColor(Color.BLACK);
				         

				         Row bottomInfoRow1 = Row.builder()
					                .add(TextCell.builder().text("Declaration: "+declaration).horizontalAlignment(LEFT).borderWidth(0).borderWidthBottom(0.0F).verticalAlignment(BOTTOM).lineSpacing(10F).build())
					                .backgroundColor(Color.WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA)
					                .fontSize(9)				              
					                .horizontalAlignment(CENTER)
					                .height(20F)	
					                .build();
				         
				        if(this.getBillInfoDAO().getComments() == null)
				       {
				    	   this.getBillInfoDAO().setComments("NA");
				       }
				       if(this.getBillInfoDAO().getComments().equals("NA"))
				         {
				         Row bottomInfoRowComments = Row.builder()
					                .add(TextCell.builder().text("Comments:").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(0.5F).build())
					                .backgroundColor(Color.WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA)
					                .fontSize(10)
					                .height(30F)
					                .horizontalAlignment(CENTER)					               	
					                .build();
				         tableBottomInfoBuilder.addRow(bottomInfoRowComments);
				         
				         }
				         else
				         {
				        	 Row bottomInfoRowComments = Row.builder()
						                .add(TextCell.builder().text("Comments:"+this.getBillInfoDAO().getComments()).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(0.5F).build())
						                .backgroundColor(Color.WHITE)
						                .textColor(Color.BLACK)
						                .font(PDType1Font.HELVETICA)
						                .fontSize(10)
						                .height(30F)
						                .horizontalAlignment(CENTER)					               	
						                .build();
					         tableBottomInfoBuilder.addRow(bottomInfoRowComments);
				         }
				     			        
				       tableBottomInfoBuilder.addRow(bottomInfoRow1);
				         
				         bottomInfo = tableBottomInfoBuilder.build();
				         
				         */
				         
				         TableBuilder signatureBuiler = Table.builder()
					                .addColumnsOfWidth(150,270,150)				                
					                .font(HELVETICA)
					                .borderColor(Color.BLACK)
					                .horizontalAlignment(CENTER);
				         
				         String taxInvoiceComments = this.getBillInfoDAO().getComments();
				         if(taxInvoiceComments == null || taxInvoiceComments.equals("NA"))
				         {
				        	 taxInvoiceComments = "";
				         }
				         Row taxInvoiceCommentsRow = Row.builder()
					                .add(TextCell.builder().text("Comments: "+taxInvoiceComments).colSpan(3).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(0.5F).build())
					                .backgroundColor(Color.WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA)
					                .fontSize(8)
					                .horizontalAlignment(LEFT)
					                .height(16F)
					                .build();
				         signatureBuiler.addRow(taxInvoiceCommentsRow);
				         
				         Row signRow1 = Row.builder()
					                .add(TextCell.builder().text("Receiver's Signature").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(0.2F).build())
					                .add(TextCell.builder().text("").verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(0.2F).build())					               
						            .add(TextCell.builder().text("For "+this.getHeaderShopName()).verticalAlignment(BOTTOM).horizontalAlignment(CENTER).borderWidth(0.5F).lineSpacing(0.2F).build())
					                .backgroundColor(Color.WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD)
					                .fontSize(7)				              
					                .horizontalAlignment(CENTER)
					                .height(34F)	
					                .build();
				         signatureBuiler.addRow(signRow1);
				       
				         
				         signature = signatureBuiler.build();   
			        
				         float startY = page.getMediaBox().getHeight() - PADDING20;
					        
					       
				         float yCordinate = page.getCropBox().getUpperRightY() - 72;
				         float startX = page.getCropBox().getLowerLeftX() + 10;
				         float endX = page.getCropBox().getUpperRightX() - 10;
				       
				     /*  contentStream.setLineWidth(0.6f);
				        contentStream.moveTo(startX, yCordinate);
				        contentStream.lineTo(endX, yCordinate);
				        contentStream.stroke();
				        
				        yCordinate = yCordinate - 15;
				        
				        contentStream.moveTo(startX, yCordinate);
				        contentStream.lineTo(endX, yCordinate);
				        contentStream.stroke();
				        */
				        
				       TableDrawer.builder()
		                .contentStream(contentStream)
		                .table(header)
		                .startX(PADDING10)
		                .startY(startY)
		                .build()
		                .draw();
				       
				        
				      
				       /* TableDrawer.builder()
		                .contentStream(contentStream)
		                .table(billNumberTable)
		                .startX(PADDING10)
		                .startY(startY-100)
		                .build()
		                .draw();
				        
				        TableDrawer.builder()
		                .contentStream(contentStream)
		                .table(customerDetails)
		                .startX(70)
		                .startY(startY-150)
		                .build()
		                .draw();*/
				        
				        TableDrawer.builder()
		                .contentStream(contentStream)
		                .table(productDetails)
		                .startX(PADDING10)
		                .startY(startY-138)
		                .build()
		                .draw();
				        
				      /* TableDrawer.builder()
		                .contentStream(contentStream)
		                .table(totalAmountDetails)
		                .startX(PADDING10)
		                .startY(startY-485)
		                .build()
		                .draw();
				        
				        TableDrawer.builder()
		                .contentStream(contentStream)
		                .table(bottomInfo)
		                .startX(PADDING10)
		                .startY(startY-605)
		                .build()
		                .draw();*/
				        
				      TableDrawer.builder()
		                .contentStream(contentStream)
		                .table(signature)
		                .startX(PADDING10)
		                .startY(startY-338)
		                .build()
		                .draw();

				         if(pdImageLeftLogoImage != null)
			        	 {
				        	
			        		 contentStream.drawImage(pdImageLeftLogoImage, 25, 335 , 50, 50);
			        		
			        	 }
			
				        
				    
				        
				         
					    contentStream.close();
				        
				       // System.out.println(path);
								
				        
				        document.save(path+"/invoice.pdf");
				        document.close();
				        
				        

						response.setHeader("Content-disposition", "inline; filename=tax-invoice.pdf");
						response.setContentType("application/pdf");
						@SuppressWarnings("resource")
						FileInputStream fileInputStream = new FileInputStream(path+"/invoice.pdf");
						PrintWriter out = response.getWriter();  
						int bytes;
						while ((bytes = fileInputStream.read()) != -1) {
							out.write(bytes);
						}
						fileInputStream.close();
						out.flush();
						out.close();
			        	 
						
			         }
		         
		         
		         
	         	
				}
				
	        	}
	        	catch (SQLException e) {
	        		e.printStackTrace();
					
				} catch (IOException e) {
					e.printStackTrace();
					
				}catch (Exception e) {
					e.printStackTrace();
					
				}finally {
					if(resultSet != null)
    				{
    					try {
    						resultSet.close(); resultSet = null;
    					} catch (SQLException e) {
    						
    					}
    				}
					if(preparedStatement != null)
					{
						try {preparedStatement.close(); preparedStatement = null;} catch (SQLException e) {}
					}
					if(connection != null)
					{
						
						try {connection.close(); connection = null;}catch (SQLException e) {}
					}
					
					
	        	}
	   }

	public HttpSession getSession() {
		return session;
	}

	public void setSession(HttpSession session) {
		this.session = session;
	}

	public SessionMap<String, Object> getSessionMap() {
		return sessionMap;
	}

	public void setSessionMap(SessionMap<String, Object> sessionMap) {
		this.sessionMap = sessionMap;
	}

	public BillInformationDAO getBillInfoDAO() {
		return billInfoDAO;
	}

	public void setBillInfoDAO(BillInformationDAO billInfoDAO) {
		this.billInfoDAO = billInfoDAO;
	}

	public List<BillProductInfoDAO> getProductInfoList() {
		return productInfoList;
	}

	public void setProductInfoList(List<BillProductInfoDAO> productInfoList) {
		this.productInfoList = productInfoList;
	}




	private String getHeaderShopName() {
		String currentBillType = this.getBillInfoDAO() != null ? this.getBillInfoDAO().getBillType() : null;
		if ("QUOTATION".equals(currentBillType) || "ESTIMATE".equals(currentBillType)) {
			String estimateQuotationShopName = (String)this.getSessionMap().get("shopnameenglishestiquote");
			if (estimateQuotationShopName != null && !estimateQuotationShopName.trim().isEmpty()) {
				return estimateQuotationShopName;
			}
		}
		return (String)this.getSessionMap().get("shopnameenglish");
	}


	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	public String getBillNumber() {
		return billNumber;
	}

	public void setBillNumber(String billNumber) {
		this.billNumber = billNumber;
	}

	public String getBillType() {
		return billType;
	}

	public void setBillType(String billType) {
		this.billType = billType;
	}

	public String getTypeOfBill() {
		return typeOfBill;
	}

	public void setTypeOfBill(String typeOfBill) {
		this.typeOfBill = typeOfBill;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}
	
	
	
	

	
	public String getBillDateTime() {
		return billDateTime;
	}

	public void setBillDateTime(String billDateTime) {
		this.billDateTime = billDateTime;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public void setSession(Map<String, Object> map) {
		// TODO Auto-generated method stub
		 sessionMap=(SessionMap<String, Object>)map;  
		
	}

	


}
