List of usage examples for com.itextpdf.text Font BOLD
int BOLD
To view the source code for com.itextpdf.text Font BOLD.
Click Source Link
From source file:com.ashish.medicine.admin.invoice.InvoiceAction.java
private void addCustomerDetails(Document document) throws DocumentException, MalformedURLException, IOException { Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 10f, Font.BOLD); Font shopNameFont = new Font(Font.FontFamily.TIMES_ROMAN, 18f, Font.BOLD); Font normalTextFont = new Font(Font.FontFamily.TIMES_ROMAN, 10f, Font.NORMAL); Phrase p = null;/*w ww .j av a2 s. c o m*/ String customerName = ""; String doctorName = ""; String doctorAddr = ""; String customerAddr = ""; String billNo = ""; String billDate = ""; if (totalRecords != null && totalRecords.size() > 0) { for (InvoiceBean iBean : totalRecords) { if (iBean.getDoctorName() != null) doctorName = iBean.getDoctorName(); if (iBean.getDoctorAddr1() != null) doctorAddr = iBean.getDoctorAddr1(); customerName = iBean.getCustomerName(); customerAddr = iBean.getCustomerAddr1(); billNo = String.valueOf(iBean.getBillNo()); billDate = iBean.getBillDate(); } p = new Phrase("Bill No:" + billNo + getSpace(120), headerFont); document.add(p); p = new Phrase("Date:" + billDate + "\n", headerFont); document.add(p); addBlankLine(document); addImage(document); addBlankLine(document); String shopName = myaccountBean.getShopName(); p = new Phrase(shopName, shopNameFont); document.add(p); addBlankLine(document); // Add store details String address = myaccountBean.getOwnerAddr1() + "," + myaccountBean.getOwnerAddr2() + "," + myaccountBean.getState() + ",PIN-" + myaccountBean.getPin(); p = new Phrase("Shop No - " + myaccountBean.getShopNo() + "," + address, normalTextFont); document.add(p); String contactNo = myaccountBean.getMob1() + "/" + myaccountBean.getPhone1(); p = new Phrase(",Contact:" + contactNo, normalTextFont); document.add(p); addBlankLine(document); p = new Phrase("Licence No:" + myaccountBean.getLicenceNo() + getSpace(20), normalTextFont); document.add(p); p = new Phrase("Baby Food Licence No:" + myaccountBean.getBabyFoodLcNo(), normalTextFont); document.add(p); addBlankLine(document); addEmptyLine(document, 25); p = new Phrase("Name:", headerFont); document.add(p); p = new Phrase(customerName + getSpace(5), normalTextFont); document.add(p); p = new Phrase("Address:", headerFont); document.add(p); p = new Phrase(customerAddr + "\n", normalTextFont); document.add(p); p = new Phrase("Doctor's Name:", headerFont); document.add(p); p = new Phrase(doctorName + getSpace(5), normalTextFont); document.add(p); p = new Phrase("Doctor's Address:", headerFont); document.add(p); p = new Phrase(doctorAddr, normalTextFont); document.add(p); } }
From source file:com.ashish.medicine.admin.invoice.InvoiceAction.java
private void createTable(Document document) throws DocumentException, MalformedURLException, IOException { PdfPTable table = new PdfPTable(8); table.setWidths(new int[] { 5, 10, 30, 15, 15, 15, 25, 20 }); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); // addLogo(table); String[] headerTitle = { "Sl", "Qty", "Medicine Name", "Mfg Date", "Batch", "Exp Date", "Schedule", "Price" }; Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 10f, Font.BOLD); for (String header : headerTitle) { Phrase p = new Phrase(header, headerFont); PdfPCell c1 = new PdfPCell(p); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setLeading(0f, 1.5f);/* w ww.j a va2 s . c o m*/ c1.setBackgroundColor(BaseColor.GRAY); table.addCell(c1); } Font contentFont = new Font(Font.FontFamily.TIMES_ROMAN, 9f); MedicineUtility mUtil = new MedicineUtility(); // table.setSpacingAfter(20); double vat = 0.0; double discount = 0.0; int count = 1; double totalAmt = 0.0; if (totalRecords != null && totalRecords.size() > 0) { for (InvoiceBean iBean : totalRecords) { // replaceDoctor = iBean.getDoctorName(); // replaceCustomer = iBean.getCustomerName(); // replaceCustAddr1 = iBean.getCustomerAddr1(); // replaceBillNo = iBean.getBillNo(); // replaceBillDate = iBean.getPurchaseDate(); vat = iBean.getVat(); discount = iBean.getDiscount(); PdfPCell c = new PdfPCell(new Phrase(count++ + "", contentFont)); table.addCell(c); c = new PdfPCell(new Phrase(iBean.getSoldoutStock() + "", contentFont)); table.addCell(c); table.addCell(new PdfPCell(new Phrase(iBean.getMedicineName(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getMfgDate(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getBatchName(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getExpDate(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getSchedule(), contentFont))); totalAmt = totalAmt + (iBean.getSoldoutStock() * iBean.getSoldoutUnitPrice()); table.addCell(new PdfPCell(new Phrase( mUtil.getFormattedAmount((iBean.getSoldoutStock() * iBean.getSoldoutUnitPrice())), contentFont))); } } double grandTotal = 0.0; // Total PdfPCell c1 = new PdfPCell(new Phrase("Total")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(totalAmt))); c1.setColspan(1); table.addCell(c1); // Vat c1 = new PdfPCell(new Phrase("Vat(" + vat + "%)")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); double vatAmt = totalAmt * vat / 100; c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(vatAmt))); c1.setColspan(1); table.addCell(c1); // Discount c1 = new PdfPCell(new Phrase("Discount(" + discount + "%)")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); double discountAmt = totalAmt * discount / 100; c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(discountAmt))); c1.setColspan(1); table.addCell(c1); // Grand Total c1 = new PdfPCell(new Phrase("Grand Total")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); grandTotal = (totalAmt + vatAmt - discountAmt); c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(grandTotal))); c1.setColspan(1); table.addCell(c1); document.add(table); }
From source file:com.athena.chameleon.engine.core.PDFCommonEventHelper.java
License:Apache License
/** * /* w w w . j ava 2 s . co m*/ * Paragraph ?.(Navigation ? title ) * * @param title * @param pageNumber * @param depth * @param x1 document left * @param x2 document right * @return Paragraph */ public Paragraph getTocParagraph(String title, int pageNumber, int depth, float x1, float x2) { Font tocFont = new Font(bfKorean, 10); if (depth == 0) tocFont.setStyle(Font.BOLD); Paragraph p = new Paragraph(); p.setSpacingAfter(5); Chunk tit = new Chunk(title + " ", tocFont); tit.setAction(PdfAction.gotoLocalPage(title, false)); Chunk point = new Chunk(".", tocFont); Chunk number = new Chunk(" " + pageNumber, tocFont); number.setAction(PdfAction.gotoLocalPage(title, false)); p.add(tit); float width = x2 - x1 - tit.getWidthPoint() - number.getWidthPoint() - (depth * 12); if ((x2 - x1) < tit.getWidthPoint()) width = x2 - x1 - (tit.getWidthPoint() - (x2 - x1)) - number.getWidthPoint() - (depth * 12) - 65; float i = point.getWidthPoint(); while (i < width) { p.add(point); i += point.getWidthPoint(); } p.add(number); return p; }
From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java
License:Apache License
/** * // ww w . j a va 2s . c o m * PDF Title Page * * @param doc * @param writer */ public static void setTitleMainPage(Document doc, PdfWriter writer, PDFCommonEventHelper event, Upload upload) throws Exception { Font fnTitle = new Font(bfKorean, 20, Font.BOLD); Font fnLabel = new Font(bfKorean, 11, Font.BOLD); Font fnText = new Font(bfKorean, 11); LineSeparator UNDERLINE = new LineSeparator(1, 80, null, com.itextpdf.text.Element.ALIGN_CENTER, -5); doc.newPage(); doc.add(Chunk.NEWLINE); event.setTitleFlag(true); int toc = writer.getPageNumber(); Image img = Image.getInstance(PDFDocGenerator.class.getResource("/image/title.gif")); img.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER); img.scalePercent(80, 80); doc.add(img); Paragraph titlePh = new Paragraph(MessageUtil.getMessage("pdf.message.main.title"), fnTitle); titlePh.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER); titlePh.setSpacingBefore(50); titlePh.setSpacingAfter(30); doc.add(titlePh); doc.add(UNDERLINE); PdfPTable t1 = new PdfPTable(2); t1.setSpacingBefore(20); t1.setWidths(new int[] { 110, 290 }); t1.getDefaultCell().setBorder(0); t1.getDefaultCell().setFixedHeight(32); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.project_name"), fnLabel)); t1.addCell(new Phrase(upload.getProjectNm(), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.department"), fnLabel)); t1.addCell(new Phrase(upload.getDepartment(), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.focus_name"), fnLabel)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.text.focus_name"), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.product"), fnLabel)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.text.product", upload.getBeforeWas(), upload.getAfterWas()), fnText)); doc.add(t1); doc.add(UNDERLINE); Paragraph executedPh = new Paragraph(MessageUtil.getMessage("pdf.message.main.label.executed"), fnLabel); executedPh.setSpacingBefore(30); executedPh.setSpacingAfter(15); executedPh.setIndentationLeft(50); doc.add(executedPh); PdfPTable t2 = new PdfPTable(2); t2.getDefaultCell().setFixedHeight(28); t2.getDefaultCell().setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); t2.getDefaultCell().setBackgroundColor(new BaseColor(217, 217, 217)); t2.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.owner"), fnLabel)); t2.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.project_role"), fnLabel)); t2.getDefaultCell().setBackgroundColor(new BaseColor(255, 255, 255)); t2.addCell(new Phrase(upload.getPerson(), fnText)); t2.addCell(new Phrase(upload.getOrgRole(), fnText)); doc.add(t2); doc.newPage(); int total = writer.reorderPages(null); int[] order = new int[total]; for (int i = 0; i < total; i++) { order[i] = i + toc; if (order[i] > total) order[i] -= total; } // apply the new order writer.reorderPages(order); }
From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java
License:Apache License
/** * ?//from w w w . j ava2s .c o m * * @param doc * @param writer * @param event * @throws Exception */ public static void setChapterSectionTOC(Document doc, PdfWriter writer, PDFCommonEventHelper event) throws Exception { doc.newPage(); event.setPagingFlag(false); Paragraph title = new Paragraph(MessageUtil.getMessage("pdf.message.toc.title"), new Font(bfKorean, 13, Font.BOLD)); title.setSpacingAfter(8); doc.add(title); int toc = writer.getPageNumber(); for (Paragraph p : event.titles) doc.add(p); doc.newPage(); int total = writer.reorderPages(null); int[] order = new int[total]; for (int i = 0; i < total; i++) { order[i] = i + toc; if (order[i] > total) order[i] -= total; } // apply the new order writer.reorderPages(order); }
From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java
License:Apache License
/** * Default ?(Bold)/*from ww w . j ava 2 s.co m*/ * * @param text text * @return Paragraph */ public static Paragraph getDefaultPoint(String text) { Font font = new Font(bfKorean, 10, Font.BOLD); Paragraph ph = new Paragraph(" " + text, font); ph.setMultipliedLeading(1.8F); ph.setIndentationLeft(45); ph.setSpacingAfter(14); return ph; }
From source file:com.base2.kagura.core.ExportHandler.java
License:Apache License
/** * Takes the output and transforms it into a PDF file. * @param out Output stream./*w w w . j a v a2s. c o m*/ * @param rows Rows of data from reporting-core * @param columns Columns to list on report */ public void generatePdf(OutputStream out, List<Map<String, Object>> rows, List<ColumnDef> columns) { try { Document document = new Document(); PdfWriter.getInstance(document, out); if (columns == null) { if (rows.size() > 0) return; columns = new ArrayList<ColumnDef>(CollectionUtils.collect(rows.get(0).keySet(), new Transformer() { @Override public Object transform(final Object input) { return new ColumnDef() { { setName((String) input); } }; } })); } if (columns.size() > 14) document.setPageSize(PageSize.A1); else if (columns.size() > 10) document.setPageSize(PageSize.A2); else if (columns.size() > 7) document.setPageSize(PageSize.A3); else document.setPageSize(PageSize.A4); document.open(); Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.NORMAL, BaseColor.BLACK); Font headerFont = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD, BaseColor.BLACK); int size = columns.size(); PdfPTable table = new PdfPTable(size); for (ColumnDef column : columns) { PdfPCell c1 = new PdfPCell(new Phrase(column.getName(), headerFont)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } table.setHeaderRows(1); if (rows != null) for (Map<String, Object> row : rows) { for (ColumnDef column : columns) { table.addCell(new Phrase(String.valueOf(row.get(column.getName())), font)); } } document.add(table); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.bdaum.zoom.email.internal.job.PdfJob.java
License:Open Source License
private void printPage(Document document, int pageNo, MultiStatus status, IProgressMonitor monitor) throws DocumentException, IOException { if (pageNo > 1) document.newPage();//from w ww . j a va 2 s .c om document.setPageCount(pageNo); final Display display = Display.getDefault(); int pageItem = 0; if (!layout.getTitle().isEmpty()) { String title = PageProcessor.computeTitle(layout.getTitle(), fileName, now, assets.size(), pageNo, pages, collection, meta); Paragraph p = new Paragraph(title, FontFactory.getFont(FontFactory.HELVETICA, titleSize, Font.BOLD, BaseColor.DARK_GRAY)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(layout.getSubtitle().isEmpty() ? titleLead + upperWaste : titleLead); document.add(p); } if (!layout.getSubtitle().isEmpty()) { String subtitle = PageProcessor.computeTitle(layout.getSubtitle(), fileName, now, assets.size(), pageNo, pages, collection, meta); Paragraph p = new Paragraph(subtitle, FontFactory.getFont(FontFactory.HELVETICA, subtitleSize, Font.NORMAL, BaseColor.DARK_GRAY)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(subtitleLead + upperWaste); document.add(p); } IVolumeManager vm = Core.getCore().getVolumeManager(); PdfPTable table = new PdfPTable(layout.getColumns()); try (Assetbox box = new Assetbox(null, status, false)) { for (int i = 0; i < rows; i++) { int ni = i * layout.getColumns(); for (int j = 0; j < layout.getColumns(); j++) { int a = (pageNo - 1) * imagesPerPage + ni + j; PdfPCell cell; if (a >= assets.size() || monitor.isCanceled()) cell = new PdfPCell(); else { final int dpi = quality == Constants.SCREEN_QUALITY ? SCREENDPI : PRINTERDPI; final int pixelWidth = (int) (imageWidth * dpi / 72); final int pixelHeight = (int) (imageHeight * dpi / 72); Asset asset = assets.get(a); zimage = new ZImage(ImageUtilities.loadThumbnail(display, asset.getJpegThumbnail(), cms, SWT.IMAGE_JPEG, true), null); org.eclipse.swt.graphics.Rectangle bounds = zimage.getBounds(); URI uri = vm.findExistingFile(asset, false); if (uri != null) { boolean r = asset.getRotation() % 180 != 0; double w = r ? asset.getHeight() : asset.getWidth(); double h = r ? asset.getWidth() : asset.getHeight(); double scale = w == 0 || h == 0 ? 1d : Math.min(pixelWidth / w, pixelHeight / h); scale = (scale <= 0.5d) ? 0.5d : 1d; File file = box.obtainFile(uri); if (file != null) try { ZImage hzimage = CoreActivator.getDefault().getHighresImageLoader().loadImage( null, status, file, asset.getRotation(), asset.getFocalLengthIn35MmFilm(), null, scale, Double.MAX_VALUE, true, ImageConstants.SRGB, null, unsharpMask, null, fileWatcher, opId, null); if (hzimage != null) { zimage.dispose(); zimage = hzimage; } } catch (UnsupportedOperationException e) { // do nothing } } display.syncExec(() -> { int kl = (keyLine > 0) ? (int) Math.max(1, (keyLine * dpi / 144)) : 0; org.eclipse.swt.graphics.Rectangle ibounds = zimage.getBounds(); double factor = Math.min((double) pixelWidth / ibounds.width, (double) pixelHeight / ibounds.height); int lw = pixelWidth + 2 * kl; int lh = pixelHeight + 2 * kl; Image newImage = new Image(display, lw, lh); GC gc = new GC(newImage); try { gc.setAntialias(SWT.ON); gc.setInterpolation(SWT.HIGH); gc.setAdvanced(true); gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); gc.fillRectangle(0, 0, lw, lh); int width = (int) (ibounds.width * factor + 2 * kl); int height = (int) (ibounds.height * factor + 2 * kl); int xoff = (lw - width) / 2; int yoff = (lh - height) / 2; if (kl > 0) { gc.setBackground(display.getSystemColor(SWT.COLOR_DARK_GRAY)); gc.fillRectangle(xoff, yoff, width, height); } zimage.draw(gc, 0, 0, ibounds.width, ibounds.height, xoff + kl, yoff + kl, width - 2 * kl, height - 2 * kl, ZImage.CROPPED, pixelWidth, pixelHeight, false); } finally { gc.dispose(); zimage.dispose(); zimage = new ZImage(newImage, null); } }); bounds = zimage.getBounds(); File jpegFile = ImageActivator.getDefault().createTempFile("PdfImg", ".jpg"); //$NON-NLS-1$//$NON-NLS-2$ tempFiles.add(jpegFile); try (FileOutputStream out = new FileOutputStream(jpegFile)) { zimage.saveToStream(monitor, true, ZImage.UNCROPPED, SWT.DEFAULT, SWT.DEFAULT, out, SWT.IMAGE_JPEG, jpegQuality); } zimage.dispose(); com.itextpdf.text.Image pdfImage = com.itextpdf.text.Image.getInstance(jpegFile.getPath()); double factor = Math.min(imageWidth / bounds.width, imageHeight / bounds.height); pdfImage.setInterpolation(true); pdfImage.scaleToFit((float) (bounds.width * factor), (float) (bounds.height * factor)); cell = new PdfPCell(pdfImage, false); cell.setHorizontalAlignment(Element.ALIGN_CENTER); monitor.worked(1); } cell.setFixedHeight((float) imageHeight); cell.setBorderWidth(0); table.addCell(cell); } renderCaptions(pageNo, seqNo, pageItem, table, ni, layout.getCaption1()); renderCaptions(pageNo, seqNo, pageItem, table, ni, layout.getCaption2()); pageItem += layout.getColumns(); seqNo += layout.getColumns(); if (verticalGap > 0 && i < rows - 1) for (int j = 0; j < layout.getColumns(); j++) { PdfPCell cell = new PdfPCell(); cell.setFixedHeight(verticalGap); cell.setBorderWidth(0); table.addCell(cell); } } table.setWidthPercentage(100f); document.add(table); if (!layout.getFooter().isEmpty()) { String footer = PageProcessor.computeTitle(layout.getFooter(), fileName, now, assets.size(), pageNo, pages, collection, meta); Paragraph p = new Paragraph(footer, FontFactory.getFont(FontFactory.HELVETICA, subtitleSize, Font.NORMAL, BaseColor.DARK_GRAY)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingBefore(upperWaste / 2 + footerLead); document.add(p); } } }
From source file:com.biblio.web.rest.PdfResources.java
@RequestMapping(value = "livre", method = RequestMethod.GET) public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, WriterException { response.setContentType("application/pdf"); GenerateQRCode ge = new GenerateQRCode(); try {/* ww w . j av a 2 s . c o m*/ Document document = new Document(); String param = request.getParameter("isbn"); Livre livre = livreRepository.findOneByIsbn(param).get(); PdfWriter e = PdfWriter.getInstance(document, response.getOutputStream()); document.open(); Font font = new Font(); font.setStyle(Font.BOLD); font.setSize(12); List list = new List(15); // document.left(12); list.add(new ListItem("Titre :" + livre.getTitre(), font)); list.add(new ListItem("Categorie :" + livre.getCategorie().getDescription(), font)); list.add(new ListItem("Auteurs :" + livre.getAuteurs(), font)); list.add(new ListItem("Edition :" + livre.getEdition(), font)); list.add(new ListItem("Editeur :" + livre.getEditeur(), font)); list.add(new ListItem("Collection :" + livre.getCollection(), font)); list.add(new ListItem("Date parution :" + livre.getDateParution(), font)); list.add(new ListItem("Isbn " + livre.getIsbn(), font)); list.add(new ListItem("Resume : " + livre.getResume(), font)); document.add(list); document.addTitle(livre.getTitre()); document.setMargins(100, 20, 0, 0); document.addCreationDate(); System.out.println("TTT v " + document.addTitle(param)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(ge.createQRImage(param, 125), "jpg", baos); Image image = Image.getInstance(baos.toByteArray()); document.add(image); document.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } }
From source file:com.carfinance.module.common.controller.DocumentDownloadController.java
/** * ???PDF//from www. j a v a 2s .c o m * @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(); } }