Example #1
0
 /**
  * Returns the height of the cell.
  *
  * @return the height of the cell
  * @since 3.0.0
  */
 public float getMaxHeight() {
   boolean pivoted = getRotation() == 90 || getRotation() == 270;
   Image img = getImage();
   if (img != null) {
     img.scalePercent(100);
     float refWidth = pivoted ? img.getScaledHeight() : img.getScaledWidth();
     float scale =
         (getRight() - getEffectivePaddingRight() - getEffectivePaddingLeft() - getLeft())
             / refWidth;
     img.scalePercent(scale * 100);
     float refHeight = pivoted ? img.getScaledWidth() : img.getScaledHeight();
     setBottom(getTop() - getEffectivePaddingTop() - getEffectivePaddingBottom() - refHeight);
   } else {
     if ((pivoted && hasFixedHeight()) || getColumn() == null)
       setBottom(getTop() - getFixedHeight());
     else {
       ColumnText ct = ColumnText.duplicate(getColumn());
       float right, top, left, bottom;
       if (pivoted) {
         right = PdfPRow.RIGHT_LIMIT;
         top = getRight() - getEffectivePaddingRight();
         left = 0;
         bottom = getLeft() + getEffectivePaddingLeft();
       } else {
         right = isNoWrap() ? PdfPRow.RIGHT_LIMIT : getRight() - getEffectivePaddingRight();
         top = getTop() - getEffectivePaddingTop();
         left = getLeft() + getEffectivePaddingLeft();
         bottom =
             hasFixedHeight()
                 ? getTop() + getEffectivePaddingBottom() - getFixedHeight()
                 : PdfPRow.BOTTOM_LIMIT;
       }
       PdfPRow.setColumn(ct, left, bottom, right, top);
       try {
         ct.go(true);
       } catch (DocumentException e) {
         throw new ExceptionConverter(e);
       }
       if (pivoted)
         setBottom(
             getTop()
                 - getEffectivePaddingTop()
                 - getEffectivePaddingBottom()
                 - ct.getFilledWidth());
       else {
         float yLine = ct.getYLine();
         if (isUseDescender()) yLine += ct.getDescender();
         setBottom(yLine - getEffectivePaddingBottom());
       }
     }
   }
   float height = getHeight();
   if (height == getEffectivePaddingTop() + getEffectivePaddingBottom()) height = 0;
   if (hasFixedHeight()) height = getFixedHeight();
   else if (hasMinimumHeight() && height < getMinimumHeight()) height = getMinimumHeight();
   return height;
 }
