View Javadoc

1   package org.kuali.ole.deliver.loan.printSlip;
2   
3   
4   
5   import com.lowagie.text.*;
6   import com.lowagie.text.Font;
7   import com.lowagie.text.pdf.*;
8   import org.apache.log4j.Logger;
9   import org.kuali.ole.OLEConstants;
10  import org.kuali.ole.deliver.circulationdesk.bo.OleCirculationDesk;
11  import org.kuali.ole.deliver.loan.LoanProcessor;
12  import org.kuali.ole.deliver.loan.bo.OleLoanDocument;
13  import org.kuali.ole.deliver.request.bo.OleDeliverRequestBo;
14  import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.Item;
15  import org.kuali.ole.location.bo.OleLocation;
16  import org.kuali.ole.patron.bo.OlePatronDocument;
17  import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
18  
19  import javax.servlet.ServletOutputStream;
20  import javax.servlet.http.HttpServletResponse;
21  import java.awt.*;
22  import java.io.ByteArrayOutputStream;
23  import java.io.OutputStream;
24  import java.text.SimpleDateFormat;
25  import java.util.*;
26  import java.util.List;
27  
28  /**
29   * The OlePrintSlip  class used to create pdf document .
30   */
31  public class OlePrintSlip extends PdfPageEventHelper {
32  
33      private static final Logger LOG = Logger.getLogger(OlePrintSlip.class);
34  
35      private Map<String, Font> printFontMap = new HashMap<String, Font>();
36  
37      private Map<String, Font> fontMap = new HashMap<String, Font>();
38      private Map<String, Color> colorMap = new HashMap<String, Color>();
39      private Map<String, Color> printColorMap = new HashMap<String, Color>();
40  
41  
42      public void populateFontMap() {
43          fontMap.put("COURIER", new Font(Font.COURIER));
44          fontMap.put("BOLD", new Font(Font.BOLD));
45          fontMap.put("BOLDITALIC", new Font(Font.BOLDITALIC));
46          fontMap.put("DEFAULTSIZE", new Font(Font.DEFAULTSIZE));
47          fontMap.put("HELVETICA", new Font(Font.HELVETICA));
48          fontMap.put("ITALIC", new Font(Font.ITALIC));
49          fontMap.put("NORMAL", new Font(Font.NORMAL));
50          fontMap.put("STRIKETHRU", new Font(Font.STRIKETHRU));
51          fontMap.put("SYMBOL", new Font(Font.SYMBOL));
52          fontMap.put("TIMES_ROMAN", new Font(Font.TIMES_ROMAN));
53          fontMap.put("UNDEFINED", new Font(Font.UNDEFINED));
54          fontMap.put("UNDERLINE", new Font(Font.UNDERLINE));
55          fontMap.put("ZAPFDINGBATS", new Font(Font.ZAPFDINGBATS));
56  
57      }
58  
59      public void populateColorMap() {
60          colorMap.put("WHITE", Color.WHITE);
61          colorMap.put("YELLOW", Color.YELLOW);
62          colorMap.put("BLACK", Color.BLACK);
63          colorMap.put("BLUE", Color.BLUE);
64          colorMap.put("CYAN", Color.CYAN);
65          colorMap.put("DARK_GRAY", Color.DARK_GRAY);
66          colorMap.put("GRAY", Color.GRAY);
67          colorMap.put("GREEN", Color.GREEN);
68          colorMap.put("LIGHT_GRAY", Color.LIGHT_GRAY);
69          colorMap.put("MAGENTA", Color.MAGENTA);
70          colorMap.put("ORANGE", Color.ORANGE);
71          colorMap.put("PINK", Color.PINK);
72          colorMap.put("RED", Color.RED);
73          colorMap.put("PINK", Color.PINK);
74      }
75  
76  
77      /**
78       *  Used to create pdf document for hold slip
79       * @param oleLoanDocument
80       * @return Void
81       */
82      public void createPdfForPrintingSlip( OleLoanDocument oleLoanDocument,HttpServletResponse response) {
83          LOG.debug("Initialize Normal pdf Template");
84          LoanProcessor loanProcessor = new LoanProcessor();
85          OlePatronDocument olePatronDocument = oleLoanDocument!=null?loanProcessor.getOlePatronDocument(oleLoanDocument.getPatronId()):null;
86          if(olePatronDocument!=null){
87              EntityNameBo nameBo = olePatronDocument!=null?olePatronDocument.getEntity().getNames().get(0):null;
88              String patronName = nameBo!=null? nameBo.getFirstName()+","+nameBo.getLastName():null;
89              Date expirationDate =  olePatronDocument!=null?olePatronDocument.getExpirationDate():null;
90  
91              OleLocation oleLocation=null;
92              OleCirculationDesk oleCirculationDesk = null;
93              try {
94                  if(oleLoanDocument.getCirculationLocationId() != null){
95                      oleCirculationDesk = loanProcessor.getOleCirculationDesk(oleLoanDocument.getCirculationLocationId());
96                      oleLocation =oleCirculationDesk!=null?oleCirculationDesk.getOleCirculationDeskLocations().get(0).getLocation():null;
97                  }
98                  String locationName = oleLocation!=null?oleLocation.getLocationName():null;
99                  String itemBarcode = oleLoanDocument.getItemId();
100                 String itemCallNumber = null;
101                 String copyNumber=null;
102                 Item oleItem = oleLoanDocument.getOleItem();
103                 if(oleItem!=null){
104                     itemCallNumber = loanProcessor.getItemCallNumber(oleItem,oleLoanDocument.getInstanceUuid());
105                     copyNumber = oleItem.getCopyNumber();
106 
107                 }else{
108                     Map itemUuid = loanProcessor.getItemDetails(itemBarcode);
109                     Map bibInformation = loanProcessor.getTitleAndAuthorfromBib((String) itemUuid.get(OLEConstants.BIB_UUID));
110                     String itemXml = null;
111                     oleLoanDocument.setInstanceUuid((String) itemUuid.get(OLEConstants.INSTANCE_UUID));
112                     oleLoanDocument.setItemUuid((String) itemUuid.get(OLEConstants.ITEM_UUID));
113                     oleLoanDocument.setTitle((String)bibInformation.get(OLEConstants.TITLE));
114                     oleLoanDocument.setAuthor((String)bibInformation.get(OLEConstants.AUTHOR));
115                     itemXml = loanProcessor.getItemXML(oleLoanDocument.getItemUuid());
116                     oleItem = loanProcessor.getItemPojo(itemXml);
117                     itemCallNumber = loanProcessor.getItemCallNumber(oleItem,oleLoanDocument.getInstanceUuid());
118                     copyNumber = oleItem.getCopyNumber();
119                 }
120                 String itemTitle = oleLoanDocument.getTitle();
121                 OleDeliverRequestBo oleDeliverRequestBo = oleLoanDocument.getOleDeliverRequestBo();
122                 String requestedBy =null;
123                 if(oleDeliverRequestBo!=null){
124                     requestedBy= oleDeliverRequestBo.getBorrowerName();
125                 }
126                 String itemStatus = oleLoanDocument.getItemStatus()!=null?oleLoanDocument.getItemStatus():"";
127                 boolean holdSlip = itemStatus.equalsIgnoreCase(OLEConstants.ITEM_STATUS_ON_HOLD);
128                 boolean inTransitSlip = itemStatus.equalsIgnoreCase(OLEConstants.ITEM_STATUS_IN_TRANSIT);
129                 boolean inTransitForHold = itemStatus.equalsIgnoreCase(OLEConstants.ITEM_STATUS_IN_TRANSIT_HOLD);
130                 boolean inTransitPerStaff = itemStatus.equalsIgnoreCase(OLEConstants.ITEM_STATUS_IN_TRANSIT_STAFF);
131                 boolean missingPieceCheck = itemStatus.equalsIgnoreCase(OLEConstants.ITEM_STATUS_RETURNED_MISSING);
132                 boolean returnedDamaged = itemStatus.equalsIgnoreCase(OLEConstants.ITEM_STATUS_RETURNED_DAMAGED);
133                 boolean claimsReturned = oleLoanDocument.isNoticeForClaimsReturned();
134                 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
135                 populateColorMap();
136                 populateFontMap();
137                 response.setContentType("application/pdf");
138                 OutputStream os = null;
139                 Document document = this.getDocument(0, 0, 5, 5);
140                 if(missingPieceCheck){
141                     os = response.getOutputStream();
142                     PdfWriter.getInstance(document, os);
143                 }
144                 document.open();
145                 document.newPage();
146                 Font boldFont = new Font(Font.TIMES_ROMAN, 15, Font.BOLD);
147                 PdfPTable pdfTable =new PdfPTable(3);
148                 Paragraph paraGraph = new Paragraph();
149                 paraGraph.setAlignment(Element.ALIGN_CENTER);
150                 if(holdSlip){
151                     paraGraph.add(new Chunk("Hold Slip",boldFont));
152                 }else if(inTransitSlip){
153                     paraGraph.add(new Chunk("Routing Slip In-Transit",boldFont));
154                 }else if(inTransitForHold){
155                     paraGraph.add(new Chunk("Routing Slip In-Transit For Hold",boldFont));
156                 }else if(inTransitPerStaff){
157                     paraGraph.add(new Chunk("Routing Slip In-Transit Per Staff Request",boldFont));
158                 }else if(missingPieceCheck){
159                     paraGraph.add(new Chunk("Missing Pieces Notice",boldFont));
160                 }else if (returnedDamaged){
161                     paraGraph.add(new Chunk("Returned Damaged",boldFont));
162                 }else if(claimsReturned){
163                     paraGraph.add(new Chunk("Claims Returned Notice",boldFont));
164                 }else {
165                     paraGraph.add(new Chunk("Receipt(CheckIn) Slip",boldFont));
166                 }
167                 paraGraph.add(Chunk.NEWLINE);
168                 paraGraph.add(Chunk.NEWLINE);
169                 paraGraph.add(Chunk.NEWLINE);
170                 if(holdSlip){
171                     pdfTable.addCell(getPdfPCellInJustified("Patron Name"));
172                     pdfTable.addCell(getPdfPCellInLeft(":"));
173                     pdfTable.addCell(getPdfPCellInJustified(patronName));
174 
175                     pdfTable.addCell(getPdfPCellInJustified("Expiration Date"));
176                     pdfTable.addCell(getPdfPCellInLeft(":"));
177                     pdfTable.addCell(getPdfPCellInJustified(expirationDate.toString()));
178 
179                 } else if(inTransitSlip){
180 
181                     pdfTable.addCell(getPdfPCellInJustified("Route To"));
182                     pdfTable.addCell(getPdfPCellInLeft(":"));
183                     pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.getItemLocation()));
184 
185                     pdfTable.addCell(getPdfPCellInJustified("Date/Time "));
186                     pdfTable.addCell(getPdfPCellInLeft(":"));
187                     pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.getCheckInDate().toString()));
188 
189                 } else if(inTransitForHold){
190 
191                     pdfTable.addCell(getPdfPCellInJustified("Route To"));
192                     pdfTable.addCell(getPdfPCellInLeft(":"));
193                     pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.getItemLocation()));
194 
195                     pdfTable.addCell(getPdfPCellInJustified("Place on hold for"));
196                     pdfTable.addCell(getPdfPCellInLeft(":"));
197                     pdfTable.addCell(getPdfPCellInJustified(requestedBy));
198 
199 
200                     pdfTable.addCell(getPdfPCellInJustified("Date/Time "));
201                     pdfTable.addCell(getPdfPCellInLeft(":"));
202                     pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.getCheckInDate().toString()));
203 
204                 } else if(inTransitPerStaff){
205 
206                     pdfTable.addCell(getPdfPCellInJustified("Route To"));
207                     pdfTable.addCell(getPdfPCellInLeft(":"));
208                     pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.getItemLocation()));
209 
210                     pdfTable.addCell(getPdfPCellInJustified("Requested By"));
211                     pdfTable.addCell(getPdfPCellInLeft(":"));
212                     pdfTable.addCell(getPdfPCellInJustified(requestedBy));
213 
214 
215                     pdfTable.addCell(getPdfPCellInJustified("Date/Time "));
216                     pdfTable.addCell(getPdfPCellInLeft(":"));
217                     pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.getCheckInDate().toString()));
218 
219                 } else if (missingPieceCheck){
220                     document.add(paraGraph);
221                     //Circulation Desk
222                     pdfTable.addCell(getPdfPCellInJustified("Circulation Location / Library Name"));
223                     pdfTable.addCell(getPdfPCellInLeft(":"));
224                     pdfTable.addCell(getPdfPCellInJustified(oleCirculationDesk.getCirculationDeskPublicName()));
225 
226                     pdfTable.addCell(getPdfPCellInJustified("Address"));
227                     pdfTable.addCell(getPdfPCellInLeft(":"));
228                     pdfTable.addCell(getPdfPCellInJustified(oleLocation.getLocationName()));
229 
230                     pdfTable.addCell(getPdfPCellInJustified("Email"));
231                     pdfTable.addCell(getPdfPCellInLeft(":"));
232                     pdfTable.addCell(getPdfPCellInJustified("kuali.ole@org.com"));
233 
234                     pdfTable.addCell(getPdfPCellInJustified("Phone #"));
235                     pdfTable.addCell(getPdfPCellInLeft(":"));
236                     pdfTable.addCell(getPdfPCellInJustified("111-5555"));
237 
238                     document.add(pdfTable);
239                     paraGraph = new Paragraph();
240                     paraGraph.add(Chunk.NEWLINE);
241                     document.add(paraGraph);
242 
243                     //Patron
244                     paraGraph = new Paragraph();
245                     paraGraph.add(new Chunk("Addressee",boldFont));
246                     paraGraph.add(Chunk.NEWLINE);
247                     document.add(paraGraph);
248 
249                     pdfTable =new PdfPTable(3);
250                     pdfTable.addCell(getPdfPCellInJustified("Borrower Name"));
251                     pdfTable.addCell(getPdfPCellInLeft(":"));
252                     pdfTable.addCell(getPdfPCellInJustified(patronName));
253 
254                     pdfTable.addCell(getPdfPCellInJustified("Address"));
255                     pdfTable.addCell(getPdfPCellInLeft(":"));
256                     pdfTable.addCell(getPdfPCellInJustified(""));
257 
258                     pdfTable.addCell(getPdfPCellInJustified("Email"));
259                     pdfTable.addCell(getPdfPCellInLeft(":"));
260                     pdfTable.addCell(getPdfPCellInJustified(olePatronDocument.getEmailAddress()!=null?olePatronDocument.getEmailAddress():""));
261 
262                     pdfTable.addCell(getPdfPCellInJustified("Phone #"));
263                     pdfTable.addCell(getPdfPCellInLeft(":"));
264                     pdfTable.addCell(getPdfPCellInJustified(olePatronDocument.getPhoneNumber()!=null?olePatronDocument.getPhoneNumber():""));
265 
266                     document.add(pdfTable );
267                     //Notice Type
268                     paraGraph = new Paragraph();
269                     paraGraph.add(new Chunk("Return with Missing Piece(s) Notice",boldFont));
270                     paraGraph.setAlignment(Element.ALIGN_CENTER);
271                     paraGraph.add(Chunk.NEWLINE);
272                     document.add(paraGraph);
273 
274 
275                     //Notice-specific text
276                     paraGraph = new Paragraph();
277                     paraGraph.add(new Chunk("The following item(s) returned by you is missing one or more of its pieces.Please return the missing piece(s) to the library shown above or contact the library about this matter to avoid incurring any penalties.",boldFont));
278                     paraGraph.setAlignment(Element.ALIGN_CENTER);
279                     paraGraph.add(Chunk.NEWLINE);
280                     document.add(paraGraph);
281 
282                     //Title/item information
283                     paraGraph = new Paragraph();
284                     paraGraph.add(new Chunk("Title/item information",boldFont));
285                     paraGraph.add(Chunk.NEWLINE);
286                     document.add(paraGraph);
287 
288                     pdfTable =new PdfPTable(3);
289                     pdfTable.addCell(getPdfPCellInJustified("Title"));
290                     pdfTable.addCell(getPdfPCellInLeft(":"));
291                     pdfTable.addCell(getPdfPCellInJustified(itemTitle));
292 
293                     pdfTable.addCell(getPdfPCellInJustified("Author"));
294                     pdfTable.addCell(getPdfPCellInLeft(":"));
295                     pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.getAuthor()));
296 
297                     pdfTable.addCell(getPdfPCellInJustified("Volume/Issue/Copy #"));
298                     pdfTable.addCell(getPdfPCellInLeft(":"));
299                     pdfTable.addCell(getPdfPCellInJustified(copyNumber));
300 
301                     pdfTable.addCell(getPdfPCellInJustified("Library shelving location "));
302                     pdfTable.addCell(getPdfPCellInLeft(":"));
303                     pdfTable.addCell(getPdfPCellInJustified(oleLocation.getLocationName()));
304 
305                     pdfTable.addCell(getPdfPCellInJustified("Call #"));
306                     pdfTable.addCell(getPdfPCellInLeft(":"));
307                     pdfTable.addCell(getPdfPCellInJustified(itemCallNumber));
308 
309                     pdfTable.addCell(getPdfPCellInJustified("Item barcode"));
310                     pdfTable.addCell(getPdfPCellInLeft(":"));
311                     pdfTable.addCell(getPdfPCellInJustified(itemBarcode));
312                     document.add(pdfTable);
313 
314                 }
315                 if (!missingPieceCheck){
316                     pdfTable.addCell(getPdfPCellInJustified("Circulation Location"));
317                     pdfTable.addCell(getPdfPCellInLeft(":"));
318                     pdfTable.addCell(getPdfPCellInJustified(locationName));
319 
320                     pdfTable.addCell(getPdfPCellInJustified("Item Barcode"));
321                     pdfTable.addCell(getPdfPCellInLeft(":"));
322                     pdfTable.addCell(getPdfPCellInJustified(itemBarcode));
323 
324                     pdfTable.addCell(getPdfPCellInJustified("Title"));
325                     pdfTable.addCell(getPdfPCellInLeft(":"));
326                     pdfTable.addCell(getPdfPCellInJustified(itemTitle));
327 
328                     pdfTable.addCell(getPdfPCellInJustified("Call Number"));
329                     pdfTable.addCell(getPdfPCellInLeft(":"));
330                     pdfTable.addCell(getPdfPCellInJustified(itemCallNumber));
331 
332                     pdfTable.addCell(getPdfPCellInJustified("Copy Number"));
333                     pdfTable.addCell(getPdfPCellInLeft(":"));
334                     pdfTable.addCell(getPdfPCellInJustified(copyNumber));
335                     if(!(holdSlip | inTransitSlip | inTransitForHold | inTransitPerStaff)){
336                         pdfTable.addCell(getPdfPCellInJustified("Check-in Date"));
337                         pdfTable.addCell(getPdfPCellInLeft(":"));
338                         pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.getCheckInDate().toString()));
339 
340                         pdfTable.addCell(getPdfPCellInJustified("Patron Barcode"));
341                         pdfTable.addCell(getPdfPCellInLeft(":"));
342                         pdfTable.addCell(getPdfPCellInJustified(olePatronDocument.getBarcode()));
343                     }
344                 }
345                 response.setContentType("application/pdf");
346                 if (!missingPieceCheck){
347                     os =response.getOutputStream();
348                     PdfWriter.getInstance(document, os);
349                     document.open();
350                     document.add(paraGraph);
351                     document.add(pdfTable);
352                     document.close();
353                 }  else {
354                     document.close();
355                 }
356                 byteArrayOutputStream.flush();
357                 byteArrayOutputStream.close();
358                 os.flush();
359                 os.close();
360             } catch (Exception e) {
361                 e.printStackTrace();
362             }
363         }
364     }
365 
366 
367     public void createDueDateSlipPdf(List<OleLoanDocument> oleLoanDocument, HttpServletResponse response) {
368         ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
369 
370         try {
371             populateColorMap();
372             populateFontMap();
373             SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yy");
374             String date = simpleDateFormat.format(System.currentTimeMillis());
375             response.setContentType("application/pdf");
376             Document document = this.getDocument(0, 0, 5, 5);
377             PdfWriter writer = PdfWriter.getInstance(document, byteArrayOutputStream);
378             document.open();
379             document.newPage();
380             Font boldFont = new Font(Font.TIMES_ROMAN, 15, Font.BOLD);
381             PdfPTable pdfTable =new PdfPTable(3);
382             Paragraph paraGraph = new Paragraph();
383             paraGraph.setAlignment(Element.ALIGN_CENTER);
384             paraGraph.add(new Chunk("Due Date Slip",boldFont));
385             paraGraph.add(Chunk.NEWLINE);
386             paraGraph.add(Chunk.NEWLINE);
387             paraGraph.add(Chunk.NEWLINE);
388             LoanProcessor loanProcessor = new LoanProcessor();
389             OleLocation oleLocation=null;
390             try {
391                 OleCirculationDesk oleCirculationDesk = null;
392                 if(oleLoanDocument.get(0).getCirculationLocationId() != null){
393                    oleCirculationDesk = loanProcessor.getOleCirculationDesk(oleLoanDocument.get(0).getCirculationLocationId());
394                 }
395                 oleLocation = oleCirculationDesk.getOleCirculationDeskLocations().get(0).getLocation();
396                // oleLocation = loanProcessor.getLocationByLocationId(oleLoanDocument.get(0).getCirculationLocationId());
397             } catch (Exception e) {
398                 e.printStackTrace();
399             }
400             String locationName = oleLocation!=null?oleLocation.getLocationName():null;
401 
402 
403             for(int dueDateSlip=0;dueDateSlip<oleLoanDocument.size();dueDateSlip++){
404 
405                 pdfTable.addCell(getPdfPCellInJustified("Circulation Location/Library Name"));
406                 pdfTable.addCell(getPdfPCellInLeft(":"));
407                 pdfTable.addCell(getPdfPCellInJustified(locationName));
408 
409                 pdfTable.addCell(getPdfPCellInJustified("Item Barcode"));
410                 pdfTable.addCell(getPdfPCellInLeft(":"));
411                 pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.get(dueDateSlip).getItemId()));
412 
413                 pdfTable.addCell(getPdfPCellInJustified("Title"));
414                 pdfTable.addCell(getPdfPCellInLeft(":"));
415                 pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.get(dueDateSlip).getTitle()));
416 
417                 pdfTable.addCell(getPdfPCellInJustified("Call Number"));
418                 pdfTable.addCell(getPdfPCellInLeft(":"));
419                 pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.get(dueDateSlip).getItemCallNumber()));
420 
421                 pdfTable.addCell(getPdfPCellInJustified("Copy Number"));
422                 pdfTable.addCell(getPdfPCellInLeft(":"));
423                 pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.get(dueDateSlip).getItemCopyNumber()));
424 
425                 pdfTable.addCell(getPdfPCellInJustified("Due Date"));
426                 pdfTable.addCell(getPdfPCellInLeft(":"));
427                 pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.get(dueDateSlip).getLoanDueDate().toString()));
428 
429                 pdfTable.addCell(getPdfPCellInJustified("Patron Barcode"));
430                 pdfTable.addCell(getPdfPCellInLeft(":"));
431                 pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.get(dueDateSlip).getPatronBarcode()));
432 
433 
434 
435                 /*paraGraph.add(Chunk.NEWLINE);
436                 paraGraph.add(Chunk.NEWLINE);
437 */
438                 pdfTable.addCell(getEmptyCell());
439                 pdfTable.addCell(getEmptyCell());
440                 pdfTable.addCell(getEmptyCell());
441 
442                 pdfTable.addCell(getEmptyCell());
443                 pdfTable.addCell(getEmptyCell());
444                 pdfTable.addCell(getEmptyCell());
445             }
446             response.setContentType("application/pdf");
447             ServletOutputStream sos = response.getOutputStream();
448             PdfWriter.getInstance(document, sos);
449             document.open();
450             document.add(paraGraph);
451             document.add(pdfTable);
452             document.close();
453             String fileName = "Due date slip_"+date;
454             ///OutputStream outputStream = new FileOutputStream(""+fileName+".pdf");
455             // byteArrayOutputStream.writeTo(outputStream);
456             byteArrayOutputStream.flush();
457             byteArrayOutputStream.close();
458             sos.flush();
459             sos.close();
460             // outputStream.close();
461         } catch (Exception e) {
462             e.printStackTrace();
463         }
464     }
465 
466     private PdfPCell getEmptyCell(){
467         PdfPCell pdfPCell = new PdfPCell(new Paragraph(Chunk.NEWLINE));
468         pdfPCell.setBorder(pdfPCell.NO_BORDER);
469         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
470         return pdfPCell;
471     }
472 
473     private PdfPCell getPdfPCellInJustified(String chunk){
474         PdfPCell pdfPCell = new PdfPCell(new Paragraph(new Chunk(chunk)));
475         pdfPCell.setBorder(pdfPCell.NO_BORDER);
476         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
477         return pdfPCell;
478     }
479     private PdfPCell getPdfPCellInLeft(String chunk){
480         PdfPCell pdfPCell = new PdfPCell(new Paragraph(new Chunk(chunk)));
481         pdfPCell.setBorder(pdfPCell.NO_BORDER);
482         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
483         return pdfPCell;
484     }
485     public Document getDocument(float f1, float f2, float f3, float f4) {
486         Document document = new Document(PageSize.A4);
487         document.setMargins(f1, f2, f3, f4);
488         return document;
489     }
490 }
491 
492