View Javadoc
1   package org.kuali.ole.deliver.bo;
2   
3   /**
4    * Created with IntelliJ IDEA.
5    * User: ?
6    * Date: 11/2/12
7    * Time: 2:27 PM
8    * To change this template use File | Settings | File Templates.
9    */
10  
11  import com.lowagie.text.*;
12  import com.lowagie.text.Font;
13  import com.lowagie.text.pdf.BaseFont;
14  import com.lowagie.text.pdf.PdfPTable;
15  import com.lowagie.text.pdf.PdfPageEventHelper;
16  import com.lowagie.text.pdf.PdfWriter;
17  import org.apache.log4j.Logger;
18  import org.kuali.ole.OLEConstants;
19  import org.kuali.rice.core.web.format.CurrencyFormatter;
20  import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
21  import org.kuali.rice.krad.service.BusinessObjectService;
22  import org.kuali.rice.krad.service.KRADServiceLocator;
23  
24  import javax.servlet.ServletOutputStream;
25  import javax.servlet.http.HttpServletResponse;
26  import java.awt.*;
27  import java.io.ByteArrayOutputStream;
28  import java.io.IOException;
29  import java.io.OutputStream;
30  import java.math.BigDecimal;
31  import java.text.SimpleDateFormat;
32  import java.util.*;
33  import java.util.List;
34  
35  /**
36   * The PrintBill  class used to create pdf document .
37   */
38  public class PrintBill extends PdfPageEventHelper {
39  
40      private static final Logger LOG = Logger.getLogger(PrintBill.class);
41  
42      private Map<String, Font> printFontMap = new HashMap<String, Font>();
43  
44      private Map<String, Font> fontMap = new HashMap<String, Font>();
45      private Map<String, Color> colorMap = new HashMap<String, Color>();
46      private Map<String, Color> printColorMap = new HashMap<String, Color>();
47  
48  
49      public void populateFontMap() {
50          fontMap.put("COURIER", new Font(Font.COURIER));
51          fontMap.put("BOLD", new Font(Font.BOLD));
52          fontMap.put("BOLDITALIC", new Font(Font.BOLDITALIC));
53          fontMap.put("DEFAULTSIZE", new Font(Font.DEFAULTSIZE));
54          fontMap.put("HELVETICA", new Font(Font.HELVETICA));
55          fontMap.put("ITALIC", new Font(Font.ITALIC));
56          fontMap.put("NORMAL", new Font(Font.NORMAL));
57          fontMap.put("STRIKETHRU", new Font(Font.STRIKETHRU));
58          fontMap.put("SYMBOL", new Font(Font.SYMBOL));
59          fontMap.put("TIMES_ROMAN", new Font(Font.TIMES_ROMAN));
60          fontMap.put("UNDEFINED", new Font(Font.UNDEFINED));
61          fontMap.put("UNDERLINE", new Font(Font.UNDERLINE));
62          fontMap.put("ZAPFDINGBATS", new Font(Font.ZAPFDINGBATS));
63  
64      }
65  
66      public void populateColorMap() {
67          colorMap.put("WHITE", Color.WHITE);
68          colorMap.put("YELLOW", Color.YELLOW);
69          colorMap.put("BLACK", Color.BLACK);
70          colorMap.put("BLUE", Color.BLUE);
71          colorMap.put("CYAN", Color.CYAN);
72          colorMap.put("DARK_GRAY", Color.DARK_GRAY);
73          colorMap.put("GRAY", Color.GRAY);
74          colorMap.put("GREEN", Color.GREEN);
75          colorMap.put("LIGHT_GRAY", Color.LIGHT_GRAY);
76          colorMap.put("MAGENTA", Color.MAGENTA);
77          colorMap.put("ORANGE", Color.ORANGE);
78          colorMap.put("PINK", Color.PINK);
79          colorMap.put("RED", Color.RED);
80  
81          colorMap.put("PINK", Color.PINK);
82      }
83  
84      public void populatePrintFontMap() {
85          BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
86          Map<String, String> criteriaMap = new HashMap<String, String>();
87          criteriaMap.put("namespaceCode", "OLE-PRNT");
88          criteriaMap.put("componentCode", "Patron Bill Font");
89          List<ParameterBo> parametersList = (List<ParameterBo>) businessObjectService.findMatching(ParameterBo.class, criteriaMap);
90          for (int i = 0; i < parametersList.size(); i++) {
91              printFontMap.put(parametersList.get(i).getName(), fontMap.get(parametersList.get(i).getValue()));
92          }
93      }
94  
95      public void populatePrintColorMap() {
96          BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
97          Map<String, String> criteriaMap = new HashMap<String, String>();
98          criteriaMap.put("namespaceCode", "OLE-PRNT");
99          criteriaMap.put("componentCode", "Patron Bill Color");
100         List<ParameterBo> parametersList = (List<ParameterBo>) businessObjectService.findMatching(ParameterBo.class, criteriaMap);
101         for (int i = 0; i < parametersList.size(); i++) {
102             printColorMap.put(parametersList.get(i).getName(), colorMap.get(parametersList.get(i).getValue()));
103         }
104     }
105 
106     public String getTemplate() {
107 
108         BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
109         Map<String, String> criteriaMap = new HashMap<String, String>();
110         criteriaMap.put("namespaceCode", "OLE-PRNT");
111         criteriaMap.put("componentCode", "Print Template");
112         List<ParameterBo> parametersList = (List<ParameterBo>) businessObjectService.findMatching(ParameterBo.class, criteriaMap);
113         return parametersList.get(0).getValue();
114 
115     }
116 
117     /**
118      * Used to select pdf template
119      *
120      * @param patronBillPayments,feeTypeList,response
121      *
122      * @return Void
123      */
124     public void generatePdf(String firstName, String lastName, List<PatronBillPayment> patronBillPayments, List<FeeType> feeTypeList,boolean isDefaultPrint,List<String> transactionIds, HttpServletResponse response) {
125         String template = getTemplate();
126         if (template.equalsIgnoreCase(OLEConstants.BILL_TEMP_NORMAL)) {
127             createPdf(firstName, lastName, patronBillPayments, feeTypeList,isDefaultPrint,transactionIds, response);
128         } else if (template.equalsIgnoreCase(OLEConstants.BILL_TEMP_TABLE)) {
129             createPdfWithTable(firstName, lastName, patronBillPayments, feeTypeList,isDefaultPrint,transactionIds, response);
130         }
131     }
132 
133     /**
134      * Used to create pdf document for patron bill
135      *
136      * @param patronBillPayments,feeTypeList,response
137      *
138      * @return Void
139      */
140     public void createPdf(String firstName, String lastName, List<PatronBillPayment> patronBillPayments, List<FeeType> feeTypeList,boolean isDefaultPrint,List<String> transactionIds, HttpServletResponse response) {
141         LOG.debug("Initialize Normal pdf Template");
142         ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
143         BigDecimal feeAmount = BigDecimal.valueOf(0);
144         BigDecimal paidAmount = BigDecimal.valueOf(0);
145         String billNumber = "";
146         try {
147             populateColorMap();
148             populateFontMap();
149             populatePrintColorMap();
150             populatePrintFontMap();
151             response.setContentType("application/pdf");
152             Document document = this.getDocument(0, 0, 5, 5);
153             document.open();
154             document.newPage();
155             Paragraph paraGraph = new Paragraph();
156             paraGraph.setAlignment(Element.ALIGN_CENTER);
157             paraGraph.add(new Chunk(OLEConstants.OlePatronBill.HEADER_PATRON_RECEIPT));
158             paraGraph.add(Chunk.NEWLINE);
159             paraGraph.add(Chunk.NEWLINE);
160             paraGraph.add(Chunk.NEWLINE);
161             SimpleDateFormat df = new SimpleDateFormat(OLEConstants.DAT_FORMAT_EFFECTIVE_PRINT);
162             paraGraph.add(new Chunk(OLEConstants.BILL_DT + " : " + df.format(System.currentTimeMillis()) + ""));
163             paraGraph.add(Chunk.NEWLINE);
164             paraGraph.add(new Chunk(OLEConstants.FIRST_NAME + " : " + firstName, printFontMap.get("Patron_Name_Font")));
165             paraGraph.add(Chunk.NEWLINE);
166             paraGraph.add(new Chunk(OLEConstants.LAST_NAME + " : " + lastName, printFontMap.get("Item_Title_Font")));
167             paraGraph.add(Chunk.NEWLINE);
168             for (int j = 0; j < feeTypeList.size(); j++) {
169                 List<OleItemLevelBillPayment> oleItemLevelBillPayments = new ArrayList<>();
170                 if (feeTypeList.get(j).getItemLevelBillPaymentList() != null) {
171                     oleItemLevelBillPayments.addAll(feeTypeList.get(j).getItemLevelBillPaymentList());
172                 } else {
173                     Map<String,String> map=new HashMap<String,String>();
174                     map.put("lineItemId",feeTypeList.get(j).getId());
175                     List<OleItemLevelBillPayment> itemLevelBillPayments=(List<OleItemLevelBillPayment>)KRADServiceLocator.getBusinessObjectService().findMatching(OleItemLevelBillPayment.class,map);
176                     if(itemLevelBillPayments!=null){
177                         oleItemLevelBillPayments.addAll(itemLevelBillPayments);
178                     }
179                 }
180                 String feeTypeName="";
181                 if(feeTypeList.get(j).getOleFeeType()!=null && feeTypeList.get(j).getOleFeeType().getFeeTypeName()!=null){
182                     feeTypeName=feeTypeList.get(j).getOleFeeType().getFeeTypeName();
183                 }
184                 if (!feeTypeList.get(j).getBillNumber().equals(billNumber)) {
185                     paraGraph.add(new Chunk(OLEConstants.BILL_NO + " : " + feeTypeList.get(j).getBillNumber()));
186                     paraGraph.add(Chunk.NEWLINE);
187                 }
188                 for (OleItemLevelBillPayment oleItemLevelBillPayment : oleItemLevelBillPayments) {
189                     boolean isAddContent = false;
190                     if(isDefaultPrint){
191                         if(transactionIds.contains(oleItemLevelBillPayment.getPaymentId())){
192                             isAddContent=true;
193                         }
194                     }  else {
195                         isAddContent=true;
196                     }
197                     if (isAddContent) {
198                         paraGraph.add(populateParagraphCell(OLEConstants.OlePatronBill.LABEL_PATRON_RECEIPT_NUMBER,oleItemLevelBillPayment.getPaymentId() != null ? oleItemLevelBillPayment.getPaymentId() : " "));
199                         paraGraph.add(Chunk.NEWLINE);
200                         paraGraph.add(populateParagraphCell(OLEConstants.OlePatronBill.LABEL_BILL_NUMBER,feeTypeList.get(j).getBillNumber() != null ? feeTypeList.get(j).getBillNumber() : " "));
201                         paraGraph.add(Chunk.NEWLINE);
202                         paraGraph.add(populateParagraphCell(OLEConstants.OlePatronBill.LABEL_FEE_TYPE,feeTypeName));
203                         paraGraph.add(Chunk.NEWLINE);
204                         paraGraph.add(populateParagraphCell(OLEConstants.OlePatronBill.LABEL_TRANSACTION_DATE,(oleItemLevelBillPayment.getPaymentDate() != null ? df.format(oleItemLevelBillPayment.getPaymentDate()) : " ")));
205                         paraGraph.add(Chunk.NEWLINE);
206                         paraGraph.add(populateParagraphCell(OLEConstants.OlePatronBill.LABEL_OPERATOR_ID,oleItemLevelBillPayment.getCreatedUser() != null ? oleItemLevelBillPayment.getCreatedUser() : " "));
207                         paraGraph.add(Chunk.NEWLINE);
208                         paraGraph.add(populateParagraphCell(OLEConstants.OlePatronBill.LABEL_ITEM_BARCODE,feeTypeList.get(j).getItemBarcode() != null ? feeTypeList.get(j).getItemBarcode() : " "));
209                         paraGraph.add(Chunk.NEWLINE);
210                         paraGraph.add(populateParagraphCell(OLEConstants.OlePatronBill.LABEL_ITEM_TITLE,feeTypeList.get(j).getItemTitle() != null ? feeTypeList.get(j).getItemTitle() : " "));
211                         paraGraph.add(Chunk.NEWLINE);
212                         paraGraph.add(populateParagraphCell(OLEConstants.OlePatronBill.LABEL_ITEM_AUTHOR,feeTypeList.get(j).getItemAuthor() != null ? feeTypeList.get(j).getItemAuthor() : " "));
213                         paraGraph.add(Chunk.NEWLINE);
214                         paraGraph.add(populateParagraphCell(OLEConstants.OlePatronBill.LABEL_ITEM_CALL_NUMBER,feeTypeList.get(j).getItemCallNumber() != null ? feeTypeList.get(j).getItemCallNumber() : " "));
215                         paraGraph.add(Chunk.NEWLINE);
216                         paraGraph.add(populateParagraphCell(OLEConstants.OlePatronBill.LABEL_TOTAL_AMOUNT,feeTypeList.get(j).getFeeAmount() != null ? CurrencyFormatter.getSymbolForCurrencyPattern()+feeTypeList.get(j).getFeeAmount().toString() : CurrencyFormatter.getSymbolForCurrencyPattern()+"0"));
217                         paraGraph.add(Chunk.NEWLINE);
218                         paraGraph.add(populateParagraphCell(OLEConstants.OlePatronBill.LABEL_PAID_AMOUNT,oleItemLevelBillPayment.getAmount() != null ? CurrencyFormatter.getSymbolForCurrencyPattern()+oleItemLevelBillPayment.getAmount().toString() : CurrencyFormatter.getSymbolForCurrencyPattern()+"0"));
219                         paraGraph.add(Chunk.NEWLINE);
220                         paraGraph.add(populateParagraphCell(OLEConstants.OlePatronBill.LABEL_TRANSACTION_NUMBER,oleItemLevelBillPayment.getTransactionNumber() != null ? oleItemLevelBillPayment.getAmount().toString() : " "));
221                         paraGraph.add(Chunk.NEWLINE);
222                         paraGraph.add(populateParagraphCell(OLEConstants.OlePatronBill.LABEL_TRANSACTION_NOTE,oleItemLevelBillPayment.getTransactionNote() != null ? oleItemLevelBillPayment.getTransactionNumber() : " "));
223                         paraGraph.add(Chunk.NEWLINE);
224                         paraGraph.add(populateParagraphCell(OLEConstants.OlePatronBill.LABEL_PAYMENT_MODE,oleItemLevelBillPayment.getPaymentMode() != null ? oleItemLevelBillPayment.getTransactionNote() : " "));
225                         paraGraph.add(Chunk.NEWLINE);
226                         paraGraph.add(populateParagraphCell(OLEConstants.OlePatronBill.LABEL_NOTE,feeTypeList.get(j).getGeneralNote() != null ? feeTypeList.get(j).getGeneralNote() : " "));
227                         paraGraph.add(Chunk.NEWLINE);
228                         feeAmount = feeAmount.add(feeTypeList.get(j).getFeeAmount().bigDecimalValue());
229                         billNumber = feeTypeList.get(j).getBillNumber();
230                         paidAmount=paidAmount.add(oleItemLevelBillPayment.getAmount().bigDecimalValue());
231                     }
232 
233                 }
234             }
235 
236 
237             paraGraph.add(Chunk.NEWLINE);
238             paraGraph.add(new Chunk(OLEConstants.TOT_AMT + " : " +CurrencyFormatter.getSymbolForCurrencyPattern()+ feeAmount.subtract(paidAmount)!=null?feeAmount.subtract(paidAmount).toString():"0" + "", printFontMap.get("Total_Font")).setBackground(printColorMap.get("Total_BGColor")));
239             response.setContentType("application/pdf");
240             ServletOutputStream sos = response.getOutputStream();
241             PdfWriter.getInstance(document, sos);
242             document.open();
243             document.add(paraGraph);
244             document.close();
245             byteArrayOutputStream.flush();
246             byteArrayOutputStream.close();
247             sos.flush();
248             sos.close();
249         } catch (Exception e) {
250             LOG.error("Exception while creating pdf", e);
251         }
252     }
253 
254 
255     public Document getDocument(float f1, float f2, float f3, float f4) {
256         Document document = new Document(PageSize.A4);
257         document.setMargins(f1, f2, f3, f4);
258         return document;
259     }
260 
261     /**
262      * Used to create pdf document for patron bill
263      *
264      * @param patronBillPayments,feeTypeList,response
265      *
266      * @return Void
267      */
268     public void createPdfWithTable(String firstName, String lastName, List<PatronBillPayment> patronBillPayments, List<FeeType> feeTypeList,boolean isDefaultPrint,List<String> transactionIds, HttpServletResponse response) {
269         LOG.debug("Initialize Table pdf Template");
270         OutputStream out = null;
271         ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
272         BigDecimal feeAmount = BigDecimal.valueOf(0);
273         BigDecimal paidAmount = BigDecimal.valueOf(0);
274         try {
275             populateColorMap();
276             populateFontMap();
277             populatePrintColorMap();
278             populatePrintFontMap();
279             response.setContentType("application/pdf");
280             Document document = this.getDocument(0, 0, 0, 0);
281             document.open();
282             document.newPage();
283             PdfPTable pdfTable = new PdfPTable(9);
284             pdfTable.getDefaultCell().setBorder(0);
285             Table table = new Table(15);
286             int headerwidths[] = {5,5,8,9,9,9,20,10,15,7,7,14,15,7,15};
287             table.setWidths(headerwidths);
288             table.setWidth(97);
289             //table.setWidth(100);
290             table.setDefaultVerticalAlignment(Element.ALIGN_TOP);
291             table.setCellsFitPage(true);
292             table.setPadding(1);
293             table.setSpacing(0);
294             table.getMarkupAttributeNames();
295             Paragraph paraGraph = new Paragraph();
296             paraGraph.setAlignment(Element.ALIGN_CENTER);
297             paraGraph.add(new Chunk(OLEConstants.OlePatronBill.HEADER_PATRON_RECEIPT));
298             paraGraph.add(Chunk.NEWLINE);
299             paraGraph.add(Chunk.NEWLINE);
300             paraGraph.add(Chunk.NEWLINE);
301             SimpleDateFormat df=new SimpleDateFormat(OLEConstants.DAT_FORMAT_EFFECTIVE_PRINT);
302             paraGraph.add(new Chunk(OLEConstants.BILL_DT + " : " + df.format(System.currentTimeMillis()) + " "));
303             paraGraph.add(Chunk.NEWLINE);
304             paraGraph.add(new Chunk(OLEConstants.FIRST_NAME + " : " + firstName, printFontMap.get("Patron_Name_Font")));
305             paraGraph.add(Chunk.NEWLINE);
306             paraGraph.add(new Chunk(OLEConstants.LAST_NAME + "  : " + lastName, printFontMap.get("Patron_Name_Font")));
307             paraGraph.add(Chunk.NEWLINE);
308             table.addCell(populateCellHeader(OLEConstants.OlePatronBill.LABEL_PATRON_RECEIPT_NUMBER, Color.gray));
309             table.addCell(populateCellHeader(OLEConstants.OlePatronBill.LABEL_BILL_NUMBER, Color.gray));
310             table.addCell(populateCellHeader(OLEConstants.OlePatronBill.LABEL_FEE_TYPE, Color.gray));
311             table.addCell(populateCellHeader(OLEConstants.OlePatronBill.LABEL_TRANSACTION_DATE, Color.gray));
312             table.addCell(populateCellHeader(OLEConstants.OlePatronBill.LABEL_OPERATOR_ID,Color.gray));
313             table.addCell(populateCellHeader(OLEConstants.OlePatronBill.LABEL_ITEM_BARCODE, Color.gray));
314             table.addCell(populateCellHeader(OLEConstants.OlePatronBill.LABEL_ITEM_TITLE,Color.gray));
315             table.addCell(populateCellHeader(OLEConstants.OlePatronBill.LABEL_ITEM_AUTHOR,Color.gray));
316             table.addCell(populateCellHeader(OLEConstants.OlePatronBill.LABEL_ITEM_CALL_NUMBER,Color.gray));
317             table.addCell(populateCellHeader(OLEConstants.OlePatronBill.LABEL_TOTAL_AMOUNT,Color.gray));
318             table.addCell(populateCellHeader(OLEConstants.OlePatronBill.LABEL_PAID_AMOUNT,Color.gray));
319             table.addCell(populateCellHeader(OLEConstants.OlePatronBill.LABEL_TRANSACTION_NUMBER,Color.gray));
320             table.addCell(populateCellHeader(OLEConstants.OlePatronBill.LABEL_TRANSACTION_NOTE,Color.gray));
321             table.addCell(populateCellHeader(OLEConstants.OlePatronBill.LABEL_PAYMENT_MODE,Color.gray));
322             table.addCell(populateCellHeader(OLEConstants.OlePatronBill.LABEL_NOTE,Color.gray));
323             table.endHeaders();
324 
325             for (FeeType feeType : feeTypeList) {
326 
327                 List<OleItemLevelBillPayment> oleItemLevelBillPayments = new ArrayList<>();
328                 if (feeType.getItemLevelBillPaymentList() != null) {
329                     oleItemLevelBillPayments.addAll(feeType.getItemLevelBillPaymentList());
330                 } else {
331                     Map<String,String> map=new HashMap<String,String>();
332                     map.put("lineItemId",feeType.getId());
333                     List<OleItemLevelBillPayment> itemLevelBillPayments=(List<OleItemLevelBillPayment>)KRADServiceLocator.getBusinessObjectService().findMatching(OleItemLevelBillPayment.class,map);
334                     if(itemLevelBillPayments!=null){
335                         oleItemLevelBillPayments.addAll(itemLevelBillPayments);
336                     }
337                 }
338                 String feeTypeName="";
339                 if(feeType.getOleFeeType()!=null && feeType.getOleFeeType().getFeeTypeName()!=null){
340                     feeTypeName=feeType.getOleFeeType().getFeeTypeName();
341                 }
342 
343                 for (OleItemLevelBillPayment oleItemLevelBillPayment : oleItemLevelBillPayments) {
344                     boolean isAddContent = false;
345                     if(isDefaultPrint){
346                         if(transactionIds.contains(oleItemLevelBillPayment.getPaymentId())){
347                             isAddContent=true;
348                         }
349                     }  else {
350                         isAddContent=true;
351                     }
352                     if (isAddContent) {
353                         table.addCell(populateCell(oleItemLevelBillPayment.getPaymentId() != null ? oleItemLevelBillPayment.getPaymentId() : " "));
354                         table.addCell(populateCell(feeType.getBillNumber() != null ? feeType.getBillNumber() : " "));
355                         table.addCell(populateCell(feeTypeName));
356                         table.addCell(populateCell((oleItemLevelBillPayment.getPaymentDate() != null ? df.format(oleItemLevelBillPayment.getPaymentDate()) : " ")));
357                         table.addCell(populateCell(oleItemLevelBillPayment.getCreatedUser() != null ? oleItemLevelBillPayment.getCreatedUser() : " "));
358                         table.addCell(populateCell(feeType.getItemBarcode() != null ? feeType.getItemBarcode() : " "));
359                         table.addCell(populateCell(feeType.getItemTitle() != null ? feeType.getItemTitle() : " "));
360                         table.addCell(populateCell(feeType.getItemAuthor() != null ? feeType.getItemAuthor() : " "));
361                         table.addCell(populateCell(feeType.getItemCallNumber() != null ? feeType.getItemCallNumber() : " "));
362                         table.addCell(populateCell(feeType.getFeeAmount() != null ? CurrencyFormatter.getSymbolForCurrencyPattern()+feeType.getFeeAmount().bigDecimalValue().setScale(2, BigDecimal.ROUND_HALF_UP) : CurrencyFormatter.getSymbolForCurrencyPattern()+"0"));
363                         table.addCell(populateCell(oleItemLevelBillPayment.getAmount() != null ? CurrencyFormatter.getSymbolForCurrencyPattern()+oleItemLevelBillPayment.getAmount().bigDecimalValue().setScale(2, BigDecimal.ROUND_HALF_UP) : CurrencyFormatter.getSymbolForCurrencyPattern()+"0"));
364                         table.addCell(populateCell(oleItemLevelBillPayment.getTransactionNumber() != null ? oleItemLevelBillPayment.getTransactionNumber() : " "));
365                         table.addCell(populateCell(oleItemLevelBillPayment.getTransactionNote() != null ? oleItemLevelBillPayment.getTransactionNote() : " "));
366                         table.addCell(populateCell(oleItemLevelBillPayment.getPaymentMode() != null ? oleItemLevelBillPayment.getPaymentMode() : " "));
367                         table.addCell(populateCell(feeType.getGeneralNote() != null ? feeType.getGeneralNote() : " "));
368                         feeAmount = feeAmount.add(feeType.getFeeAmount().bigDecimalValue());
369                         paidAmount=paidAmount.add(oleItemLevelBillPayment.getAmount().bigDecimalValue());
370                     }
371 
372                 }
373             }
374             String totaldueAmount=feeAmount.subtract(paidAmount)!=null?feeAmount.subtract(paidAmount).toString():"0";
375          /*   paraGraph.add(new Chunk(OLEConstants.TOT_AMT + " : " + CurrencyFormatter.getSymbolForCurrencyPattern() + totaldueAmount + "",printFontMap.get("Patron_Name_Font")));
376             paraGraph.add(Chunk.NEWLINE);*/
377             paraGraph.add(new Chunk(OLEConstants.TOT_AMT_PAID + " : " + CurrencyFormatter.getSymbolForCurrencyPattern()+ (paidAmount!=null?paidAmount.toString():"0") + "",printFontMap.get("Patron_Name_Font")));
378             paraGraph.add(Chunk.NEWLINE);
379             response.setContentType("application/pdf");
380             ServletOutputStream sos = response.getOutputStream();
381             PdfWriter.getInstance(document, sos);
382             document.open();
383             document.add(paraGraph);
384             document.add(table);
385             document.close();
386             byteArrayOutputStream.flush();
387             byteArrayOutputStream.close();
388         } catch (Exception e) {
389             LOG.error("Exception while creating pdf with table", e);
390         }
391     }
392 
393     private Cell  populateCellHeader(String header,Color color){
394         BaseFont bf=null;
395         Cell cell = new Cell();
396         try {
397             if (header != null) {
398                 bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
399                 float glyphWidth = bf.getWidth(header);
400                 float width = glyphWidth * 0.001f * 16f;
401                 float fontSize = 400 * width / glyphWidth;
402                 Font font=new Font();
403                 font.setSize(fontSize);
404                 cell.addElement(new Paragraph(header,font));
405 
406             }
407         } catch (DocumentException e) {
408             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
409         } catch (IOException e) {
410             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
411         }
412         cell.setBackgroundColor(color);
413         return cell;
414     }
415 
416     private Cell  populateCell(String header){
417         BaseFont bf=null;
418         Cell cell = new Cell();
419         try {
420             if (header != null) {
421                 bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
422                 float glyphWidth = bf.getWidth(header);
423                 float width = glyphWidth * 0.001f * 16f;
424                 float fontSize = 400 * width / glyphWidth;
425                 Font font=new Font();
426                 font.setSize(fontSize);
427                 cell.addElement(new Paragraph(header, font));
428             }
429         } catch (DocumentException e) {
430             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
431         } catch (IOException e) {
432             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
433         }
434         return cell;
435     }
436 
437     private Chunk  populateParagraphCell(String header,String value){
438         return (new Chunk(header+" : " + value ,printFontMap.get("Patron_Name_Font")));
439     }
440 }
441 
442