Example usage for com.itextpdf.text Chunk Chunk

List of usage examples for com.itextpdf.text Chunk Chunk

Introduction

In this page you can find the example usage for com.itextpdf.text Chunk Chunk.

Prototype

public Chunk(final DrawInterface separator) 

Source Link

Document

Creates a separator Chunk.

Usage

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private byte[] createModelPages(Contact contact, List<Model> models, Toc tableOfContents)
        throws IOException, DocumentException {

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    Document document = iTextUtil.createNewDocument();
    PdfWriter writer = PdfWriter.getInstance(document, bos);

    document.open();//from www  .  j  a  va  2 s. c  om

    // create a PdfPTable for every model (so we can measure the height)
    final List<PdfPTable> modelPageTables = new ArrayList<>();
    Collections.sort(models);
    for (Model model : models) {
        if (model != null) {
            modelPageTables.add(createModelPage(contact, model, writer));
        }
    }

    // put the PdfPTable Models tables on PDF pages (multiple per page if possible)
    byte[] pages = new byte[] {};

    int height = 0;
    List<String> pageNames = new ArrayList<>();

    int i = 0;
    for (PdfPTable modelPageTable : modelPageTables) {

        // create a new pdf page, if necessary
        if (height != 0 && (height + modelPageTable.getTotalHeight()
                + 20 /* for the line separator */ ) >= iTextUtil.PAGE_HEIGHT) {

            writer.close();
            document.close();
            bos.close();

            byte[] page = bos.toByteArray();
            tableOfContents.addEntries(2, pageNames, page, true,
                    Toc.MODEL_SORT_PREFIX + "___" + IntUtil.format(++i));
            pages = iTextUtil.merge(pages, page);

            height = 0;
            pageNames.clear();
            bos = new ByteArrayOutputStream();
            document = iTextUtil.createNewDocument();
            writer = PdfWriter.getInstance(document, bos);

            document.open();

        } else if (height != 0) {
            // if not the first model on the page, draw a separator

            document.add(new Paragraph(
                    new Chunk(new LineSeparator(.25f, 80f, BaseColor.LIGHT_GRAY, Element.ALIGN_CENTER, -2))));
            document.add(new Paragraph(new Chunk("   ")));
        }

        // rerender the table (with a valid pdfWriter)
        document.add(createModelPage(contact, models.get(modelPageTables.indexOf(modelPageTable)), writer));
        height += modelPageTable.getTotalHeight();
        pageNames.add(models.get(modelPageTables.indexOf(modelPageTable)).getProductNameProcessed());

    }
    writer.close();
    document.close();

    byte[] page = bos.toByteArray();
    tableOfContents.addEntries(2, pageNames, page, true, Toc.MODEL_SORT_PREFIX + "___" + IntUtil.format(++i));
    pages = iTextUtil.merge(pages, page);

    return pages;

}

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private byte[] enableLinkToWebsite(byte[] pdf, Toc tableOfContents) throws IOException, DocumentException {

    try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) {

        final PdfReader reader = new PdfReader(pdf);

        final PdfStamper stamper = new PdfStamper(reader, bos);

        for (int i = tableOfContents.getFirstPageOfToc(); i <= tableOfContents
                .getLastPageNumberOfModelPages(); i++) {

            final Chunk websiteChunk = new Chunk("..................");
            websiteChunk.setAction(new PdfAction(websiteLink));

            ColumnText ct = new ColumnText(stamper.getUnderContent(i));
            ct.setSimpleColumn(335, 10, 400, 35);
            ct.addText(new Phrase(websiteChunk));
            ct.go();/*w w w  . j  a  v  a2 s. com*/

            final Chunk emailChunk = new Chunk(".........................................");
            emailChunk.setAction(new PdfAction(emailLink));

            ct = new ColumnText(stamper.getUnderContent(i));
            ct.setSimpleColumn(240, 10, 330, 35);
            ct.addText(new Phrase(emailChunk));
            ct.go();

        }

        stamper.close();
        reader.close();
        return bos.toByteArray();

    }

}

From source file:bestdeal.util.genererPdf.java

