Example usage for javax.servlet ServletOutputStream close

List of usage examples for javax.servlet ServletOutputStream close

Introduction

In this page you can find the example usage for javax.servlet ServletOutputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes this output stream and releases any system resources associated with this stream.

Usage

From source file:org.openmrs.module.pmtct.util.FileExporter.java

/**
 * Auto generated method comment/*from ww w.  ja v  a 2  s .c o  m*/
 * 
 * @param request
 * @param response
 * @param patientList
 * @param filename
 * @param title
 * @throws Exception
 */
public void exportToCSVFile(HttpServletRequest request, HttpServletResponse response, List<Object> patientList,
        String filename, String title) throws Exception {
    ServletOutputStream outputStream = null;
    try {
        outputStream = response.getOutputStream();
        Patient p;
        PatientService ps = Context.getPatientService();

        response.setContentType("text/plain");
        response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
        outputStream.println("" + title);
        outputStream.println("Number of Patients: " + patientList.size());
        outputStream.println();
        outputStream.println("No.,Identifier, Names, Gender, BirthDay, Enrollment Date, HIV Status");
        outputStream.println();

        int ids = 0;

        for (Object patient : patientList) {
            Object[] o = (Object[]) patient;
            p = ps.getPatient(Integer.parseInt(o[0].toString()));
            ids += 1;
            outputStream.println(ids + "," + p.getActiveIdentifiers().get(0).getIdentifier() + ","
                    + p.getPersonName() + "," + p.getGender() + "," + sdf.format(p.getBirthdate()) + ","
                    + o[3].toString() + ","
                    + pmtctTag.lastObsValueByConceptId(p.getPatientId(), PMTCTConstants.RESULT_OF_HIV_TEST));
        }

        outputStream.flush();
    } catch (Exception e) {
        log.error(e.getMessage());
    } finally {
        if (null != outputStream)
            outputStream.close();
    }
}

From source file:org.akaza.openclinica.control.core.SecureController.java

License:asdf

public void dowloadFile(File f, String contentType) throws Exception {

    response.setHeader("Content-disposition", "attachment; filename=\"" + f.getName() + "\";");
    response.setContentType("text/xml");
    response.setHeader("Pragma", "public");

    ServletOutputStream op = response.getOutputStream();

    DataInputStream in = null;/*from   w  w  w. j  av  a2  s . c o m*/
    try {
        response.setContentType("text/xml");
        response.setHeader("Pragma", "public");
        response.setContentLength((int) f.length());

        byte[] bbuf = new byte[(int) f.length()];
        in = new DataInputStream(new FileInputStream(f));
        int length;
        while (in != null && (length = in.read(bbuf)) != -1) {
            op.write(bbuf, 0, length);
        }

        in.close();
        op.flush();
        op.close();
    } catch (Exception ee) {
        ee.printStackTrace();
    } finally {
        if (in != null) {
            in.close();
        }
        if (op != null) {
            op.close();
        }
    }
}

From source file:org.openmrs.module.pmtct.util.FileExporter.java

/**
 * Auto generated method comment//from   w  w w  .  java  2 s  . c om
 * 
 * @param request
 * @param response
 * @param patientList
 * @param filename
 * @param title
 * @throws Exception
 */
public void exportInfantsTestToCSVFile(HttpServletRequest request, HttpServletResponse response,
        List<Object> patientList, String filename, String title) throws Exception {
    ServletOutputStream outputStream = null;
    try {
        outputStream = response.getOutputStream();
        Patient p;
        Patient mother;
        PatientService ps = Context.getPatientService();

        response.setContentType("text/plain");
        response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
        outputStream.println("" + title);
        outputStream.println("Number of Patients: " + patientList.size());
        outputStream.println();
        outputStream.println("No. ,Identifier, Names, Mother's Names, Gender, Birthdate, Scheduled Visit");
        outputStream.println();

        int ids = 0;

        for (Object patient : patientList) {
            Object[] o = (Object[]) patient;

            p = ps.getPatient(Integer.parseInt(o[0].toString()));
            mother = pmtctTag.getChildMother(p.getPatientId());

            ids += 1;
            outputStream.println(ids + "," + p.getActiveIdentifiers().get(0).getIdentifier() + ","
                    + p.getPersonName() + "," + mother.getPersonName() + "," + p.getGender() + ","
                    + sdf.format(p.getBirthdate()) + "," + sdf.format(o[4]));
        }

        outputStream.flush();
    } catch (Exception e) {
        log.error(e.getMessage());
    } finally {
        if (null != outputStream)
            outputStream.close();
    }
}

From source file:org.kuali.kfs.module.tem.document.web.struts.TravelActionBase.java

/**
 *
 * @param request/*from   www . j a v a  2  s  . co m*/
 * @param response
 * @param reportFile
 * @param fileName
 * @throws IOException
 */
