List of usage examples for com.itextpdf.text Document add
public boolean add(Element element) throws DocumentException
Element
to the Document
. From source file:com.bicitools.dao.RutasDAODecorador.java
@Override public RespuestaJson exportarRecorridosRuta(String usuario, String fechaIni, String fechaFin, String archivo) { Ruta r = new Ruta(); RespuestaJson res = new RespuestaJson(); res = getRutasDAO().exportarRecorridosRuta(usuario, fechaIni, fechaFin, archivo); Vector qresul = null;//ww w .ja va2s . c o m SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date fechaUno, fechaDos; try { fechaUno = formatter.parse(fechaIni); fechaDos = formatter.parse(fechaFin); } catch (ParseException ex) { String inputStr = "01-01-1900 00:00:00"; DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); try { fechaUno = dateFormat.parse(inputStr); } catch (Exception miex) { fechaUno = new java.util.Date(); } fechaDos = new java.util.Date(); } try { Query query = em.createNamedQuery("Ruta.findByUsuarioFechas"); query.setParameter("usuario", usuario); query.setParameter("fechaIni", fechaUno, TemporalType.TIMESTAMP); query.setParameter("fechaFin", fechaDos, TemporalType.TIMESTAMP); qresul = (Vector) query.getResultList(); if (qresul.size() > 0) { int i; ArrayList rta = new ArrayList(); // Se crea el documento Document documento = new Document(); // Se crea el OutputStream para el fichero donde queremos dejar el pdf. FileOutputStream ficheroPdf = null; //ficheroPdf = new FileOutputStream("/Users/jhony/Documents/Uni Andes/Fabricas/Bicitools/bicitools/reporte.pdf"); DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy_HHmmss"); Date fechaReporte = new Date(); ficheroPdf = new FileOutputStream(archivo + "/Reporte_RutasRecorridos_" + usuario + "_" + dateFormat.format(fechaReporte) + ".pdf"); // Se asocia el documento al OutputStream y se indica que el espaciado entre // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); // Se abre el documento. documento.open(); documento.add(new Paragraph("Reporte de Recorridos por Ruta para " + usuario)); documento.add(new Paragraph(" ")); Date fechaSalida = fechaUno; // Create an instance of SimpleDateFormat used for formatting DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String reportDate = df.format(fechaSalida); documento.add(new Paragraph("Fecha Inicial: " + reportDate)); fechaSalida = fechaDos; reportDate = df.format(fechaSalida); documento.add(new Paragraph("Fecha Final: " + reportDate)); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); for (i = 0; i < qresul.size(); i++) { PdfPTable tabla = new PdfPTable(3); Ruta miRuta = (Ruta) qresul.get(i); RutaPunto puntos = new RutaPunto(); DatosRutasRecorridosJson rutaSalida = new DatosRutasRecorridosJson(); //ruta //ArrayList<DatosLugaresJson> lugares = obtenerPuntosRutaUsuario(miRuta.getNombre()); //rutaSalida.setLugares(lugares); RutaPunto puntoUno; RutaPunto puntoDos; //ruta 1 rutaSalida.setNombre(miRuta.getNombre()); // Create an instance of SimpleDateFormat used for formatting df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); rutaSalida.setFechaHora(df.format(miRuta.getFechaCreacion())); //obtiene primer y ultimo punto puntoUno = obtenerPuntoRutaIndiceUsuario(miRuta.getNombre(), 0); puntoDos = obtenerPuntoRutaIndiceUsuario(miRuta.getNombre(), -1); //consumeServicio Tiempo y distancia final Gson prettyGson = new GsonBuilder().setPrettyPrinting().create(); DatosConsumoPuntoRutaJson entrada = new DatosConsumoPuntoRutaJson(); entrada.setLatitudOrigen(Double.parseDouble(puntoUno.getLatitud())); entrada.setLongitudOrigen(Double.parseDouble(puntoUno.getLongitud())); entrada.setLatitudDestino(Double.parseDouble(puntoDos.getLatitud())); entrada.setLongitudDestino(Double.parseDouble(puntoDos.getLongitud())); final String representacionBonita = prettyGson.toJson(entrada); res = ConsumeServicios.consumeTiempoDist(representacionBonita); if (res.getCodigo() == 0) { ArrayList<TiempoDistanciaInfo> datos; TiempoDistanciaInfo infoRuta; datos = res.getDatos(); infoRuta = (TiempoDistanciaInfo) datos.get(0); //rutaSalida.setDistancia(infoRuta.getDistancia().replace("\"","")); //rutaSalida.setTiempo(infoRuta.getTiempo().replace("\"","")); documento.add(new Paragraph("Nombre: " + miRuta.getNombre())); documento.add( new Paragraph("Distancia calculada: " + infoRuta.getDistancia().replace("\"", ""))); documento.add(new Paragraph("Tiempo estimado: " + infoRuta.getTiempo().replace("\"", ""))); documento.add(new Paragraph("-------Recorridos-----")); documento.add(new Paragraph(" ")); tabla.addCell(infoRuta.getDistancia().replace("\"", "")); tabla.addCell(infoRuta.getTiempo().replace("\"", "")); rutaSalida.setRecorridos(obtenerRecoRuta(usuario, fechaIni, fechaFin, miRuta.getNombre())); documento.add(new Paragraph("---------------------")); documento.add(new Paragraph(" ")); rta.add(rutaSalida); res = ConstruyeRespuesta.construyeRespuestaOk(); //res.setDatos(rta); documento.add(tabla); } } documento.add(new Paragraph(" ")); try { Image foto = Image.getInstance( "http://1.bp.blogspot.com/-fV-ThFg9bN0/UCr4VMFrJ-I/AAAAAAAAEYQ/-_vIDIYDLz8/s1600/dibujo-pintar-doki-bicicleta.jpg"); foto.scaleToFit(100, 100); foto.setAlignment(Chunk.ALIGN_CENTER); documento.add(foto); } catch (IOException | DocumentException e) { } documento.close(); } else { res = ConstruyeRespuesta.construyeRespuestaFalla("no hay datos " + qresul.size()); } } catch (Exception ex) { res = ConstruyeRespuesta.construyeRespuestaFalla("error " + ex.getMessage()); } //res.setDescripcion("numero de datos devueltos " + qresul.size()); return res; }
From source file:com.bicitools.dao.RutasDAODecorador.java
@Override public RespuestaJson exportarReporteMetricasUsuario(String usuario, String fechaIni, String fechaFin, String archivo) {// w ww. j a v a 2s. c o m RespuestaJson res = new RespuestaJson(); res = getRutasDAO().exportarReporteMetricasUsuario(usuario, fechaIni, fechaFin, archivo); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date fechaUno, fechaDos; try { fechaUno = formatter.parse(fechaIni); fechaDos = formatter.parse(fechaFin); } catch (ParseException ex) { String inputStr = "01-01-1900 00:00:00"; DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); try { fechaUno = dateFormat.parse(inputStr); } catch (Exception miex) { fechaUno = new java.util.Date(); } fechaDos = new java.util.Date(); } Query query = em.createNamedQuery("Ruta.findMetricasByUsuario"); query.setParameter("usuario", usuario); query.setParameter("fechaIni", fechaUno, TemporalType.TIMESTAMP); query.setParameter("fechaFin", fechaDos, TemporalType.TIMESTAMP); List<Object[]> qresul = query.getResultList(); if (qresul.size() > 0) { try { // Se crea el documento Document documento = new Document(); // Se crea el OutputStream para el fichero donde queremos dejar el pdf. FileOutputStream ficheroPdf = null; //ficheroPdf = new FileOutputStream("/Users/jhony/Documents/Uni Andes/Fabricas/Bicitools/bicitools/reporte.pdf"); DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy_HHmmss"); Date fechaReporte = new Date(); ficheroPdf = new FileOutputStream( archivo + "/Reporte_" + usuario + "_" + dateFormat.format(fechaReporte) + ".pdf"); // Se asocia el documento al OutputStream y se indica que el espaciado entre // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); // Se abre el documento. documento.open(); documento.add(new Paragraph("Reporte de Actividad para " + usuario)); documento.add(new Paragraph(" ")); /*documento.add(new Paragraph("Este es el segundo y tiene una fuente rara", FontFactory.getFont("arial", // fuente 22, // tamao Font.ITALIC, // estilo BaseColor.CYAN))); // color */ documento.add(new Paragraph("Fecha Inicial: " + fechaUno)); documento.add(new Paragraph("Fecha Final: " + fechaDos)); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); PdfPTable tabla = new PdfPTable(3); tabla.addCell("Fecha"); tabla.addCell("Tiempo"); tabla.addCell("Distancia"); int distanciaTotal = 0, tiempoTotal = 0; ArrayList<DatosMetricasReportesJson> rta = new ArrayList<>(); ArrayList<DatosMetricasUsuarioJson> lista = new ArrayList<>(); DatosMetricasReportesJson salida = new DatosMetricasReportesJson(); MetricasUsuario total = new MetricasUsuario(); lista.clear(); for (Object[] object : qresul) { Date fechaSalida = (Date) object[2]; // Create an instance of SimpleDateFormat used for formatting DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String reportDate = df.format(fechaSalida); tabla.addCell(reportDate); tabla.addCell((String) object[1]); tabla.addCell((String) object[0]); distanciaTotal += Integer.parseInt((String) object[0]); tiempoTotal += Integer.parseInt((String) object[1]); } documento.add(tabla); documento.add(new Paragraph(" ")); documento.add(new Paragraph("Tiempo Total: " + tiempoTotal)); documento.add(new Paragraph("Distancia Total: " + distanciaTotal)); documento.add(new Paragraph(" ")); try { Image foto = Image.getInstance( "http://1.bp.blogspot.com/-fV-ThFg9bN0/UCr4VMFrJ-I/AAAAAAAAEYQ/-_vIDIYDLz8/s1600/dibujo-pintar-doki-bicicleta.jpg"); foto.scaleToFit(100, 100); foto.setAlignment(Chunk.ALIGN_CENTER); documento.add(foto); } catch (Exception e) { e.printStackTrace(); } res = ConstruyeRespuesta.construyeRespuestaOk(); documento.close(); //res.setDatos(rta); } catch (DocumentException ex) { Logger.getLogger(RutasDAO.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(RutasDAO.class.getName()).log(Level.SEVERE, null, ex); } } else { res = ConstruyeRespuesta.construyeRespuestaFalla("no hay datos " + qresul.size()); } return res; }
From source file:com.bougsid.printers.PrintMission.java
public void printMission(Mission mission) { Document document = new Document(PageSize.A4); try {/*from ww w . j av a2 s . c o m*/ File downloadDir = new File(msg.getMessage("application.mission.downloaddir")); if (!downloadDir.exists()) { downloadDir.mkdir(); } System.out.println("Dir =" + downloadDir.getPath()); PdfWriter.getInstance(document, new FileOutputStream(downloadDir.getPath() + "/" + mission.getUuid() + ".pdf")); document.open(); Paragraph p = new Paragraph(); p.setSpacingAfter(60); document.add(p); //header Paragraph paragraph = new Paragraph( msg.getMessage("mission.pdf.school") + " " + mission.getIdMission() + " ", DEFAULT_FONT); Phrase phrase = new Phrase(msg.getMessage("mission.pdf.city") + " " + LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))); paragraph.add(phrase); paragraph.setSpacingAfter(50); document.add(paragraph); //title PdfPTable table = new PdfPTable(1); table.setWidthPercentage(40); PdfPCell cell = new PdfPCell(new Phrase(msg.getMessage("mission.pdf.title"), FontFactory.getFont(FontFactory.HELVETICA, 18))); cell.setBorderWidth(1); cell.setPadding(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setSpacingAfter(40); document.add(table); //content table = new PdfPTable(2); table.setWidthPercentage(100); //line 1 cell = new PdfPCell(new Paragraph(mission.getEmploye().getCivilite().getLabel(), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getFullName(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 2 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.matricule"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getMatricule(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 3 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.grade"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getFonction(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); if (mission.getEntreprise() != null) { //line 4 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.text_1"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.text_1_2"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 5 cell = new PdfPCell(new Paragraph(" ", DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(" - " + mission.getEntreprise().getNom(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); } //line 6 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.lieu"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); p = new Paragraph(); p.setFont(DEFAULT_FONT); for (Ville ville : mission.getVilles()) { p.add(ville.getNom() + "\n"); } cell = new PdfPCell(p); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 7 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.startdate"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph( ": " + mission.getStartDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + " Heure : " + mission.getStartDate().format(DateTimeFormatter.ofPattern("HH:mm")), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 8 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.enddate"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph( ": " + mission.getEndDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + " Heure : " + mission.getEndDate().format(DateTimeFormatter.ofPattern("HH:mm")), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 9 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.transport"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); switch (mission.getTransportType()) { case PERSONNEL: cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.perso") + " " + mission.getEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat") + " " + mission.getEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT)); break; case Accompagnement: cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.accomp") + " " + mission.getAccompEmploye().getCivilite() + " " + mission.getAccompEmploye().getFullName() + " " + msg.getMessage("mission.pdf.accomp.voitue") + " " + mission.getAccompEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat") + " " + mission.getAccompEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT)); break; case Service: cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.service") + " " + mission.getEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat") + " " + mission.getEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT)); break; default: { cell = new PdfPCell(new Paragraph( ": " + mission.getTransportType().getLabel() + " " + msg.getMessage("mission.pdf.taxi"), DEFAULT_FONT)); } } cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); table.setSpacingAfter(40); document.add(table); //note document.add(new Paragraph(msg.getMessage("mission.pdf.TEXT_2"), DEFAULT_FONT)); //signature if (mission.getEmploye().getGrade().getType() == GradeType.DG) { } else { Employe dir = employeService.getDG(); if (dir != null) paragraph = new Paragraph(dir.getFullName(), DEFAULT_FONT); paragraph.setAlignment(Element.ALIGN_RIGHT); paragraph.setSpacingBefore(40); document.add(paragraph); paragraph = new Paragraph(msg.getMessage("mission.pdf.DG"), DEFAULT_FONT); paragraph.setAlignment(Element.ALIGN_RIGHT); document.add(paragraph); } } catch (DocumentException ex) { ex.printStackTrace(); } catch (FileNotFoundException ex) { ex.printStackTrace(); } document.close(); // try { // Desktop.getDesktop().open(new File("./order.pdf")); // } catch (IOException ex) { // JOptionPane.showMessageDialog(null, "Fichier gner mais ne peut pas etre ouvert vrifier le dossier"); // } }
From source file:com.carfinance.module.common.controller.DocumentDownloadController.java
/** * ???PDF/*from w w w. ja v a 2 s . 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
/** * ??// w ww . j a v a 2s .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.centurylink.mdw.pdf.PdfExportHelper.java
License:Apache License
public byte[] exportProcess(Process process, File outputFile) throws Exception { new ActivityNodeSequencer(process).assignNodeSequenceIds(); Document document = new Document(); DocWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile)); document.open();//from w w w .ja va 2 s .c om document.setPageSize(PageSize.LETTER); Rectangle pageSize = document.getPageSize(); Chapter chapter = printProcessPdf(writer, 1, process, pageSize); document.add(chapter); document.close(); return Files.readAllBytes(Paths.get(outputFile.getPath())); }
From source file:com.coast.PDFPrinter_iText.java
License:Apache License
/** * Prints the document at its actual size. This is the recommended way to print. *//*www. j av a 2 s. c o m*/ private static void print(String pFileName, String pPayload) throws IOException, Exception { Document document = new Document(); // step 2 PdfWriter.getInstance(document, new FileOutputStream(pFileName)); // step 3 document.open(); // step 4 String _dateTime = LocalDateTime.now().toString(); document.addTitle("List of All Customers & their assets as of: " + _dateTime); document.addCreationDate(); document.addSubject("List of All Customers & their assets as of: " + _dateTime); Font _font = new Font(); _font.setColor(BaseColor.BLUE); _font.setStyle(Font.BOLD); _font.setSize(15); Chunk _chunk = new Chunk("List of All Customers & their assets as of: " + _dateTime); _chunk.setFont(_font); Paragraph _header = new Paragraph(); _header.add(_chunk); document.add(_header); document.add(new Paragraph(pPayload)); // step 5 document.close(); }
From source file:com.coderbd.pos.pdf.BarcodePdf.java
public void generateBarcodePdf(int amount) throws UnsupportedEncodingException { try {/*from www .j a v a2s .c o m*/ String filename = directory + "\\" + barcodeData + ".pdf"; Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); PdfContentByte cb = writer.getDirectContent(); Barcode128 code25 = new Barcode128(); code25.setGenerateChecksum(true); code25.setCode(barcodeData); code25.setSize(10f); code25.setX(1.50f); PdfPTable pdfPTable = new PdfPTable(3); float[] widths = { 0.45f, .10f, .45f }; pdfPTable.setWidths(widths); String codeName = getCodeName(shop.getShopName(), shop.getShopId(), amount); System.out.println("BarCodeName:" + codeName); Image image = code25.createImageWithBarcode(cb, null, null); Paragraph paragraph = new Paragraph(codeName); paragraph.setSpacingBefore(10.0f); PdfPCell title = new PdfPCell(paragraph); title.setBorder(Rectangle.NO_BORDER); PdfPCell barcodeCell = new PdfPCell(image, true); barcodeCell.setBorder(Rectangle.NO_BORDER); PdfPCell blank = new PdfPCell(); blank.setBorder(Rectangle.NO_BORDER); Paragraph blankParagraph = new Paragraph("- -"); PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph); pdfPCellBlank.setBorder(Rectangle.NO_BORDER); for (int i = 0; i < barcodeQuantity; i++) { /** * This is for barcode pdf title */ pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); /** * This is for barcode image */ pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); /** * Blank space after barcode image */ pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); } document.add(pdfPTable); document.close(); } catch (DocumentException | FileNotFoundException dex) { System.out.println(dex.getMessage()); } }
From source file:com.coderbd.pos.pdf.BarcodePdf.java
public void generateBarcodePdf(boolean fixedRate, Product p) throws UnsupportedEncodingException { try {/*from w w w . j a v a2s. com*/ String filename = directory + "\\" + barcodeData + ".pdf"; Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); PdfContentByte cb = writer.getDirectContent(); Barcode128 code25 = new Barcode128(); code25.setGenerateChecksum(true); code25.setCode(barcodeData); code25.setSize(10f); code25.setX(1.50f); PdfPTable pdfPTable = new PdfPTable(3); float[] widths = { 0.45f, .10f, .45f }; pdfPTable.setWidths(widths); String codeName = getCodeName(shop.getShopName(), shop.getShopId(), (int) p.getProductBuyRate()); System.out.println("BarCodeName:" + codeName); Image image = code25.createImageWithBarcode(cb, null, null); Paragraph paragraph = new Paragraph(codeName); paragraph.setSpacingBefore(10.0f); PdfPCell title = new PdfPCell(paragraph); title.setBorder(Rectangle.NO_BORDER); PdfPCell barcodeCell = new PdfPCell(image, true); barcodeCell.setBorder(Rectangle.NO_BORDER); PdfPCell blank = new PdfPCell(); blank.setBorder(Rectangle.NO_BORDER); Paragraph blankParagraph = new Paragraph("- -"); PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph); pdfPCellBlank.setBorder(Rectangle.NO_BORDER); for (int i = 0; i < barcodeQuantity; i++) { /** * This is for barcode pdf title */ pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); /** * This is for barcode image */ pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); /** * Blank space after barcode image */ pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); } document.add(pdfPTable); document.close(); } catch (DocumentException | FileNotFoundException dex) { System.out.println(dex.getMessage()); } }
From source file:com.coderbd.pos.pdf.CodePDF.java
public boolean genCodeVer2Pdf() throws UnsupportedEncodingException { if (isFixedRated == true) { barcodeQuantity = 12;//w w w. j av a2s. co m } else { barcodeQuantity = 15; } try { String filename = ""; if (isFixedRated) { filename = directory + "\\" + product.getProductBarcode() + "_FIXED_TK" + ".pdf"; } else { filename = directory + "\\" + product.getProductBarcode() + ".pdf"; } Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); PdfContentByte cb = writer.getDirectContent(); Barcode128 code25 = new Barcode128(); code25.setGenerateChecksum(true); code25.setCode(product.getProductBarcode()); code25.setSize(10f); code25.setX(1.50f); PdfPTable pdfPTable = new PdfPTable(7); pdfPTable.setWidthPercentage(98); float[] widths = { 0.22f, 0.04f, 0.22f, 0.04f, 0.22f, 0.04f, 0.22f }; pdfPTable.setWidths(widths); String codeName = getCodeName(product.getShop().getShopName(), product.getShop().getShopId(), (int) product.getProductBuyRate()); System.out.println("BarCodeName:" + codeName); Image image = code25.createImageWithBarcode(cb, null, null); Font titleArialFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL); Font priceFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.BOLD); Paragraph paragraph = new Paragraph(codeName, titleArialFont); paragraph.setSpacingBefore(10.0f); PdfPCell title = new PdfPCell(paragraph); title.setBorder(Rectangle.NO_BORDER); Paragraph fixedTKParagraph = new Paragraph("FIXED TK: " + product.getProductSellRate(), priceFont); PdfPCell fixedRateCell = new PdfPCell(fixedTKParagraph); fixedRateCell.setBorder(Rectangle.NO_BORDER); PdfPCell barcodeCell = new PdfPCell(image, true); barcodeCell.setBorder(Rectangle.NO_BORDER); PdfPCell blank = new PdfPCell(); blank.setBorder(Rectangle.NO_BORDER); Paragraph blankParagraph = new Paragraph("- -"); PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph); pdfPCellBlank.setBorder(Rectangle.NO_BORDER); for (int i = 0; i < barcodeQuantity; i++) { /** * This is for barcode pdf title */ pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); /** * This is for barcode image */ pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); /** * */ if (isFixedRated == true) { pdfPTable.addCell(fixedRateCell); pdfPTable.addCell(blank); pdfPTable.addCell(fixedRateCell); pdfPTable.addCell(blank); pdfPTable.addCell(fixedRateCell); pdfPTable.addCell(blank); pdfPTable.addCell(fixedRateCell); } /** * Blank space after barcode image */ pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); } document.add(pdfPTable); document.add(new Paragraph( "Shop Name: " + product.getShop().getShopName() + ", Name:" + product.getProductName() + "\n,Qty: " + product.getProductStock() + ", " + new Date().toString(), titleArialFont)); document.close(); return true; } catch (DocumentException | FileNotFoundException dex) { System.out.println(dex.getMessage()); return false; } }