Example #2
0
  private static void imageToPDF(String folder, Collection<Path> all) {

    for (Path path : all) {

      Document document = new Document();

      String absolutePathInput = path.toFile().getAbsolutePath();
      String absolutePathOutput = folder + "/" + path.getFileName() + ".pdf";

      if (absolutePathInput.endsWith(".gif")
          ||
          //
          absolutePathInput.endsWith(".GIF")
          ||
          //
          absolutePathInput.endsWith(".jpg")
          ||
          //
          absolutePathInput.endsWith(".JPG")
          ||
          //
          absolutePathInput.endsWith(".png")
          ||
          //
          absolutePathInput.endsWith(".PNG")) {

        try {
          FileOutputStream fos = new FileOutputStream(absolutePathOutput);
          PdfWriter writer = PdfWriter.getInstance(document, fos);
          writer.open();
          document.open();

          int indentation = 0;

          Image image = Image.getInstance(absolutePathInput);
          float scaler =
              ((document.getPageSize().getWidth()
                          - document.leftMargin()
                          - document.rightMargin()
                          - indentation)
                      / image.getWidth())
                  * 100;

          image.scalePercent(scaler);

          document.add(image);
          document.close();
          writer.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
Example #3
0
  private PdfPTable getHeader() throws DocumentException, IOException {

    PdfPTable table = new PdfPTable(1);

    table.setWidthPercentage(100);

    Image image = Image.getInstance(getClass().getResource("/images/SLA_header.png"));
    image.scalePercent(42);
    PdfPCell cell = new PdfPCell(image);
    cell.setBorder(0);
    cell.setPadding(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);
    return table;
  }
  private static Image getBarcode(Document document, PdfWriter pdfWriter, String servicio) {

    PdfContentByte cimg = pdfWriter.getDirectContent();
    Barcode128 code128 = new Barcode128();
    code128.setCode(servicio);
    code128.setCodeType(Barcode128.CODE128);
    code128.setTextAlignment(Element.ALIGN_CENTER);
    Image image = code128.createImageWithBarcode(cimg, null, null);
    float scaler = (5);
    image.scalePercent(scaler);
    image.setAlignment(Element.ALIGN_CENTER);
    image.scaleAbsoluteWidth(800);

    System.out.print(" Width: " + image.getWidth());
    System.out.println(" Heights: " + image.getHeight());
    return image;
  }
  @Override
  public void addText(PdfPCell cell, String text) {
    String[] parts = text.split("->");

    super.addText(cell, parts[0] + "\n\n");

    try {
      Image image = Image.getInstance("icons/arrow.png");
      image.scalePercent(30F);
      image.setAlignment(Element.ALIGN_CENTER);
      cell.addElement(image);
    } catch (BadElementException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    super.addText(cell, "\n" + parts[1]);
  }
Example #6
0
  /**
   * @param imageUrllist
   * @param mOutputPdfFileName
   * @return
   * @throws FileNotFoundException
   * @throws BadElementException
   * @throws MalformedURLException
   * @throws DocumentException
   * @throws IOException
   */
  public static File convertPicToPdf(List<String> imageUrllist, String mOutputPdfFileName)
      throws FileNotFoundException, BadElementException, MalformedURLException, DocumentException,
          IOException {
    Document doc = new Document(PageSize.A4, 10, 10, 10, 10);
    FileOutputStream fileOutputStream = new FileOutputStream(mOutputPdfFileName);
    PdfWriter.getInstance(doc, fileOutputStream);
    float height, width;
    Image image;
    int percent;
    doc.open();
    for (String string : imageUrllist) {
      doc.newPage();
      image = Image.getInstance(string);
      image.setAlignment(Image.MIDDLE);
      height = image.getHeight();
      width = image.getWidth();
      if (readPictureDegree(string) == 90) {
        // 如果图片需要旋转,设置高度为宽度,宽度为高度
        height = image.getWidth();
        width = image.getHeight();
      }
      // 旋转图片
      image.setRotationDegrees(-readPictureDegree(string));
      System.out.println(height);
      System.out.println(width);
      percent = getPercent2(height, width);
      System.out.println(percent);

      image.scalePercent(percent); // 表示是原来图像的比例;
      doc.add(image);
      System.out.println("convert " + string + "successful");
    }
    doc.close();
    File mOutputPdfFile = new File(mOutputPdfFileName);
    if (!mOutputPdfFile.exists()) {
      mOutputPdfFile.deleteOnExit();
      return null;
    }
    return mOutputPdfFile;
  }
Example #7
0
  /**
   * This method handles PUT requests from the client. PUT requests will come from the applet
   * portion of this application and are the way that images and other files can be posted to the
   * server.
   *
   * @param request the HTTP request object
   * @param response the HTTP response object
   * @exception ServletException
   * @exception IOException
   */
  public void doPut(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    HttpSession session = request.getSession();
    /*
     * The Scan applet will zip all the files together to create a
     * faster upload and to use just one server connection.
     */
    ZipInputStream in = new ZipInputStream(request.getInputStream());

    /*
     * This will write all the files to a directory on the server.
     */
    try {
      try {

        File file = new File("scan");
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        String fileSize = null;
        while (true) {
          ZipEntry entry = in.getNextEntry();
          if (entry == null) {
            break;
          }
          File f = File.createTempFile("translate", entry.getName());
          FileOutputStream out = new FileOutputStream(f);
          FileInputStream inStream = null;
          try {
            int read;
            byte[] buf = new byte[2024];

            while ((read = in.read(buf)) > 0) {
              out.write(buf, 0, read);
            }
            out.close();
            inStream = new FileInputStream(f);
            System.out.println(entry.getSize());
            byte[] b = new byte[inStream.available()];
            inStream.read(b);
            System.out.println(b.length);
            com.itextpdf.text.Image image1 = com.itextpdf.text.Image.getInstance(b);
            image1.scalePercent(30);
            image1.setCompressionLevel(9);
            document.add(image1);
          } finally {
          }
        }
        document.close();
        //                fileSize = CommonUtils.getFileSize(file);
        //                DocumentStoreLogDAO documentStoreLogDAO = new DocumentStoreLogDAO();
        //                DocumentStoreLog documentStoreLog = null;
        //                DocumentStoreLog documentStore =
        // (DocumentStoreLog)session.getAttribute(CommonConstants.DOCUMENT_STORE_LOG);
        //                if(null != documentStore) {
        //                    documentStore.setFileSize(fileSize);
        //                }
        //                Transaction tx = documentStoreLogDAO.getSession().getTransaction();
        //                tx.begin();
        //                documentStoreLogDAO.save(documentStore);
        //                tx.commit();
      } catch (ZipException ze) {
        /*
         * We want to catch each sip exception separately because
         * there is a possibility that we can read more files from
         * the archive even if one of them is corrupted.
         */
        ze.printStackTrace();
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      in.close();
    }

    /*
     * Now that we have finished uploading the files
     * we will send a reponse to the server indicating
     * our success.
     */

    response.setContentType(CONTENT_TYPE);
    PrintWriter out = response.getWriter();
    out.println("<html><head><title>ImageSrv</title></head></html>");
    out.flush();
    out.close();
    response.setStatus(HttpServletResponse.SC_OK);
  }
Example #8
0
    @Override
    public void onEndPage(PdfWriter writer, Document document) {
      Rectangle rect = writer.getBoxSize("art");

      Image imghead = null;
      PdfContentByte cbhead = null;

      try {
        imghead = Image.getInstance("LogoSapito5.png");
        imghead.setAbsolutePosition(0, 0);
        imghead.setAlignment(Image.ALIGN_CENTER);
        imghead.scalePercent(10f);
        cbhead = writer.getDirectContent();
        PdfTemplate tp = cbhead.createTemplate(100, 150);
        tp.addImage(imghead);
        cbhead.addTemplate(tp, 100, 715);

      } catch (BadElementException e) {
        e.printStackTrace();
      } catch (DocumentException e) {
        e.printStackTrace();
      } catch (IOException ex) {
        Logger.getLogger(Cuentaspagar.class.getName()).log(Level.SEVERE, null, ex);
      }

      Phrase headPhraseImg =
          new Phrase(cbhead + "", FontFactory.getFont(FontFactory.TIMES_ROMAN, 7, Font.NORMAL));

      Calendar c1 = Calendar.getInstance();
      Calendar c2 = new GregorianCalendar();
      String dia, mes, annio;
      dia = Integer.toString(c1.get(Calendar.DATE));
      mes = Integer.toString(c1.get(Calendar.MONTH));
      annio = Integer.toString(c1.get(Calendar.YEAR));
      java.util.Date fecha = new Date();
      String fechis = dia + "/" + mes + "/" + annio;
      Paragraph parrafo5 =
          new Paragraph(
              fechis,
              FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLACK));
      ColumnText.showTextAligned(
          writer.getDirectContent(),
          Element.ALIGN_CENTER,
          new Phrase(parrafo5),
          rect.getRight(450),
          rect.getTop(-80),
          0);

      Paragraph parrafo7 =
          new Paragraph(
              "Empresa Sapito S.A. de C.V.",
              FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK));
      ColumnText.showTextAligned(
          writer.getDirectContent(),
          Element.ALIGN_CENTER,
          new Phrase(parrafo7),
          rect.getBottom(250),
          rect.getTop(-60),
          0);

      Paragraph parrafo8 =
          new Paragraph(
              "Cuentas por cobrar",
              FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD, BaseColor.BLACK));
      ColumnText.showTextAligned(
          writer.getDirectContent(),
          Element.ALIGN_CENTER,
          new Phrase(parrafo8),
          rect.getBottom(250),
          rect.getTop(-40),
          0);

      ColumnText.showTextAligned(
          writer.getDirectContent(),
          Element.ALIGN_BOTTOM,
          new Phrase(
              "      _________________________________________________________________________________    "),
          rect.getBorder(),
          rect.getTop(-24),
          0);

      ColumnText.showTextAligned(
          writer.getDirectContent(),
          Element.ALIGN_BOTTOM,
          new Phrase(
              "      _________________________________________________________________________________    "),
          rect.getBorder(),
          rect.getTop(-20),
          0);

      Paragraph parrafo6 =
          new Paragraph(
              String.format("Pág %d", writer.getPageNumber()),
              FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLACK));
      ColumnText.showTextAligned(
          writer.getDirectContent(),
          Element.ALIGN_CENTER,
          new Phrase(parrafo6),
          rect.getRight(-35),
          rect.getTop(-80),
          0);
    }
Example #9
0
  public static void createPdf(String filename) throws IOException, DocumentException {
    // step 1
    Document document = new Document(new Rectangle(340, 842));
    // step 2
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
    // step 3
    document.open();
    // step 4
    PdfContentByte cb = writer.getDirectContent();

    String code = "2846510";

    // EAN 13
    document.add(new Paragraph("Barcode EAN.UCC-13"));
    BarcodeEAN codeEAN = new BarcodeEAN();
    /*
    //codeEAN.setCode("4512345678906");
    codeEAN.setCode(code);
    document.add(new Paragraph("default:"));
    document.add(codeEAN.createImageWithBarcode(cb, null, null));
    codeEAN.setGuardBars(false);
    document.add(new Paragraph("without guard bars:"));
    document.add(codeEAN.createImageWithBarcode(cb, null, null));
    codeEAN.setBaseline(-1f);
    codeEAN.setGuardBars(true);
    document.add(new Paragraph("text above:"));
    document.add(codeEAN.createImageWithBarcode(cb, null, null));
    codeEAN.setBaseline(codeEAN.getSize());


    // UPC A
    document.add(new Paragraph("Barcode UCC-12 (UPC-A)"));
    codeEAN.setCodeType(Barcode.UPCA);
    //codeEAN.setCode("785342304749");
    codeEAN.setCode(code);
    document.add(codeEAN.createImageWithBarcode(cb, null, null));


    // EAN 8
    document.add(new Paragraph("Barcode EAN.UCC-8"));
    codeEAN.setCodeType(Barcode.EAN8);
    codeEAN.setBarHeight(codeEAN.getSize() * 1.5f);
    //codeEAN.setCode("34569870");
    codeEAN.setCode(code);
    document.add(codeEAN.createImageWithBarcode(cb, null, null));


    // UPC E
    document.add(new Paragraph("Barcode UPC-E"));
    codeEAN.setCodeType(Barcode.UPCE);
    //codeEAN.setCode("03456781");
    codeEAN.setCode(code);
    document.add(codeEAN.createImageWithBarcode(cb, null, null));
    codeEAN.setBarHeight(codeEAN.getSize() * 3f);


    // EANSUPP
    document.add(new Paragraph("Bookland"));
    document.add(new Paragraph("ISBN 0-321-30474-8"));
    codeEAN.setCodeType(Barcode.EAN13);
    //codeEAN.setCode("9781935182610");
    codeEAN.setCode(code);

    BarcodeEAN codeSUPP = new BarcodeEAN();
    codeSUPP.setCodeType(Barcode.SUPP5);
    //codeSUPP.setCode("55999");
    codeSUPP.setCode(code);
    codeSUPP.setBaseline(-2);
    BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN, codeSUPP);
    document.add(eanSupp.createImageWithBarcode(cb, null, BaseColor.BLUE));
    */

    // CODE 128
    document.add(new Paragraph("Barcode 128"));
    Barcode128 code128 = new Barcode128();
    // code128.setCode("0123456789 hello");
    code128.setCode(code);
    document.add(code128.createImageWithBarcode(cb, null, null));
    code128.setCode("0123456789\uffffMy Raw Barcode (0 - 9)");
    code128.setCodeType(Barcode.CODE128_RAW);
    document.add(code128.createImageWithBarcode(cb, null, null));

    // Data for the barcode :
    String code402 = "24132399420058289";
    String code90 = "3700000050";
    String code421 = "422356";
    StringBuffer data = new StringBuffer(code402);
    data.append(Barcode128.FNC1);
    data.append(code90);
    data.append(Barcode128.FNC1);
    data.append(code421);
    Barcode128 shipBarCode = new Barcode128();
    shipBarCode.setX(0.75f);
    shipBarCode.setN(1.5f);
    shipBarCode.setSize(10f);
    shipBarCode.setTextAlignment(Element.ALIGN_CENTER);
    shipBarCode.setBaseline(10f);
    shipBarCode.setBarHeight(50f);
    shipBarCode.setCode(data.toString());
    document.add(shipBarCode.createImageWithBarcode(cb, BaseColor.BLACK, BaseColor.BLUE));

    // it is composed of 3 blocks whith AI 01, 3101 and 10
    Barcode128 uccEan128 = new Barcode128();
    uccEan128.setCodeType(Barcode.CODE128_UCC);
    uccEan128.setCode("(01)00000090311314(10)ABC123(15)060916");
    document.add(uccEan128.createImageWithBarcode(cb, BaseColor.BLUE, BaseColor.BLACK));
    uccEan128.setCode("0191234567890121310100035510ABC123");
    document.add(uccEan128.createImageWithBarcode(cb, BaseColor.BLUE, BaseColor.RED));
    uccEan128.setCode("(01)28880123456788");
    document.add(uccEan128.createImageWithBarcode(cb, BaseColor.BLUE, BaseColor.BLACK));

    // INTER25
    document.add(new Paragraph("Barcode Interleaved 2 of 5"));
    BarcodeInter25 code25 = new BarcodeInter25();
    code25.setGenerateChecksum(true);
    code25.setCode("41-1200076041-001");
    document.add(code25.createImageWithBarcode(cb, null, null));
    code25.setCode("411200076041001");
    document.add(code25.createImageWithBarcode(cb, null, null));
    code25.setCode("0611012345678");
    code25.setChecksumText(true);
    document.add(code25.createImageWithBarcode(cb, null, null));

    // POSTNET
    document.add(new Paragraph("Barcode Postnet"));
    BarcodePostnet codePost = new BarcodePostnet();
    document.add(new Paragraph("ZIP"));
    codePost.setCode("01234");
    document.add(codePost.createImageWithBarcode(cb, null, null));
    document.add(new Paragraph("ZIP+4"));
    codePost.setCode("012345678");
    document.add(codePost.createImageWithBarcode(cb, null, null));
    document.add(new Paragraph("ZIP+4 and dp"));
    codePost.setCode("01234567890");
    document.add(codePost.createImageWithBarcode(cb, null, null));

    document.add(new Paragraph("Barcode Planet"));
    BarcodePostnet codePlanet = new BarcodePostnet();
    codePlanet.setCode("01234567890");
    codePlanet.setCodeType(Barcode.PLANET);
    document.add(codePlanet.createImageWithBarcode(cb, null, null));

    // CODE 39
    document.add(new Paragraph("Barcode 3 of 9"));
    Barcode39 code39 = new Barcode39();
    code39.setCode("ITEXT IN ACTION");
    document.add(code39.createImageWithBarcode(cb, null, null));

    document.add(new Paragraph("Barcode 3 of 9 extended"));
    Barcode39 code39ext = new Barcode39();
    code39ext.setCode("iText in Action");
    code39ext.setStartStopText(false);
    code39ext.setExtended(true);
    document.add(code39ext.createImageWithBarcode(cb, null, null));

    // CODABAR
    document.add(new Paragraph("Codabar"));
    BarcodeCodabar codabar = new BarcodeCodabar();
    codabar.setCode("A123A");
    codabar.setStartStopText(true);
    document.add(codabar.createImageWithBarcode(cb, null, null));

    // PDF417
    document.add(new Paragraph("Barcode PDF417"));
    BarcodePDF417 pdf417 = new BarcodePDF417();
    String text =
        "Call me Ishmael. Some years ago--never mind how long "
            + "precisely --having little or no money in my purse, and nothing "
            + "particular to interest me on shore, I thought I would sail about "
            + "a little and see the watery part of the world.";
    pdf417.setText(text);
    Image img = pdf417.getImage();
    img.scalePercent(50, 50 * pdf417.getYHeight());
    document.add(img);

    document.add(new Paragraph("Barcode Datamatrix"));
    BarcodeDatamatrix datamatrix = new BarcodeDatamatrix();
    datamatrix.generate(text);
    img = datamatrix.createImage();
    document.add(img);

    document.add(new Paragraph("Barcode QRCode"));
    BarcodeQRCode qrcode = new BarcodeQRCode("Moby Dick by Herman Melville", 1, 1, null);
    img = qrcode.getImage();
    document.add(img);

    // step 5
    document.close();
  }
Example #10
0
  public String execute() throws IOException {
    HttpServletResponse response = ServletActionContext.getResponse();
    Voucher cash_voucher = new Voucher();

    try {

      String final_prepared_by = getPrepared_by();
      String final_paid_to_name = getPaid_to_name();
      String final_reason_paid_amount = getReason_paid_amount();
      String final_cash_cheque_no = getCash_cheque_no();
      float ch_amount = getCash_cheque_amount();
      String enter_date_page = getDate();
      // System.out.println("enter_date in setter method"+enter_date_page);

      String payment_type_final = getCheck();
      // System.out.println("payment_type_final"+payment_type_final);

      SimpleDateFormat simpleDateFormat3 = new SimpleDateFormat("yyyy-MM-dd");
      java.util.Date tempDate3 = simpleDateFormat3.parse(enter_date_page);
      SimpleDateFormat outputDateFormat4 = new SimpleDateFormat("dd/MMM/YYYY");
      Object from_date3 = outputDateFormat4.format(tempDate3);
      // System.out.println("you need to enter date is " + from_date3);

      response.setContentType("application/pdf");
      Document document = new Document(PageSize.A4, 3, 3, 50, 50);

      ByteArrayOutputStream baos = new ByteArrayOutputStream();

      PdfWriter pdfWriter = PdfWriter.getInstance(document, baos);
      document.open();

      int cont =
          cash_voucher.e_voucher_entry(
              final_paid_to_name,
              final_reason_paid_amount,
              payment_type_final,
              final_cash_cheque_no,
              ch_amount,
              from_date3,
              final_prepared_by);

      if (cont > 0) {

        String voucher_no = "";
        String emp_name = "";
        String reason_to_pay = "";
        String payment_type = "";

        String cheque_no = "";
        String amount = "";
        String enter_date = "";
        String prepared_by = "";

        String sys_date = "";

        ArrayList<String> data = cash_voucher.getting_data_voucher();
        if (data.size() > 0) {
          for (int m = 0; m < data.size(); m++) {
            String fandf_data = data.get(m).toString();

            String reg_arr[] = fandf_data.split("\\^");

            voucher_no = reg_arr[0];
            emp_name = reg_arr[1];
            reason_to_pay = reg_arr[2];
            payment_type = reg_arr[3];

            cheque_no = reg_arr[4];
            amount = reg_arr[5];
            enter_date = reg_arr[6];
            prepared_by = reg_arr[7];

            sys_date = reg_arr[8];
          }
        }

        String detailed_rupees = ConvertRupeesintoWords.NumberToWord(amount);
        String final_amount_words = detailed_rupees + "Rupees only";
        // PdfPTable table1 = new PdfPTable(new float[] { 7, 3 });

        Image image1 =
            Image.getInstance(
                "https://lh6.googleusercontent.com/-UiPLWs8CC8A/U2iMqI16btI/AAAAAAAAAFI/MsD-9T20XPI/s160-k-no/");

        image1.scalePercent(20);

        PdfPTable table = new PdfPTable(new float[] {2, 7, 5});
        PdfPCell cell;

        PdfPCell cell2 = new PdfPCell();

        cell2.addElement(new Chunk(image1, 5, -5));
        // cell2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
        // cell2.setBorder(Rectangle.TOP);

        // cell2.setBorder(Rectangle.BOTTOM);
        // cell2.setBorder(Rectangle.RIGHT);
        cell2.setRowspan(2);
        table.addCell(cell2);

        Chunk reportTitle = new Chunk("Nali Clock Software Solutions Pvt.Ltd." + "\n", bigbold);
        reportTitle.setUnderline(0.1f, -2f); // 0.1 thick, -2 y-location

        Chunk sbpart = new Chunk("Patnering With Global Leadres" + "\n " + "\n ", italic);
        Chunk add1 =
            new Chunk("#308/287,Above DTDC Courier, Konappana Agrahara," + "\n", smallBold);

        Chunk add2 = new Chunk("Hosur Main Road, Bangalore - 560100" + "\n", smallBold);

        Phrase phrase = new Phrase();
        phrase.add(reportTitle);
        phrase.add(sbpart);
        phrase.add(add1);
        phrase.add(add2);

        Paragraph para = new Paragraph();
        para.add(phrase);

        cell = new PdfPCell(new Phrase(para));
        // cell.setBorder(Rectangle.RIGHT);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        // cell.setBorder(Rectangle.TOP);

        cell.setRowspan(2);
        table.addCell(cell);

        /*  cell=new PdfPCell(new Phrase("CASH / VOUCHER ",bigbold));
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);*/

        Font font = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, BaseColor.WHITE);

        Chunk vouch = new Chunk("CASH / VOUCHER ", font);
        Phrase phrase_vouch = new Phrase();
        phrase_vouch.add(vouch);
        Paragraph para_voch = new Paragraph();
        // para_voch.FontFactory.getFont(new Color(0x00, 0x00, 0xFF));
        para_voch.add(phrase_vouch);

        cell = new PdfPCell(new Phrase(para_voch));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(BaseColor.GRAY);
        /*cell.setRowspan(2);*/
        table.addCell(cell);

        Chunk vrno = new Chunk("Vr. No :" + voucher_no + "\n" + "\n", catFont);

        Chunk date = new Chunk("Date :" + sys_date, catFont);
        Phrase phrase2 = new Phrase();
        phrase2.add(vrno);
        phrase2.add(date);

        Paragraph para2 = new Paragraph();
        para2.add(phrase2);

        cell = new PdfPCell(new Phrase(para2));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);

        document.add(table);

        PdfPTable table2 = new PdfPTable(new float[] {10, 3, 1});

        cell = new PdfPCell(new Phrase("Particulars", bigbold));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table2.addCell(cell);

        cell = new PdfPCell(new Phrase("Rs.", bigbold));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table2.addCell(cell);

        cell = new PdfPCell(new Phrase("Ps.", bigbold));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table2.addCell(cell);

        Chunk paid_to = new Chunk("Paid to :" + emp_name + "\n" + "\n", catFont);

        Chunk towards = new Chunk("Towards :" + reason_to_pay + "\n" + "\n", catFont);

        Chunk cash =
            new Chunk(
                "Cash / Cheque No. :"
                    + cheque_no
                    + "                                        "
                    + "Date : "
                    + enter_date,
                catFont);

        Phrase phrase3 = new Phrase();
        phrase3.add(paid_to);
        phrase3.add(towards);
        phrase3.add(cash);

        Paragraph para3 = new Paragraph();
        para3.add(phrase3);

        cell = new PdfPCell(new Phrase(para3));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table2.addCell(cell);

        table2.addCell(new Phrase(" ", bigbold));
        table2.addCell(new Phrase(" ", bigbold));

        Chunk rupees = new Chunk("Rupees in words :" + final_amount_words + "\n", catFont);

        Chunk total =
            new Chunk(
                "                                                                                         Total :"
                    + " "
                    + "\n",
                bigbold);

        Phrase phrase4 = new Phrase();
        phrase4.add(rupees);
        Phrase phrase5 = new Phrase();

        phrase5.add(total);

        Paragraph para4 = new Paragraph();
        para4.setAlignment(com.itextpdf.text.Element.ALIGN_LEFT);

        para4.add(phrase4);

        Paragraph para5 = new Paragraph();
        para5.setAlignment(com.itextpdf.text.Element.ALIGN_RIGHT);
        para5.setIndentationRight(70);
        para5.add(phrase5);

        Paragraph para6 = new Paragraph();
        para6.add(para4);
        para6.add(para5);

        cell = new PdfPCell(new Phrase(para6));

        table2.addCell(cell);

        Chunk amt = new Chunk(" " + amount, bigbold);

        Phrase ph_amt = new Phrase();
        ph_amt.add(amt);
        Paragraph para_amt = new Paragraph();
        para_amt.add(ph_amt);
        cell = new PdfPCell(new Phrase(para_amt));
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        table2.addCell(cell);

        table2.addCell(new Phrase(" " + " ", bigbold));

        cell =
            new PdfPCell(
                new Phrase(
                    "Prepared By                   Checked By                        Authorized By                              Receiver's Signature "
                        + "\n "
                        + "\n "
                        + "\n ",
                    catFont));

        cell.setColspan(3);
        cell.setRowspan(2);
        table2.addCell(cell);
        document.add(table2);
      } else {
        PdfPCell cell_final;
        PdfPTable ta_final = new PdfPTable(new float[] {2, 7, 5});

        cell_final = new PdfPCell(new Phrase("Record is not inserted Please try Again", smallBold));
        cell_final.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell_final.setColspan(3);
        ta_final.addCell(cell_final);
        document.add(ta_final);
      }

      document.close();

      pdfWriter.close();
      document.close();

      response.setContentLength(baos.size());
      response.addHeader("Content-Disposition", "attachment; filename=\"cash voucher.pdf\"");
      OutputStream out = response.getOutputStream();
      out = response.getOutputStream();
      baos.writeTo(out);
      out.flush();
      out.close();

    } catch (Exception e) {
      System.out.println("problem in generating pdf for  cash e voucher");
      System.err.println("exception in print==" + e.getMessage());
      e.printStackTrace();
    }
    inputStream.close();
    return "SUCCESS";
  }