private ByteArrayOutputStream getPdfData(
     JSONArray data, JSONArray res, HttpServletRequest request) throws ServiceException {
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   try {
     String[] colHeader = getColHeader();
     String[] colIndex = getColIndexes();
     String[] val = getColValues(colHeader, data);
     String[] resources = getResourcesColHeader(res, data);
     String[] mainHeader = {"Dates", "Duration", "Work", "Cost", "Tasks", "Resources"};
     Document document = null;
     if (landscape) {
       Rectangle recPage = new Rectangle(PageSize.A4.rotate());
       recPage.setBackgroundColor(new java.awt.Color(255, 255, 255));
       document = new Document(recPage, 15, 15, 30, 30);
     } else {
       Rectangle recPage = new Rectangle(PageSize.A4);
       recPage.setBackgroundColor(new java.awt.Color(255, 255, 255));
       document = new Document(recPage, 15, 15, 30, 30);
     }
     PdfWriter writer = PdfWriter.getInstance(document, baos);
     writer.setPageEvent(new EndPage());
     document.open();
     if (showLogo) {
       getCompanyDetails(request);
       addComponyLogo(document, request);
     }
     addTitleSubtitle(document);
     addTable(data, resources, colIndex, colHeader, mainHeader, val, document);
     document.close();
     writer.close();
     baos.close();
   } catch (ConfigurationException ex) {
     throw ServiceException.FAILURE("ExportProjectReport.getPdfData", ex);
   } catch (DocumentException ex) {
     throw ServiceException.FAILURE("ExportProjectReport.getPdfData", ex);
   } catch (JSONException e) {
     throw ServiceException.FAILURE("ExportProjectReport.getPdfData", e);
   } catch (IOException e) {
     throw ServiceException.FAILURE("ExportProjectReport.getPdfData", e);
   } catch (Exception e) {
     throw ServiceException.FAILURE("ExportProjectReport.getPdfData", e);
   }
   return baos;
 }
 /**
  * @see com.lowagie.text.pdf.PdfPTableEvent#tableLayout(com.lowagie.text.pdf.PdfPTable, float[][],
  *     float[], int, int, com.lowagie.text.pdf.PdfContentByte[])
  */
 public void tableLayout(
     PdfPTable table,
     float[][] widths,
     float[] heights,
     int headerRows,
     int rowStart,
     PdfContentByte[] canvases) {
   float[] width = widths[0];
   Rectangle rect =
       new Rectangle(width[0], heights[heights.length - 1], width[width.length - 1], heights[0]);
   rect.cloneNonPositionParameters(this);
   int bd = rect.getBorder();
   rect.setBorder(Rectangle.NO_BORDER);
   canvases[PdfPTable.BACKGROUNDCANVAS].rectangle(rect);
   rect.setBorder(bd);
   rect.setBackgroundColor(null);
   canvases[PdfPTable.LINECANVAS].rectangle(rect);
 }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    regService = new RegService();
    nuser = (RegForm) form;
    nuser = regService.authenticate(nuser);
    String uname = nuser.getUserName();
    String pwd = nuser.getFpassword();
    String cpwd = nuser.getCpassword();
    String acc = nuser.getAccno();
    String fn = nuser.getFirstName();
    String ln = nuser.getLastName();
    String sx = nuser.getSex();
    String add = nuser.getAddress();
    String co = nuser.getCountry();
    String zp = nuser.getZip();
    String mb = nuser.getMobile();
    String em = nuser.getEmail();

    RegForm regForm = (RegForm) form;
    Rectangle pageSize = new Rectangle(400, 400);
    pageSize.setBackgroundColor(new java.awt.Color(0xDF, 0xFF, 0xDE));
    Document document = new Document(pageSize);
    PdfWriter.getInstance(
        document, new FileOutputStream("D:/kowthal training/java/31rep/Report.pdf"));
    document.open();
    PdfPTable table = new PdfPTable(2);
    table.addCell("UserName");
    table.addCell(uname);
    table.addCell("Password");
    table.addCell(pwd);
    table.addCell("Confirm Password");
    table.addCell(cpwd);
    table.addCell("First Name");
    table.addCell(fn);
    table.addCell("Last Name");
    table.addCell(ln);
    table.addCell("Sex");
    table.addCell(sx);
    table.addCell("Address");
    table.addCell(add);
    table.addCell("Country");
    table.addCell(co);
    table.addCell("Zip Code");
    table.addCell(zp);
    table.addCell("Mobile");
    table.addCell(mb);
    table.addCell("E-mail id");
    table.addCell(em);
    System.out.println("before fetch");
    document.add(table);
    System.out.println("after fetch");
    document.add(new Paragraph("Created by Kowthal(947)"));
    document.close();

    target = "success";
    return mapping.findForward(target);
  }