@SuppressWarnings("rawtypes")
protected void displayPDF(HttpServletRequest request, HttpServletResponse response, File reportFile,
        StringBuilder fileName) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    String contentDisposition = "";
    try {
        ArrayList master = new ArrayList();
        PdfCopy writer = null;

        // create a reader for the document
        String reportName = reportFile.getAbsolutePath();
        PdfReader reader = new PdfReader(reportName);
        reader.consolidateNamedDestinations();

        // retrieve the total number of pages
        int n = reader.getNumberOfPages();
        List bookmarks = SimpleBookmark.getBookmark(reader);
        if (bookmarks != null) {
            master.addAll(bookmarks);
        }

        // step 1: create a document-object
        com.lowagie.text.Document pdfDoc = new com.lowagie.text.Document(reader.getPageSizeWithRotation(1));
        // step 2: create a writer that listens to the document
        writer = new PdfCopy(pdfDoc, baos);
        // step 3: open the document
        pdfDoc.open();
        // step 4: add content
        PdfImportedPage page;
        for (int i = 0; i < n;) {
            ++i;
            page = writer.getImportedPage(reader, i);
            writer.addPage(page);
        }
        writer.freeReader(reader);
        if (!master.isEmpty()) {
            writer.setOutlines(master);
        }
        // step 5: we close the document
        pdfDoc.close();

        StringBuffer sbContentDispValue = new StringBuffer();
        String useJavascript = request.getParameter("useJavascript");
        if (useJavascript == null || useJavascript.equalsIgnoreCase("false")) {
            sbContentDispValue.append("attachment");
        } else {
            sbContentDispValue.append("inline");
        }
        sbContentDispValue.append("; filename=");
        sbContentDispValue.append(fileName);

        contentDisposition = sbContentDispValue.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }

    response.setContentType("application/pdf");
    response.setHeader("Content-Disposition", contentDisposition);
    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
    response.setHeader("Pragma", "public");
    response.setContentLength(baos.size());

    // write to output
    ServletOutputStream sos;
    sos = response.getOutputStream();
    baos.writeTo(sos);
    sos.flush();
    sos.close();
}

From source file:com.brick.customer.service.Customer.java

public void exportCustomerInfo(Context context) {
    CustomerInfoExcel cie = new CustomerInfoExcel();
    try {//from w  w w  .  ja v  a  2s .  c o  m
        context.getResponse().setContentType("application/vnd.ms-excel;charset=GB2312");
        context.response.setHeader("Content-Disposition",
                "attachment;filename=" + new String(("?.xls").getBytes("GBK"), "ISO-8859-1"));
        List<HashMap<String, Object>> cusInfo = (List<HashMap<String, Object>>) DataAccessor
                .query("customer.getCustomerInfoList", null, DataAccessor.RS_TYPE.LIST);

        ServletOutputStream out = context.getResponse().getOutputStream();
        context.contextMap.put("sheetName", "?");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("cusInfo", cusInfo);
        cie.createReport(map, context).write(out);
        out.flush();
        out.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.bluexml.xforms.controller.navigation.NavigationManager.java

/**
 * Send image.//www.j av  a  2  s .  co  m
 * 
 * @param req
 *            the req
 * @param resp
 *            the resp
 */
public void sendImage(HttpServletRequest req, HttpServletResponse resp) {
    String location = req.getParameter("location");
    InputStream in = null;
    if (StringUtils.trimToNull(location) != null) {
        boolean isImage = false;
        int lastIndexOf = location.lastIndexOf('.');
        if (lastIndexOf != -1) {
            String extension = location.substring(lastIndexOf).toUpperCase();
            if (extension.endsWith("JPEG") || extension.endsWith("JPG") || extension.endsWith("PNG")
                    || extension.endsWith("BMP") || extension.endsWith("GIF")) {
                isImage = true;
            }
        }
        if (isImage) {
            File sourceFile = null;
            if (location.startsWith("file:")) {
                try {
                    // location = URLEncoder.encode(location, "UTF-8");
                    // URI fileURI = URI.create(location);
                    location = location.replace("file:", "");
                    if (location.charAt(2) == ':') {
                        location = location.subSequence(1, location.length()).toString();
                    }
                    sourceFile = new File(location);
                } catch (Exception e) {
                    sourceFile = null;
                    if (logger.isErrorEnabled()) {
                        logger.error(e);
                    }
                }
            } else {
                sourceFile = new File(AlfrescoController.UPLOAD_DIRECTORY, location);
            }

            try {
                in = new FileInputStream(sourceFile);
            } catch (FileNotFoundException e) {
                if (logger.isErrorEnabled()) {
                    logger.error(e);
                }
            }

        }
    }
    if (in == null) {
        in = NavigationSessionListener.getContext().getResourceAsStream("/resources/images/blank.png");
    }

    ServletOutputStream out = null;

    try {
        out = resp.getOutputStream();
        byte[] bytes = new byte[1024];
        int bytesRead;

        while ((bytesRead = in.read(bytes)) != -1) {
            out.write(bytes, 0, bytesRead);
        }
    } catch (Exception e) {
        if (logger.isErrorEnabled()) {
            logger.error(e);
        }
    } finally {

        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                if (logger.isErrorEnabled()) {
                    logger.error(e);
                }
            }
        }
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                if (logger.isErrorEnabled()) {
                    logger.error(e);
                }
            }
        }
    }

}

