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