List of usage examples for com.itextpdf.text BaseColor BLACK
BaseColor BLACK
To view the source code for com.itextpdf.text BaseColor BLACK.
Click Source Link
From source file:com.atacadao.almoxarifado.model.GerandoPDF.java
public void pdfImpressaoBarraDeCodigo(String codigo) { Document documento = new Document(new Rectangle(90, 65)); documento.setMargins(0, 0, 0, 0);/*from www . ja v a 2 s . c o m*/ PdfWriter pdf; try { pdf = PdfWriter.getInstance(documento, new FileOutputStream("codigodebarras.pdf")); documento.open(); PdfContentByte contB = pdf.getDirectContent(); Barcode128 barCode = new Barcode128(); barCode.setCode(codigo); barCode.setCodeType(Barcode128.CODE128); Image image = barCode.createImageWithBarcode(contB, BaseColor.BLACK, BaseColor.BLACK); Paragraph titulo = new Paragraph("ATCADO DOS PISOS\n", new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 5)); titulo.setPaddingTop(0); titulo.setAlignment(Element.ALIGN_CENTER); float scaler = ((documento.getPageSize().getWidth() - documento.leftMargin() - documento.rightMargin() - 0) / image.getWidth()) * 60; image.scalePercent(scaler); image.setPaddingTop(0); image.setAlignment(Element.ALIGN_CENTER); documento.add(titulo); documento.add(image); documento.close(); Desktop.getDesktop().open(new File("codigodebarras.pdf")); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } }
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.// www. j av a 2 s.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.ui.internal.dialogs.ExhibitionEditDialog.java
License:Open Source License
private void writeDocument(Document document, File targetFile) { boolean frame = detailTabfolder.getSelectionIndex() == 1; try (FileOutputStream out = new FileOutputStream(targetFile)) { PdfWriter writer = PdfWriter.getInstance(document, out); document.open();/* w ww . j a v a 2 s.com*/ writer.setPageEvent(new PdfPageEventHelper() { int pageNo = 0; com.itextpdf.text.Font ffont = new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.HELVETICA, 9, com.itextpdf.text.Font.NORMAL, BaseColor.DARK_GRAY); @Override public void onEndPage(PdfWriter w, Document d) { PdfContentByte cb = w.getDirectContent(); Phrase footer = new Phrase(String.valueOf(++pageNo), ffont); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer, (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom(), 0); } }); String tit = NLS.bind(Messages.ExhibitionEditDialog_exhibition_name, nameField.getText()); Paragraph p = new Paragraph(tit, FontFactory.getFont(FontFactory.HELVETICA, 14, com.itextpdf.text.Font.BOLD, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(8); document.add(p); String subtitle = NLS.bind(Messages.ExhibitionEditDialog_image_list, Constants.DFDT.format(new Date()), frame ? Messages.ExhibitionEditDialog_image_sizes : Messages.ExhibitionEditDialog_frame_sizes); p = new Paragraph(subtitle, FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(14); document.add(p); p = new Paragraph(descriptionField.getText(), FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(10); document.add(p); p = new Paragraph(infoField.getText(), FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(10); document.add(p); IDbManager db = Core.getCore().getDbManager(); List<Wall> walls = current.getWall(); Wall[] sortedWalls = walls.toArray(new Wall[walls.size()]); Arrays.sort(sortedWalls, new Comparator<Wall>() { public int compare(Wall o1, Wall o2) { return o1.getLocation().compareToIgnoreCase(o2.getLocation()); } }); for (Wall wall : sortedWalls) { p = new Paragraph(wall.getLocation(), FontFactory.getFont(FontFactory.HELVETICA, 12, com.itextpdf.text.Font.BOLD, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_LEFT); p.setSpacingAfter(12); document.add(p); PdfPTable table = new PdfPTable(7); // table.setBorderWidth(1); // table.setBorderColor(new Color(224, 224, 224)); // table.setPadding(5); // table.setSpacing(0); table.setWidths(new int[] { 8, 33, 13, 13, 20, 13, 20 }); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_No, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_title, Element.ALIGN_LEFT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_xpos, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_height, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_size, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_dpi, Element.ALIGN_RIGHT)); table.addCell(createTableHeader("", Element.ALIGN_LEFT)); //$NON-NLS-1$ // table.endHeaders(); List<ExhibitImpl> exhibits = new ArrayList<ExhibitImpl>(); for (String exhibitId : wall.getExhibit()) { ExhibitImpl exhibit = db.obtainById(ExhibitImpl.class, exhibitId); if (exhibit != null) exhibits.add(exhibit); } Collections.sort(exhibits, new Comparator<ExhibitImpl>() { public int compare(ExhibitImpl e1, ExhibitImpl e2) { return ((Exhibit) e1).getX() - ((Exhibit) e2).getX(); } }); int no = 1; for (ExhibitImpl exhibit : exhibits) { int tara = computeTara(frame, exhibit); table.addCell(createTableCell(String.valueOf(no++), Element.ALIGN_RIGHT)); table.addCell(createTableCell(exhibit.getTitle(), Element.ALIGN_LEFT)); af.setMaximumFractionDigits(2); af.setMinimumFractionDigits(2); String x = af.format((exhibit.getX() - tara) / 1000d); table.addCell(createTableCell(NLS.bind("{0} m", x), Element.ALIGN_RIGHT)); //$NON-NLS-1$ String y = af.format((exhibit.getY() + tara) / 1000d); table.addCell(createTableCell(NLS.bind("{0} m", y), Element.ALIGN_RIGHT)); //$NON-NLS-1$ af.setMaximumFractionDigits(1); af.setMinimumFractionDigits(1); String h = af.format((exhibit.getHeight() + 2 * tara) / 10d); int width = exhibit.getWidth(); String w = af.format((width + 2 * tara) / 10d); table.addCell(createTableCell(NLS.bind("{0} x {1} cm", w, h), Element.ALIGN_RIGHT)); //$NON-NLS-1$ AssetImpl asset = dbManager.obtainAsset(exhibit.getAsset()); if (asset != null) { int pixels = asset.getWidth(); double dpi = pixels * 25.4d / width; table.addCell(createTableCell(String.valueOf((int) dpi), Element.ALIGN_RIGHT)); } else table.addCell(""); //$NON-NLS-1$ table.addCell(createTableCell(exhibit.getSold() ? Messages.ExhibitionEditDialog_sold : "", //$NON-NLS-1$ Element.ALIGN_LEFT)); } document.add(table); } document.close(); } catch (DocumentException e) { UiActivator.getDefault().logError(Messages.ExhibitionEditDialog_internal_error_writing_pdf, e); } catch (IOException e) { UiActivator.getDefault().logError(Messages.ExhibitionEditDialog_io_error_writing_pdf, e); } }
From source file:com.bdaum.zoom.ui.internal.dialogs.ExhibitionEditDialog.java
License:Open Source License
private static PdfPCell createTableHeader(String header, int alignment) { PdfPCell cell = new PdfPCell(new Paragraph(header, FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.BOLD, BaseColor.BLACK))); cell.setBorderColor(new BaseColor(224, 224, 224)); cell.setBorderWidth(1);/*from w w w . java 2 s .c o m*/ cell.setPadding(5); cell.setHorizontalAlignment(alignment); return cell; }
From source file:com.bdaum.zoom.ui.internal.dialogs.ExhibitionEditDialog.java
License:Open Source License
private static PdfPCell createTableCell(String value, int alignment) { PdfPCell cell = new PdfPCell(new Paragraph(value, FontFactory.getFont(FontFactory.HELVETICA, 9, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK))); cell.setBorderColor(new BaseColor(224, 224, 224)); cell.setBorderWidth(1);//w w w. j a v a2 s . co m cell.setPadding(5); cell.setHorizontalAlignment(alignment); return cell; }
From source file:com.carfinance.module.common.controller.DocumentDownloadController.java
/** * ???PDF/*w ww. j av a 2s .co 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(); } }
From source file:com.carfinance.module.common.controller.DocumentDownloadController.java
/** * ??// www. ja v a2 s . co m * @param model * @param request * @param response */ @RequestMapping(value = "/pdfhunchecontrace", method = RequestMethod.GET) public void pdfHuncheContrace(Model model, HttpServletRequest request, HttpServletResponse response) { String contrace_id_str = request.getParameter("contrace_id"); String org_id = ""; String contrace_no = ""; String customer_name = ""; String vehicle_id = ""; String daily_available_km = ""; 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(); daily_available_km = vehicleContraceInfo.getDaily_available_km() + ""; } else { 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(); } } List<VehicleContraceVehsInfo> vehicleContraceVehsInfoList = this.vehicleServiceManageService .getVehicleContraceVehsListByContraceId(Long.valueOf(contrace_id_str)); //1.ContentType response.setContentType("multipart/form-data"); //2.????(??a.pdf) response.setHeader("Content-Disposition", "attachment;fileName=" + contrace_no + ".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("hunche.contrace.download.path") + contrace_no + ".pdf")); // pdf ? Paragraph paragraph1 = new Paragraph("???", bold_fontChinese); paragraph1.setAlignment(Element.ALIGN_CENTER); Paragraph paragraph2 = new Paragraph( "???", normal_fontChinese); Paragraph paragraph3 = new Paragraph("" + customer_name + " (", normal_fontChinese); Paragraph paragraph4 = new Paragraph( "?????________________???", normal_fontChinese); Paragraph paragraph5 = new Paragraph("??????", normal_fontChinese); // table PdfPTable table = new PdfPTable(4); table.setWidthPercentage(100); table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); PdfPCell cell = new PdfPCell(); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Paragraph("?", normal_fontChinese)); table.addCell(cell); cell.setPhrase(new Paragraph("", normal_fontChinese)); table.addCell(cell); cell.setPhrase(new Paragraph("?/", normal_fontChinese)); table.addCell(cell); cell.setPhrase(new Paragraph("?", normal_fontChinese)); table.addCell(cell); // ? for (VehicleContraceVehsInfo v : vehicleContraceVehsInfoList) { PdfPCell newcell = new PdfPCell(); newcell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); newcell.setPhrase(new Paragraph("1", normal_fontChinese)); table.addCell(newcell); newcell.setPhrase(new Paragraph(v.getModel(), normal_fontChinese)); table.addCell(newcell); newcell.setPhrase(new Paragraph(v.getDaily_price() + "", normal_fontChinese)); table.addCell(newcell); newcell.setPhrase(new Paragraph(daily_available_km, normal_fontChinese)); table.addCell(newcell); } Paragraph paragraph6 = new Paragraph( "??_________________________________________________________________", normal_fontChinese); Paragraph paragraph7 = new Paragraph( "____________________________?______", normal_fontChinese); Paragraph paragraph8 = new Paragraph("????", normal_fontChinese); Paragraph paragraph9 = new Paragraph( "???________________________???________________________", normal_fontChinese); Paragraph paragraph10 = new Paragraph("?", normal_fontChinese); Paragraph paragraph11 = new Paragraph( "???????????????", normal_fontChinese); Paragraph paragraph12 = new Paragraph("?", normal_fontChinese); Paragraph paragraph13 = new Paragraph( "??????????????", normal_fontChinese); Paragraph paragraph14 = new Paragraph( "?????????", normal_fontChinese); Paragraph paragraph15 = new Paragraph("?????", normal_fontChinese); Paragraph paragraph16 = new Paragraph( "(/) (/)", normal_fontChinese); Paragraph paragraph17 = new Paragraph( " ??", normal_fontChinese); Paragraph paragraph18 = new Paragraph( "?? ?? ", normal_fontChinese); Paragraph paragraph19 = new Paragraph( " 201 ", normal_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(table); 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(paragraph15); pdfDoc.add(paragraph16); pdfDoc.add(paragraph17); pdfDoc.add(paragraph18); pdfDoc.add(paragraph19); pdfDoc.close(); ServletOutputStream out; //File(?download.pdf) File file = new File(appProps.get("hunche.contrace.download.path") + contrace_no + ".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(); } }
From source file:com.cib.statementstamper.windows.StatementStamperMainWindow.java
License:Open Source License
@Override public void attach() { super.attach(); try {//from w w w . j a va 2 s . co m logo = Image .getInstance(StatementStamperMainWindow.class.getResource("/resources/images/cib_logo.jpg")); logo.setAlignment(Image.LEFT); logo.scalePercent(30); isplogo = Image .getInstance(StatementStamperMainWindow.class.getResource("/resources/images/isplogo.jpg")); isplogo.setAlignment(Image.LEFT); isplogo.scalePercent(50); baseFontArial = BaseFont.createFont("/resources/fonts/ARIAL.TTF", BaseFont.CP1250, BaseFont.EMBEDDED); myFontBase = BaseFont.createFont("/resources/fonts/courbd.ttf", BaseFont.CP1250, BaseFont.EMBEDDED); bottomFont = new Font(baseFontArial, 7, Font.NORMAL, BaseColor.BLACK); bottomFontBold = new Font(baseFontArial, 7, Font.BOLD, BaseColor.BLACK); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } upload.addListener((Upload.SucceededListener) this); upload.addListener((Upload.StartedListener) this); upload.addListener((Upload.FinishedListener) this); upload.addListener((Upload.FailedListener) this); upload.setImmediate(true); addComponent(upload); }
From source file:com.deadormi.servlet.CreaPdfServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w ww . ja v a 2 s.com * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url = request.getQueryString(); Integer gruppo_id = Integer.parseInt(url.substring(url.indexOf("=") + 1, url.length())); List<Utente> iscritti = null; List<Post> posts = null; Gruppo gruppo = null; Utente utente = null; String imageUrl = null; String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort(); try { iscritti = UtenteController.getUserByGroupId(request, gruppo_id); gruppo = GruppoController.getGruppoById(request, gruppo_id); } catch (SQLException ex) { log.error(ex); } // step 1: creation of a document-object Document document = new Document(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); String incipit = "Report del " + CurrentDate.getCurrentDate() + "\n"; Paragraph pIncipit = new Paragraph(incipit, FontFactory.getFont(FontFactory.HELVETICA, 14, BaseColor.BLACK)); pIncipit.setAlignment(Element.ALIGN_CENTER); pIncipit.setSpacingAfter(10); document.add(pIncipit); String title = "Gruppo " + gruppo.getNome(); Paragraph pTitle = new Paragraph(title, FontFactory.getFont(FontFactory.HELVETICA, 18, BaseColor.BLUE)); pTitle.setAlignment(Element.ALIGN_CENTER); pTitle.setSpacingAfter(40); document.add(pTitle); PdfPCell labelNome = new PdfPCell(new Paragraph("Nome utente")); PdfPCell labelNumPost = new PdfPCell(new Paragraph("Num. post")); PdfPCell labelData = new PdfPCell(new Paragraph("Data ultimo post")); labelNome.setBorder(Rectangle.NO_BORDER); labelNumPost.setBorder(Rectangle.NO_BORDER); labelData.setBorder(Rectangle.NO_BORDER); for (int i = 0; i < iscritti.size(); i++) { utente = iscritti.get(i); try { posts = PostController.getPostByGruppoIdAndUserId(request, gruppo_id, utente.getId_utente()); } catch (SQLException ex) { Logger.getLogger(CreaPdfServlet.class.getName()).log(Level.SEVERE, null, ex); } if (utente.getNome_avatar() != null) { imageUrl = baseUrl + request.getContextPath() + AVATAR_RESOURCE_PATH + "/" + utente.getId_utente() + "_" + utente.getNome_avatar(); ; } else { imageUrl = baseUrl + request.getContextPath() + "/res/images/user_avatar.png"; } Image image = Image.getInstance(new URL(imageUrl)); image.scaleToFit(50, 50); PdfPTable table = new PdfPTable(3); PdfPCell cellAvatar = new PdfPCell(image); cellAvatar.setHorizontalAlignment(Element.ALIGN_CENTER); cellAvatar.setBorder(Rectangle.NO_BORDER); cellAvatar.setRowspan(3); PdfPCell cellNome = new PdfPCell(new Paragraph(utente.getUsername() + "")); cellNome.setBorder(Rectangle.NO_BORDER); PdfPCell cellNumPost = new PdfPCell(new Paragraph(posts.size() + "")); cellNumPost.setBorder(Rectangle.NO_BORDER); //L'ultimo sempre il piu recente siccome la query ORDER BY data_creazione PdfPCell cellData; if (posts.size() != 0) { cellData = new PdfPCell(new Paragraph(posts.get(posts.size() - 1).getData_creazione())); } else { cellData = new PdfPCell(new Paragraph("N/A")); } cellData.setBorder(Rectangle.NO_BORDER); PdfPCell cellVoidBottom = new PdfPCell(new Paragraph(" ")); cellVoidBottom.setBorder(Rectangle.BOTTOM); cellVoidBottom.setPaddingBottom(10); cellVoidBottom.setColspan(3); PdfPCell cellVoidTop = new PdfPCell(new Paragraph(" ")); cellVoidTop.setBorder(Rectangle.NO_BORDER); cellVoidTop.setPaddingTop(10); cellVoidTop.setColspan(3); table.addCell(cellVoidTop); table.addCell(cellAvatar); table.addCell(labelNome); table.addCell(cellNome); table.addCell(labelNumPost); table.addCell(cellNumPost); table.addCell(labelData); table.addCell(cellData); table.addCell(cellVoidBottom); document.add(table); } document.close(); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "inline; filename=ahahah.pdf"); OutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } catch (DocumentException ex) { Logger.getLogger(CreaPdfServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.devox.GUI.PDF.CrearReporteApto.java
@Override public PdfPTable crearTabla() { PdfPTable table = new PdfPTable(8); //new float[]{2.4f, 3f, 1.25f, 1.2f, 1f, 1.15f, 1.1f, 1.55f} PdfPCell cell;//w w w .j a v a 2 s .c o m cell = new PdfPCell(new Phrase("CDIGO", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorRight(GRIS_CLARO); cell.setFixedHeight(20f); table.addCell(cell); cell = new PdfPCell(new Phrase("DESCRIPCIN", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(GRIS_CLARO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); cell = new PdfPCell(new Phrase("LOTE", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(GRIS_CLARO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); cell = new PdfPCell(new Phrase("FECHA DE CADUCIDAD", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(GRIS_CLARO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); cell = new PdfPCell(new Phrase("CANTIDAD", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(GRIS_CLARO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); cell = new PdfPCell(new Phrase("DICTAMEN", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(AMARILLO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); cell = new PdfPCell(new Phrase("PRECIO", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(AMARILLO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); cell = new PdfPCell(new Phrase("OBSERVACIONES", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(AMARILLO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); try { table.setWidths(new float[] { 2.4f, 3f, 1.25f, 1.2f, 1f, 1.15f, 1.1f, 1.55f }); table.setWidthPercentage(100); } catch (DocumentException ex) { Log.print(ex); } return table; }