From source file:org.etudes.tool.melete.ExportMeleteModules.java

/**
 * writes the zip file to browser//from   w  w  w .ja  va 2  s  .c om
 *
 * @param file -
 *            zip file to download
 * @throws Exception
 */
private void download(File file) throws Exception {
    FileInputStream fis = null;
    ServletOutputStream out = null;
    try {
        String disposition = "attachment; filename=\"" + file.getName() + "\"";
        fis = new FileInputStream(file);

        FacesContext cxt = FacesContext.getCurrentInstance();
        ExternalContext context = cxt.getExternalContext();
        HttpServletResponse response = (HttpServletResponse) context.getResponse();
        response.setContentType("application/zip"); // application/zip
        response.addHeader("Content-Disposition", disposition);
        // Contributed by Diego for ME-233
        response.setHeader("Pragma", "public");
        response.setHeader("Cache-Control", "public, post-check=0, must-revalidate, pre-check=0");

        out = response.getOutputStream();

        int len;
        byte buf[] = new byte[102400];
        while ((len = fis.read(buf)) > 0) {
            out.write(buf, 0, len);
        }

        out.flush();
    } catch (IOException e) {
        throw e;
    } finally {
        try {
            if (out != null)
                out.close();
        } catch (IOException e1) {
        }

        try {
            if (fis != null)
                fis.close();
        } catch (IOException e2) {
        }
    }
}

From source file:org.openmrs.module.pmtct.util.FileExporter.java

/**
 * Auto generated method comment//from  w ww  .ja  v a2  s  .com
 * 
 * @param request
 * @param response
 * @param drugOrderList
 * @param filename
 * @param title
 * @throws Exception
 */
public void exportDrugToCSVFile(HttpServletRequest request, HttpServletResponse response,
        List<DrugOrder> drugOrderList, String filename, String title) throws Exception {
    ServletOutputStream outputStream = null;
    try {
        outputStream = response.getOutputStream();
        Patient p = (drugOrderList != null) ? drugOrderList.get(0).getPatient() : null;
        int count = 0;

        response.setContentType("text/plain");
        response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
        outputStream.println("" + title);
        outputStream.println();

        if (null != p) {
            outputStream.println("Identifier, " + p.getActiveIdentifiers().get(0).getIdentifier());
            outputStream.println("Names, " + p.getPersonName());
            outputStream.println("Gender, " + p.getGender());
        }
        outputStream.println();

        outputStream.println(
                "No., Item ordered, Dose/Units, Frequency, Instructions, Start date, Discontinued date");
        outputStream.println();
        for (DrugOrder drugOrder : drugOrderList) {
            count += 1;
            outputStream.println(count + ", " + drugOrder.getDrug().getName() + ", " + drugOrder.getDose() + " "
                    + drugOrder.getDoseUnits().getName().getName() + ", " + drugOrder.getFrequency() + ", "
                    + drugOrder.getInstructions() + ", " + sdf.format(drugOrder.getEffectiveStartDate()) + ", "
                    + sdf.format(drugOrder.getEffectiveStopDate()));
        }

        outputStream.flush();
    } catch (Exception e) {
        log.error(e.getMessage());
    } finally {
        if (null != outputStream)
            outputStream.close();
    }
}

From source file:com.indeed.imhotep.web.QueryServlet.java

private void handleDescribeField(HttpServletRequest req, HttpServletResponse resp,
        DescribeStatement parsedQuery) throws IOException {
    final ServletOutputStream outputStream = resp.getOutputStream();
    final String dataset = parsedQuery.dataset;
    final String fieldName = parsedQuery.field;
    final List<String> topTerms = topTermsCache.getTopTerms(dataset, fieldName);
    FieldMetadata field = metadata.getDataset(dataset).getField(fieldName);
    if (field == null) {
        field = new FieldMetadata("notfound", FieldType.String);
        field.setDescription("Field not found");
    }/*from   w  w w . ja v a  2  s .c  o  m*/
    final boolean json = req.getParameter("json") != null;
    if (json) {
        resp.setContentType(MediaType.APPLICATION_JSON_VALUE);
        final ObjectMapper mapper = new ObjectMapper();
        mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
        final ObjectNode jsonRoot = mapper.createObjectNode();
        field.toJSON(jsonRoot);

        final ArrayNode termsArray = mapper.createArrayNode();
        jsonRoot.put("topTerms", termsArray);
        for (String term : topTerms) {
            termsArray.add(term);
        }
        mapper.writeValue(outputStream, jsonRoot);
    } else {
        for (String term : topTerms) {
            outputStream.println(term);
        }
    }
    outputStream.close();
}

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

/**
 * ???PDF/*from  w ww.ja v  a 2 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();
    }
}