public static void main(String[] args) {
    // - Paramtres de connexion  la base de donnes
    Connection connection;//  w ww .j  ava 2s .  c o m
    String[][] data = new String[][] { { " ", " ", " ", " ", " " }, { " ", " ", " ", " ", " " },
            { " ", " ", " ", " ", " " }, };

    try {
        String requete = "select c.nom,c.prenom,c.email,k.nom,k.prenom,k.telephone,k.adresse,k.email,d.id_deal,d.nom_deal,v.quantite,v.prix_unitaire from client c INNER JOIN voucher v on v.id_client=c.id_client INNER JOIN deal d on v.id_deal=d.id_deal INNER JOIN vendeur k on d.id_vendeur=k.id_vendeur";
        connection = MyConnection.getInstance();
        mypdf = new Document(PageSize.A4, 50, 50, 50, 50);
        File di = new File("C:/Voucher");
        File fl[] = di.listFiles();
        try {
            OutputStream file = new FileOutputStream(new File("C:/Voucher\\Voucher.pdf"));
            PdfWriter.getInstance(mypdf, file);

            mypdf.open();
            Statement stm;

            mypdf.addAuthor("Best Deal");
            mypdf.addSubject("Voucher ");
            mypdf.add(new Paragraph("Socite BestDeal"));
            mypdf.add(new Paragraph("Adresse La Chotrana ESPRIT "));
            mypdf.add(new Paragraph("TEL : xx xxx xxx"));
            mypdf.add(new Paragraph("FAX : xx xxx xxx"));
            mypdf.add(new Paragraph(
                    "                                                                                                       "
                            + new Date().toString()));
            mypdf.add(new Paragraph("  "));
            mypdf.add(new Paragraph("                                   " + "Voucher N'01",
                    FontFactory.getFont(FontFactory.HELVETICA, 21, Font.BOLDITALIC)));
            mypdf.add(new Paragraph("  "));

            mypdf.add(new Paragraph("CLIENT :",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC)));
            try {
                stm = connection.createStatement();
                ResultSet rs = stm.executeQuery(requete);

                while (rs.next()) {
                    // add a country to the document as a Chunk
                    //mypdf.add(new Chunk(rs.getString("quantite")));
                    Phrase p = new Phrase("Nom:   ");
                    Phrase p2 = new Phrase(new Chunk(rs.getString("nom")));
                    Paragraph pa = new Paragraph();
                    pa.add(p);
                    pa.add(p2);
                    mypdf.add(pa);

                    Phrase p3 = new Phrase("Prenom:  ");
                    Phrase p4 = new Phrase(new Chunk(rs.getString("prenom")));
                    Paragraph pa1 = new Paragraph();
                    pa1.add(p3);
                    pa1.add(p4);
                    mypdf.add(pa1);

                    Phrase p5 = new Phrase("Adresse:  ");
                    Phrase p6 = new Phrase(new Chunk(rs.getString("adresse")));
                    Paragraph pa2 = new Paragraph();
                    pa2.add(p5);
                    pa2.add(p6);
                    mypdf.add(pa2);

                    Phrase p7 = new Phrase("Tlphone:  ");
                    Phrase p8 = new Phrase(new Chunk(rs.getString("telephone")));
                    Paragraph pa3 = new Paragraph();
                    pa3.add(p7);
                    pa3.add(p8);
                    mypdf.add(pa3);

                    mypdf.add(new Paragraph("  "));

                    mypdf.add(new Paragraph("Vendeur :",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC)));

                    Phrase p9 = new Phrase("Nom:  ");
                    Phrase p10 = new Phrase(new Chunk(rs.getString("nom")));
                    Paragraph pa4 = new Paragraph();
                    pa4.add(p9);
                    pa4.add(p10);
                    mypdf.add(pa4);

                    Phrase p11 = new Phrase("Prnom:  ");
                    Phrase p12 = new Phrase(new Chunk(rs.getString("prenom")));
                    Paragraph pa5 = new Paragraph();
                    pa5.add(p11);
                    pa5.add(p12);
                    mypdf.add(pa5);

                    Phrase p13 = new Phrase("Tlphone:  ");
                    Phrase p14 = new Phrase(new Chunk(rs.getString("telephone")));
                    Paragraph pa6 = new Paragraph();
                    pa6.add(p13);
                    pa6.add(p14);
                    mypdf.add(pa6);

                    Phrase p15 = new Phrase("Adresse:  ");
                    Phrase p16 = new Phrase(new Chunk(rs.getString("adresse")));
                    Paragraph pa7 = new Paragraph();
                    pa7.add(p15);
                    pa7.add(p16);
                    mypdf.add(pa7);

                    Phrase p17 = new Phrase("Email:  ");
                    Phrase p18 = new Phrase(new Chunk(rs.getString("email")));
                    Paragraph pa8 = new Paragraph();
                    pa8.add(p17);
                    pa8.add(p18);
                    mypdf.add(pa8);

                    mypdf.add(new Paragraph("  "));
                    mypdf.add(new Paragraph("  "));
                    mypdf.add(new Paragraph("  "));

                    for (int i = 0; i < rs.getRow(); i++) {
                        for (int j = 0; j < data[i].length - 1; j++) {
                            data[i][j] = rs.getString(j + 9);
                            // if (j==3)
                            //     data[i][4]= Float.parseFloat(data[i][3])*Integer.parseInt(data[i][2])+"";
                        }
                    }

                    for (int i = 0; i < rs.getRow(); i++) {
                        float s = Integer.parseInt(data[i][2].trim()) * Float.parseFloat(data[i][3].trim());
                        data[i][4] = s + "";
                    }

                    //mypdf.add(new Phrase("nom"));
                    //mypdf.add(new  Chunk(rs.getString("nom")));
                    //mypdf.add( new Paragraph("nom:", new Chunk(rs.getString("nom"))));
                    //mypdf.add(new Chunk(" "));
                    //Chunk id = new Chunk(rs.getString("id"));
                    // with a background color
                    //id.setBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f);
                    // and a text rise
                    //id.setTextRise(6);
                    //  mypdf.add(id);
                    mypdf.add(Chunk.NEWLINE);
                }

            } catch (SQLException ex) {
                Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
            }
            // mypdf.add(new Paragraph("Nom "));
            //  mypdf.add(new Paragraph("Prenom "));
            // mypdf.add(new Paragraph("Adresse "));
            //mypdf.add(new Paragraph("Tlphone "));

            // mypdf.add(new Paragraph("Nom "));
            // mypdf.add(new Paragraph("Nom de la socit "));
            //  mypdf.add(new Paragraph("Adresse "));
            // mypdf.add(new Paragraph("Tlphone "));
            // mypdf.add(new Paragraph("  "));

            String[] headers = new String[] { "  Id_deal", "   Nom Deal", "   Quantit", "    Prix unitaire",
                    "   Prix total" };
            PdfPTable table = new PdfPTable(headers.length);
            for (int i = 0; i < headers.length; i++) {
                String header = headers[i];
                PdfPCell cell = new PdfPCell();
                cell.setGrayFill(0.9f);
                cell.setPhrase(new Phrase(header.toUpperCase()));
                table.addCell(cell);
            }
            table.completeRow();
            for (int i = 0; i < data.length; i++) {
                for (int j = 0; j < data[i].length; j++) {
                    String datum = data[i][j];
                    PdfPCell cell = new PdfPCell();
                    cell.setPhrase(new Phrase(datum.toUpperCase()));
                    table.addCell(cell);
                }
                table.completeRow();
            }

            mypdf.add(table);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
        }

        mypdf.add(new Paragraph(" "));
        mypdf.add(new Paragraph(" "));
        mypdf.add(new Paragraph(
                "Pour toute question concernant cette facture,veuillez contacter Nom,numro de tlphone,adresse de messagerie ",
                FontFactory.getFont(null, 9, Font.NORMAL)));
        mypdf.add(new Paragraph(
                "                                                      Merci pour votre confiance",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLDITALIC)));
        mypdf.add(new Paragraph("      "));
        mypdf.add(new Paragraph("  "));
        mypdf.add(new Paragraph("  "));

        mypdf.close();

    } catch (DocumentException ex) {
        Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:bussiness.ReportHandler.java

public void BuildSaleReport(double totalCost) {
    try {/*from w w w .ja  va2  s.c  o m*/
        // Se crea el documento
        Document documento = new Document();
        // Se crea el OutputStream para el fichero donde queremos dejar el pdf.
        FileOutputStream ficheroPdf = new FileOutputStream("fichero.pdf");

        // Se asocia el documento al OutputStream y se indica que el espaciado entre
        // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);
        Image imagen = Image.getInstance("logo.jpeg");

        documento.open();
        PdfPTable table = new PdfPTable(2);
        table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
        table.getDefaultCell().setPaddingLeft(60);
        BuildHeaderSaleReport(documento);

        documento.add(new Chunk("\n"));
        documento.add(new Chunk("\n"));
        documento.add(new Chunk("\n"));
        documento.add(new Chunk("\n"));
        documento.add(new Chunk("\n"));
        documento.add(new Chunk("\n"));

        imagen.setAbsolutePosition(110f, 150f);

        BuildBodySaleReport(table, totalCost, documento);

        BuildFooterSaleReport(documento);
        documento.add(imagen);
        documento.close();

    } catch (Exception e) {
        System.err.println("Ocurrio un error: " + e);
        System.exit(-1);
    }
}

From source file:bussiness.ReportHandler.java

public void BuildVeterinaryPrescription(String clientName, String petName, List<Medicine> medicines,
        String comments, Double totalCost) {
    try {// w  w  w  . ja  v  a 2s. c  o  m
        Document veterinaryPrescription = new Document(PageSize.A3.rotate());
        //Tal vez agregar la fecha al nombre de la receta
        FileOutputStream fileOutputStream = new FileOutputStream("prescription.pdf");
        PdfWriter.getInstance(veterinaryPrescription, fileOutputStream).setInitialLeading(20);
        Image logo = Image.getInstance("logo2.png");
        Image division = Image.getInstance("linea.png");
        veterinaryPrescription.open();
        division.setAbsolutePosition(20f, 600f);
        veterinaryPrescription.add(division);
        logo.setAbsolutePosition(400, 50f);
        veterinaryPrescription.add(logo);

        //Encabezado
        BuildHeaderPrescription(veterinaryPrescription, clientName, petName);

        //Cuerpo
        veterinaryPrescription.add(new Chunk("\n"));
        veterinaryPrescription.add(new Chunk("\n"));
        veterinaryPrescription.add(new Chunk("\n"));

        PdfPTable table = new PdfPTable(3);
        table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
        table.getDefaultCell().setPaddingLeft(60);

        BuildBodyPrescription(medicines, veterinaryPrescription, totalCost, table);

        BuildFooterPrescription(veterinaryPrescription, comments);

        veterinaryPrescription.close();
    } catch (Exception e) {
        System.err.println("Ocurrio un error: " + e);
        System.exit(-1);
    }
}

From source file:bussiness.ReportHandler.java

private void BuildHeaderPrescription(Document veterinaryPrescription, String clientName, String petName)
        throws DocumentException, IOException {
    BaseFont baseFont = BaseFont.createFont("Cookie.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED);
    Font font = new Font(baseFont);
    font.setStyle(Font.BOLDITALIC);
    font.setSize(35);/* w  w  w.jav a2s .  c o m*/
    Doctor doctor = SessionManager.getLoggedDoctor();
    Paragraph p1 = new Paragraph("Dr. " + doctor.getName(), font);
    p1.setAlignment(Element.ALIGN_CENTER);
    veterinaryPrescription.add(p1);
    // veterinaryPrescription.add(new Chunk("\n"));

    Font font2 = new Font();
    font2.setSize(20);

    Paragraph p2 = new Paragraph("CEDULA PROFESIONAL  " + doctor.getIdentityCard(), font2);

    p2.setAlignment(Element.ALIGN_CENTER);

    veterinaryPrescription.add(p2);
    veterinaryPrescription.add(new Chunk("\n"));
    Paragraph p3 = new Paragraph("Nombre del cliente: " + clientName, font2);
    veterinaryPrescription.add(p3);
    Paragraph p4 = new Paragraph("Nombre de la mascota: " + petName, font2);
    veterinaryPrescription.add(p4);
}

From source file:bussiness.ReportHandler.java

private void BuildHeaderSaleReport(Document documento) throws DocumentException {

    Date date = new Date();
    Chunk glue = new Chunk(new VerticalPositionMark());
    Paragraph p = new Paragraph(hourdateFormat.format(date));
    p.add(new Chunk(glue));
    p.add("Le atendio: " + Receptionist.name);
    documento.add(p);/*from www . j  a v  a2s.c om*/

}

From source file:bussiness.ReportHandler.java

private void BuildFooterSaleReport(Document documento) throws DocumentException {

    documento.add(new Chunk("\n"));
    documento.add(new Chunk("\n"));
    documento.add(new Chunk("\n"));

    Paragraph p2 = new Paragraph("GRACIAS POR SU PREFERENCIA");
    p2.setAlignment(Element.ALIGN_CENTER);
    Paragraph p3 = new Paragraph("VUELVA PRONTO");
    p3.setAlignment(Element.ALIGN_CENTER);
    documento.add(p2);//www  .j av  a 2 s.  c o  m
    documento.add(p3);
}

From source file:com.alokomkar.aliensonearth.report.AbstractPdfReport.java

/**
 * @param document/*from w  w  w  .  j a  v  a 2 s .c o  m*/
 * Virtual Function for adding Line Separator.
 */
protected void addLineSeperator(Document document) {
    LineSeparator ls = new LineSeparator();
    try {
        document.add(new Chunk(ls));
        document.add(new Phrase("\n"));
    } catch (DocumentException e) {
        e.printStackTrace();
    }

}

From source file:com.carfinance.module.common.controller.DocumentDownloadController.java

/**
 * ???PDF/*from   ww  w.j av a2 s.com*/
 * @param model
 * @param request
 * @param response
 */
@RequestMapping(value = "/pdfcontrace", method = RequestMethod.GET)
public void pdfContrace(Model model, HttpServletRequest request, HttpServletResponse response) {
    String contrace_id_str = request.getParameter("contrace_id");
    long contrace_type = Long.valueOf(request.getParameter("contrace_type"));//??1-2-?
    long vehicle_contrace_id = Long.valueOf(request.getParameter("vehicle_contrace_id"));

    String org_id = "";
    String contrace_no = "";
    String customer_name = "";
    String license_plate = "";
    String vehicle_model = "";
    String engine_no = "";
    String carframe_no = "";
    double guide_price = 0;
    String color = "";
    String begin_time = "";
    String end_time = "";
    String driving_user_name = "";
    String driving_user_license_no = "";
    String daily_price = "";
    String daily_available_km = "";
    String over_km_price = "";
    String over_hour_price = "";
    String month_price = "";
    String month_available_km = "";
    String pre_payment = "";
    String deposit = "";
    String monthly_day = "";
    String vehicle_id = "";

    if (contrace_type == 1) {
        VehicleContraceInfo vehicleContraceInfo = this.vehicleServiceManageService
                .getVehicleContraceInfoById(Long.valueOf(contrace_id_str));
        if (vehicleContraceInfo != null) {
            org_id = String.valueOf(vehicleContraceInfo.getOrg_id());
            contrace_no = vehicleContraceInfo.getContrace_no();
            customer_name = vehicleContraceInfo.getCustomer_name();

            //                List<VehicleContraceVehsInfo> vehsList = this.vehicleServiceManageService.getVehicleContraceVehsListByContraceId(vehicleContraceInfo.getId());
            //                if(vehsList != null) {
            //                    VehicleContraceVehsInfo vehsInfo = vehsList.get(0);
            VehicleContraceVehsInfo vehsInfo = this.vehicleServiceManageService
                    .getContraceVehicleByid(vehicle_contrace_id);
            VehicleInfo vehicleInfo = this.vehicleManageService.getVehicleInfoByid(vehsInfo.getVehicle_id());

            license_plate = vehicleInfo.getLicense_plate();
            vehicle_model = vehicleInfo.getModel();
            engine_no = vehicleInfo.getEngine_no();
            carframe_no = vehicleInfo.getCarframe_no();
            guide_price = vehicleInfo.getGuide_price();
            color = vehicleInfo.getColor();

            driving_user_name = vehsInfo.getDriving_user_name();
            driving_user_license_no = vehsInfo.getDriving_user_license_no();

            daily_price = vehicleInfo.getDaily_price() + "";
            vehicle_id = vehicleInfo.getId() + "";
            //                }

            begin_time = vehicleContraceInfo.getUse_begin();
            end_time = vehicleContraceInfo.getUse_end();

            daily_available_km = vehicleContraceInfo.getDaily_available_km() + "";
            over_km_price = vehicleContraceInfo.getOver_km_price() + "";
            over_hour_price = vehicleContraceInfo.getOver_hour_price() + "";
            month_price = vehicleContraceInfo.getMonth_price() + "";
            month_available_km = vehicleContraceInfo.getMonth_available_km() + "";
            pre_payment = vehicleContraceInfo.getPre_payment() + "";
            deposit = vehicleContraceInfo.getDeposit() + "";
            monthly_day = vehicleContraceInfo.getMonthly_day() + "";
        }
    } else if (contrace_type == 2) {
        PropertyContraceInfo propertyContraceInfo = this.vehicleServiceManageService
                .getPropertyContraceInfoById(Long.valueOf(contrace_id_str));
        if (propertyContraceInfo != null) {
            org_id = String.valueOf(propertyContraceInfo.getOrg_id());
            contrace_no = propertyContraceInfo.getContrace_no();
            customer_name = propertyContraceInfo.getCustomer_name();
        }
    }
    //1.ContentType
    response.setContentType("multipart/form-data");
    //2.????(??a.pdf)
    response.setHeader("Content-Disposition", "attachment;fileName=" + contrace_no + "_" + vehicle_id + ".pdf");

    Document pdfDoc = new Document(PageSize.A4, 50, 50, 50, 50);
    // ?? pdf ?
    try {
        BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", false);

        Font bold_fontChinese = new Font(bfChinese, 18, Font.BOLD, BaseColor.BLACK);
        Font normal_fontChinese = new Font(bfChinese, 12, Font.NORMAL, BaseColor.BLACK);
        Font normal_desc_fontChinese = new Font(bfChinese, 6, Font.NORMAL, BaseColor.BLACK);

        FileOutputStream pdfFile = new FileOutputStream(new File(
                appProps.get("normal.contrace.download.path") + contrace_no + "_" + vehicle_id + ".pdf"));
        // pdf ?
        Paragraph paragraph1 = new Paragraph("???", bold_fontChinese);
        paragraph1.setAlignment(Element.ALIGN_CENTER);

        Chunk customer_name_underline = new Chunk(customer_name);
        customer_name_underline.setUnderline(1f, 3f);

        Chunk license_plate_underline = new Chunk(license_plate);
        license_plate_underline.setUnderline(1f, 3f);

        Chunk vehicle_model_underline = new Chunk(vehicle_model);
        vehicle_model_underline.setUnderline(1f, 3f);

        Chunk engine_no_underline = new Chunk(engine_no);
        engine_no_underline.setUnderline(1f, 3f);

        Chunk carframe_no_underline = new Chunk(carframe_no);
        carframe_no_underline.setUnderline(1f, 3f);

        Chunk guide_price_underline = new Chunk(guide_price / 10000 + "");
        guide_price_underline.setUnderline(1f, 3f);

        Chunk color_underline = new Chunk(color);
        color_underline.setUnderline(1f, 3f);

        Chunk begin_time_underline = new Chunk(begin_time);
        begin_time_underline.setUnderline(1f, 3f);

        Chunk end_time_underline = new Chunk(end_time);
        end_time_underline.setUnderline(1f, 3f);

        Chunk driving_user_name_underline = new Chunk(
                driving_user_name == null ? "___/___" : driving_user_name);
        driving_user_name_underline.setUnderline(1f, 3f);

        Chunk driving_user_license_no_underline = new Chunk(
                driving_user_license_no == null ? "_____/_____" : driving_user_license_no);
        driving_user_license_no_underline.setUnderline(1f, 3f);

        Chunk daily_price_underline = new Chunk(daily_price);
        daily_price_underline.setUnderline(1f, 3f);

        Chunk daily_available_km_underline = new Chunk(daily_available_km);
        daily_available_km_underline.setUnderline(1f, 3f);

        Chunk over_km_price_underline = new Chunk(over_km_price);
        over_km_price_underline.setUnderline(1f, 3f);

        Chunk over_hour_price_underline = new Chunk(over_hour_price);
        over_hour_price_underline.setUnderline(1f, 3f);

        Chunk month_price_underline = new Chunk(month_price == null ? "_____/_____" : month_price);
        month_price_underline.setUnderline(1f, 3f);

        Chunk month_available_km_underline = new Chunk(
                month_available_km == null ? "_____/_____" : month_available_km);
        month_available_km_underline.setUnderline(1f, 3f);

        Chunk pre_payment_underline = new Chunk(pre_payment);
        pre_payment_underline.setUnderline(1f, 3f);

        Chunk deposit_underline = new Chunk(deposit);
        deposit_underline.setUnderline(1f, 3f);

        Chunk monthly_day_underline = new Chunk(monthly_day == null ? "___/___" : monthly_day);
        monthly_day_underline.setUnderline(1f, 3f);

        Paragraph paragraph2 = new Paragraph(
                "???    ???"
                        + contrace_no,
                normal_fontChinese);
        Paragraph paragraph3 = new Paragraph("" + customer_name_underline
                + " (    20____________", normal_fontChinese);
        Paragraph paragraph4 = new Paragraph(
                "??? ??????????",
                normal_fontChinese);
        Paragraph paragraph5 = new Paragraph("???____"
                + license_plate_underline + "____?____" + vehicle_model_underline
                + "________" + color_underline + "____??____" + engine_no_underline
                + "____?____" + carframe_no_underline + "____??____"
                + guide_price_underline + "____", normal_fontChinese);
        Paragraph paragraph6 = new Paragraph("?____" + begin_time_underline
                + "____?____" + end_time_underline + "____",
                normal_fontChinese);
        Paragraph paragraph7 = new Paragraph("??____"
                + driving_user_name_underline + "____??____" + driving_user_license_no_underline
                + "____?", normal_fontChinese);
        Paragraph paragraph8 = new Paragraph("????", normal_fontChinese);
        Paragraph paragraph9 = new Paragraph("1????____" + daily_price_underline
                + "____??____" + daily_available_km_underline
                + "____??____" + over_km_price_underline
                + "____??____" + over_hour_price_underline
                + "____??30????____"
                + month_price_underline + "____??____" + month_available_km_underline
                + "____30",
                normal_fontChinese);
        Paragraph paragraph10 = new Paragraph(
                "2??????8:00---20:00",
                normal_fontChinese);
        Paragraph paragraph11 = new Paragraph(
                "3??????",
                normal_fontChinese);
        Paragraph paragraph12 = new Paragraph(
                "4????____" + pre_payment_underline
                        + "____??____"
                        + monthly_day_underline + "____?",
                normal_fontChinese);
        Paragraph paragraph13 = new Paragraph("5???____"
                + deposit_underline
                + "____(???)???????",
                normal_fontChinese);
        Paragraph paragraph14 = new Paragraph(
                "6????1%????????",
                normal_fontChinese);
        Image image = Image.getInstance(appProps.get("normal.contrace.download.path") + "chekuang.jpg");

        Paragraph paragraph15 = new Paragraph("?", normal_desc_fontChinese);
        Paragraph paragraph16 = new Paragraph(
                "1?????????",
                normal_desc_fontChinese);
        Paragraph paragraph17 = new Paragraph(
                "2????5000?200",
                normal_desc_fontChinese);
        Paragraph paragraph18 = new Paragraph(
                "3????",
                normal_desc_fontChinese);
        Paragraph paragraph19 = new Paragraph(
                "4???????????????",
                normal_desc_fontChinese);
        Paragraph paragraph20 = new Paragraph(
                "5?????????",
                normal_desc_fontChinese);
        Paragraph paragraph21 = new Paragraph(
                "6????????????",
                normal_desc_fontChinese);
        Paragraph paragraph22 = new Paragraph("?", normal_desc_fontChinese);
        Paragraph paragraph23 = new Paragraph(
                "1???????",
                normal_desc_fontChinese);
        Paragraph paragraph24 = new Paragraph(
                "2?????????????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph25 = new Paragraph(
                "3????????????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph26 = new Paragraph(
                "4?????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph27 = new Paragraph(
                "5????????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph28 = new Paragraph(
                "6?????????????????????620%?30%??????????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph29 = new Paragraph(
                "7???????????",
                normal_desc_fontChinese);
        Paragraph paragraph30 = new Paragraph(
                "8????????",
                normal_desc_fontChinese);

        Paragraph paragraph31 = new Paragraph(
                "9??????????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph32 = new Paragraph(
                "10????????????",
                normal_desc_fontChinese);
        Paragraph paragraph33 = new Paragraph(
                "11???????????500-1000",
                normal_desc_fontChinese);
        Paragraph paragraph34 = new Paragraph(
                "12??????????",
                normal_desc_fontChinese);
        Paragraph paragraph35 = new Paragraph(
                "13?????_________________________________7??????????\n",
                normal_desc_fontChinese);
        Paragraph paragraph36 = new Paragraph(
                "14?????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph37 = new Paragraph(
                "15?????????5000????????????????400?500100????",
                normal_desc_fontChinese);
        Paragraph paragraph38 = new Paragraph(
                "16???????????????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph39 = new Paragraph("?", normal_desc_fontChinese);
        Paragraph paragraph40 = new Paragraph(
                "1??????????????",
                normal_desc_fontChinese);
        Paragraph paragraph41 = new Paragraph(
                "2????????????",
                normal_desc_fontChinese);
        Paragraph paragraph42 = new Paragraph(
                "3????",
                normal_desc_fontChinese);
        Paragraph paragraph43 = new Paragraph(
                "4??????????50%?????????",
                normal_desc_fontChinese);
        Paragraph paragraph44 = new Paragraph(
                "5???????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph45 = new Paragraph(
                "6???????????????",
                normal_desc_fontChinese);
        Paragraph paragraph46 = new Paragraph(
                "7?????????50%",
                normal_desc_fontChinese);
        Paragraph paragraph47 = new Paragraph(
                "8???7????????????",
                normal_desc_fontChinese);
        Paragraph paragraph48 = new Paragraph(
                "9???_____/?40??8????_____??",
                normal_desc_fontChinese);
        Paragraph paragraph49 = new Paragraph(
                "10?????___?????",
                normal_desc_fontChinese);
        Paragraph paragraph50 = new Paragraph(
                "11????",
                normal_desc_fontChinese);
        Paragraph paragraph51 = new Paragraph("??", normal_desc_fontChinese);
        Paragraph paragraph52 = new Paragraph(
                "1?????????20%????",
                normal_desc_fontChinese);
        Paragraph paragraph53 = new Paragraph(
                "2???????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph54 = new Paragraph(
                "?????___________________\n",
                normal_desc_fontChinese);
        Paragraph paragraph55 = new Paragraph(
                "???????????????",
                normal_desc_fontChinese);
        Paragraph paragraph56 = new Paragraph(
                "???????",
                normal_desc_fontChinese);
        Paragraph paragraph57 = new Paragraph("?????????",
                normal_desc_fontChinese);
        Paragraph paragraph58 = new Paragraph(
                "???                     ?",
                normal_desc_fontChinese);
        Paragraph paragraph59 = new Paragraph(
                "                                           ???                            ??",
                normal_desc_fontChinese);

        //  Document ?File  PdfWriter ?
        PdfWriter.getInstance(pdfDoc, pdfFile);
        pdfDoc.open(); //  Document 

        // ??
        pdfDoc.add(paragraph1);
        pdfDoc.add(new Chunk("\n\n"));
        pdfDoc.add(paragraph2);
        pdfDoc.add(paragraph3);
        pdfDoc.add(paragraph4);
        pdfDoc.add(paragraph5);
        pdfDoc.add(paragraph6);
        pdfDoc.add(paragraph7);
        pdfDoc.add(paragraph8);
        pdfDoc.add(paragraph9);
        pdfDoc.add(paragraph10);
        pdfDoc.add(paragraph11);
        pdfDoc.add(paragraph12);
        pdfDoc.add(paragraph13);
        pdfDoc.add(paragraph14);
        pdfDoc.add(image);

        pdfDoc.newPage();
        pdfDoc.add(paragraph15);
        pdfDoc.add(paragraph16);
        pdfDoc.add(paragraph17);
        pdfDoc.add(paragraph18);
        pdfDoc.add(paragraph19);
        pdfDoc.add(paragraph20);
        pdfDoc.add(paragraph21);
        pdfDoc.add(paragraph22);
        pdfDoc.add(paragraph23);
        pdfDoc.add(paragraph24);
        pdfDoc.add(paragraph25);
        pdfDoc.add(paragraph26);
        pdfDoc.add(paragraph27);
        pdfDoc.add(paragraph28);
        pdfDoc.add(paragraph29);
        pdfDoc.add(paragraph30);
        pdfDoc.add(paragraph31);
        pdfDoc.add(paragraph32);
        pdfDoc.add(paragraph33);
        pdfDoc.add(paragraph34);
        pdfDoc.add(paragraph35);
        pdfDoc.add(paragraph36);
        pdfDoc.add(paragraph37);
        pdfDoc.add(paragraph38);
        pdfDoc.add(paragraph39);
        pdfDoc.add(paragraph40);
        pdfDoc.add(paragraph41);
        pdfDoc.add(paragraph42);
        pdfDoc.add(paragraph43);
        pdfDoc.add(paragraph44);
        pdfDoc.add(paragraph45);
        pdfDoc.add(paragraph46);
        pdfDoc.add(paragraph47);
        pdfDoc.add(paragraph48);
        pdfDoc.add(paragraph49);
        pdfDoc.add(paragraph50);
        pdfDoc.add(paragraph51);
        pdfDoc.add(paragraph52);
        pdfDoc.add(paragraph53);
        pdfDoc.add(paragraph54);
        pdfDoc.add(paragraph55);
        pdfDoc.add(paragraph56);
        pdfDoc.add(paragraph57);
        pdfDoc.add(paragraph58);
        pdfDoc.add(paragraph59);

        pdfDoc.close();

        ServletOutputStream out;
        //File(?download.pdf)
        File file = new File(
                appProps.get("normal.contrace.download.path") + contrace_no + "_" + vehicle_id + ".pdf");

        try {
            FileInputStream inputStream = new FileInputStream(file);
            //3.response?ServletOutputStream(out)
            out = response.getOutputStream();
            int b = 0;
            byte[] buffer = new byte[512];
            while (b != -1) {
                b = inputStream.read(buffer);
                //4.?(out)
                out.write(buffer, 0, b);
            }
            inputStream.close();
            out.close();
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}