List of usage examples for com.itextpdf.text Font Font
public Font(final BaseFont bf, final float size, final int style, final BaseColor color)
From source file:cis_690_report.Reporter.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed File1 = jTextField1.getText(); JFileChooser chooser = new JFileChooser(); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile() != null) { File3 = chooser.getSelectedFile().getAbsolutePath(); }//from w ww .j a va2 s. c om File file = new File(File1); try { br1 = new BufferedReader(new FileReader(file)); b1 = new BufferedReader(new FileReader(file)); } catch (FileNotFoundException ex) { } int number_of_rows1 = 0; String line = ""; String cvsSplitBy = ","; try { while ((line = br1.readLine()) != null) { // use comma as separator number_of_rows1++; } } catch (IOException ex) { Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex); } bull1 = new String[number_of_rows1][]; int k = 0; BufferedReader br2 = null; try { br2 = new BufferedReader(new FileReader(file)); } catch (FileNotFoundException ex) { } try { while ((line = br2.readLine()) != null) { // use comma as separator String Bull[] = line.split(","); System.out.println(Bull.length); bull1[k] = new String[93]; if (Bull.length < 10) { for (int j = 0; j < 92; j++) { bull1[k][j] = ""; //System.out.println(Bull[j]); } } else { for (int j = 0; j < Bull.length; j++) { bull1[k][j] = Bull[j]; //System.out.println(Bull[j]); } } k++; } } catch (IOException ex) { } Document doc = new Document(); PdfWriter docWriter = null; DecimalFormat df = new DecimalFormat("0.00"); try { //special font sizes Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 8, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 6); Font bfBold20 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD); //file path docWriter = PdfWriter.getInstance(doc, new FileOutputStream(File3)); //document header attributes doc.addAuthor("Shubh Chopra"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Shubh Chopra"); doc.addTitle("BES"); doc.setPageSize(PageSize.LETTER.rotate()); //open document doc.open(); //create a paragraph Paragraph paragraph = new Paragraph("BULL EVALUATION\n\n"); paragraph.setFont(bfBold20); paragraph.setAlignment(Element.ALIGN_CENTER); Image img = Image.getInstance("VETMED.png"); img.scaleToFit(300f, 150f); doc.add(paragraph); PdfPTable table1 = new PdfPTable(2); table1.setWidthPercentage(100); PdfPCell cell = new PdfPCell(img); cell.setBorder(PdfPCell.NO_BORDER); table1.addCell(cell); String temp1 = "\tOwner: " + bull1[1][78] + " " + bull1[1][79] + "\n\n\tRanch: " + bull1[1][80] + "\n\n\tAddress: " + bull1[1][71] + "\n\n\tCity: " + bull1[1][73] + "\n\n\tState: " + bull1[1][76] + "\tZip: " + bull1[1][77] + "\n\n\tPhone: " + bull1[1][75] + "\n\n"; table1.addCell(getCell(temp1, PdfPCell.ALIGN_LEFT)); doc.add(table1); boolean[] checkboxs = { jCheckBox1.isSelected(), jCheckBox2.isSelected(), jCheckBox3.isSelected(), jCheckBox4.isSelected(), jCheckBox5.isSelected(), jCheckBox6.isSelected(), jCheckBox7.isSelected(), jCheckBox8.isSelected(), jCheckBox9.isSelected(), jCheckBox10.isSelected(), jCheckBox11.isSelected(), jCheckBox12.isSelected(), jCheckBox13.isSelected() }; //specify column widths int temp = 0; for (int x = 0; x < checkboxs.length; x++) { if (checkboxs[x] == true) { temp++; } } float[] columnWidths = new float[temp + 5]; for (int x = 0; x < columnWidths.length; x++) { if (x < 5) columnWidths[x] = 1f; else if (jCheckBox1.isSelected() && x == 5) columnWidths[x] = 2f; else if (jCheckBox2.isSelected() && jCheckBox3.isSelected() && x == 7) columnWidths[x] = 2f; else if (!jCheckBox2.isSelected() && jCheckBox3.isSelected() && x == 6) columnWidths[x] = 2f; else if (jCheckBox4.isSelected() && x == columnWidths.length - 2) columnWidths[x] = 2f; else if (jCheckBox5.isSelected() && x == columnWidths.length - 1) columnWidths[x] = 2f; else columnWidths[x] = 1f; } //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); // set table width a percentage of the page width table.setWidthPercentage(90f); Reporter re; re = new Reporter(); //insert column headings re.insertCell(table, "ID-Tag", Element.ALIGN_CENTER, 1, bfBold12); re.insertCell(table, "ID-Tatto", Element.ALIGN_CENTER, 1, bfBold12); re.insertCell(table, "ID-RFID", Element.ALIGN_CENTER, 1, bfBold12); re.insertCell(table, "ID-Brand", Element.ALIGN_CENTER, 1, bfBold12); re.insertCell(table, "ID-Other", Element.ALIGN_CENTER, 1, bfBold12); if (jCheckBox1.isSelected()) re.insertCell(table, "Age", Element.ALIGN_CENTER, 1, bfBold12); if (jCheckBox2.isSelected()) re.insertCell(table, "Scrotal", Element.ALIGN_CENTER, 1, bfBold12); if (jCheckBox3.isSelected()) re.insertCell(table, "Motility", Element.ALIGN_CENTER, 1, bfBold12); if (jCheckBox6.isSelected()) re.insertCell(table, "Normal", Element.ALIGN_CENTER, 1, bfBold12); if (jCheckBox7.isSelected()) re.insertCell(table, "M2", Element.ALIGN_CENTER, 1, bfBold12); if (jCheckBox8.isSelected()) re.insertCell(table, "M3", Element.ALIGN_CENTER, 1, bfBold12); if (jCheckBox9.isSelected()) re.insertCell(table, "M4", Element.ALIGN_CENTER, 1, bfBold12); if (jCheckBox10.isSelected()) re.insertCell(table, "M5", Element.ALIGN_CENTER, 1, bfBold12); if (jCheckBox11.isSelected()) re.insertCell(table, "M6", Element.ALIGN_CENTER, 1, bfBold12); if (jCheckBox12.isSelected()) re.insertCell(table, "M7", Element.ALIGN_CENTER, 1, bfBold12); if (jCheckBox13.isSelected()) re.insertCell(table, "M8", Element.ALIGN_CENTER, 1, bfBold12); if (jCheckBox4.isSelected()) re.insertCell(table, "Comments", Element.ALIGN_CENTER, 1, bfBold12); if (jCheckBox5.isSelected()) re.insertCell(table, "Classification", Element.ALIGN_CENTER, 1, bfBold12); table.setHeaderRows(1); //insert an empty row //create section heading by cell merging //just some random data to fill for (int x = 1; x < number_of_rows1; x++) { re.insertCell(table, bull1[x][7], Element.ALIGN_CENTER, 1, bf12); re.insertCell(table, bull1[x][8], Element.ALIGN_CENTER, 1, bf12); re.insertCell(table, bull1[x][6], Element.ALIGN_CENTER, 1, bf12); re.insertCell(table, bull1[x][2], Element.ALIGN_CENTER, 1, bf12); re.insertCell(table, bull1[x][9], Element.ALIGN_CENTER, 1, bf12); if (jCheckBox1.isSelected()) re.insertCell(table, bull1[x][0], Element.ALIGN_CENTER, 1, bf12); if (jCheckBox2.isSelected()) re.insertCell(table, bull1[x][70], Element.ALIGN_CENTER, 1, bf12); if (jCheckBox3.isSelected()) re.insertCell(table, bull1[x][61], Element.ALIGN_CENTER, 1, bf12); if (jCheckBox6.isSelected()) re.insertCell(table, bull1[x][43], Element.ALIGN_CENTER, 1, bf12); if (jCheckBox7.isSelected()) re.insertCell(table, bull1[x][45], Element.ALIGN_CENTER, 1, bf12); if (jCheckBox8.isSelected()) re.insertCell(table, bull1[x][47], Element.ALIGN_CENTER, 1, bf12); if (jCheckBox9.isSelected()) re.insertCell(table, bull1[x][49], Element.ALIGN_CENTER, 1, bf12); if (jCheckBox10.isSelected()) re.insertCell(table, bull1[x][51], Element.ALIGN_CENTER, 1, bf12); if (jCheckBox11.isSelected()) re.insertCell(table, bull1[x][53], Element.ALIGN_CENTER, 1, bf12); if (jCheckBox12.isSelected()) re.insertCell(table, bull1[x][55], Element.ALIGN_CENTER, 1, bf12); if (jCheckBox13.isSelected()) re.insertCell(table, bull1[x][57], Element.ALIGN_CENTER, 1, bf12); if (jCheckBox4.isSelected()) re.insertCell(table, "", Element.ALIGN_CENTER, 1, bf12); if (jCheckBox5.isSelected()) re.insertCell(table, bull1[x][35], Element.ALIGN_CENTER, 1, bf12); } doc.add(table); } catch (DocumentException dex) { dex.printStackTrace(); } catch (FileNotFoundException ex) { Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex); } finally { if (doc != null) { //close the document doc.close(); } if (docWriter != null) { //close the writer docWriter.close(); } } // TODO add your handling code here: } //GEN-LAST:event_jButton1ActionPerformed }
From source file:client.welcome2.java
private void genRepButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_genRepButtonActionPerformed Document doc = new Document(); PdfWriter docWriter = null;//from w w w . j av a 2s. c o m int repID = ThreadLocalRandom.current().nextInt(10000, 99999 + 1); DecimalFormat df = new DecimalFormat("0.00"); //Date d = Calendar.getInstance().getTime(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); Date date = new Date(); try { //special font sizes Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 12); //file path String dt = dateFormat.format(date); sFileName = "Report No- " + repID + " Project Report- " + dt + " Status " + report_status + " .pdf"; String path = "src/ProjectReports/" + sFileName; docWriter = PdfWriter.getInstance(doc, new FileOutputStream(path)); DateFormat dateFormat3 = new SimpleDateFormat("dd/MM/yyyy HH:mm"); String d = dateFormat3.format(Calendar.getInstance().getTime()); //document header attributes doc.addCreationDate(); doc.setPageSize(PageSize.LETTER); //open document doc.open(); //create a paragraph DateFormat dateFormat2 = new SimpleDateFormat("dd/MM/yyyy"); String sd2 = dateFormat2.format(pBeginDateChooser.getDate()); String ed2 = dateFormat2.format(pEndDateChooser.getDate()); Image image = Image.getInstance("src/Images/logo for pdf.png"); Font font1 = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD); Paragraph paragraph = new Paragraph(); Paragraph paragraph2 = new Paragraph("This report was generated by " + loginGUI.username + " at " + d + "\nYou can see all projects from " + sd2 + " to " + ed2); image.setAlignment(Image.RIGHT); doc.add(image); //specify column widths float[] columnWidths = { 2f, 2f, 2f, 2f, 2f }; //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); // set table width a percentage of the page width table.setWidthPercentage(100f); //insert column headings insertCell(table, "Project ID", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Project Name", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Start Date", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Due Date", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Status", Element.ALIGN_CENTER, 1, bfBold12); table.setHeaderRows(1); //insert an empty row /* insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);*/ //create section heading by cell merging /* insertCell(table, "New York Orders ...", Element.ALIGN_LEFT, 4, bfBold12);*/ /*double orderTotal, total = 0;*/ String add1, add2, add3, add4, add5; DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd"); String sd = dateFormat1.format(pBeginDateChooser.getDate()); String ed = dateFormat1.format(pEndDateChooser.getDate()); if (report_status.equals("All")) { try { String sql = "select project_id,project_name,start_date,due_date,status from projects where due_date >= '" + sd + "' and due_date <= '" + ed + "' and start_date >= '" + sd + "'and start_date <= '" + ed + "'"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { add1 = rs.getString("project_id"); add2 = rs.getString("project_name"); add3 = dateFormat.format(rs.getDate("start_date")); add4 = dateFormat.format(rs.getDate("due_date")); add5 = rs.getString("status"); insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } else { try { String sql = "select project_id,project_name,start_date,due_date,status from projects where status = '" + report_status + "' and due_date >= '" + sd + "' and due_date <= '" + ed + "' and start_date >= '" + sd + "'and start_date <= '" + ed + "'"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { add1 = rs.getString("project_id"); add2 = rs.getString("project_name"); add3 = dateFormat.format(rs.getDate("start_date")); add4 = dateFormat.format(rs.getDate("due_date")); add5 = rs.getString("status"); insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } //add the PDF table to the paragraph paragraph2.add(table); // add the paragraph to the document doc.add(new Paragraph("\nProject Status Report " + dt + "\n", font1)); doc.add(paragraph2); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } finally { if (doc != null) { //close the document doc.close(); JOptionPane.showMessageDialog(null, "Report No " + repID + " Generated!"); } if (docWriter != null) { //close the writer docWriter.close(); } } saveToDB(report_status, date, repID); }
From source file:client.welcome3.java
private void genRepButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_genRepButtonActionPerformed Document doc = new Document(); PdfWriter docWriter = null;/* www.ja va 2 s.co m*/ int repID = ThreadLocalRandom.current().nextInt(10000, 99999 + 1); DecimalFormat df = new DecimalFormat("0.00"); //Date d = Calendar.getInstance().getTime(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); Date date = new Date(); try { //special font sizes Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 12); //file path String dt = dateFormat.format(date); sFileName = "Report No- " + repID + " Project Report- " + dt + " Status " + report_status + " .pdf"; String path = "src/ProjectReports/" + sFileName; docWriter = PdfWriter.getInstance(doc, new FileOutputStream(path)); DateFormat dateFormat3 = new SimpleDateFormat("dd/MM/yyyy HH:mm"); String d = dateFormat3.format(Calendar.getInstance().getTime()); //document header attributes doc.addCreationDate(); doc.setPageSize(PageSize.LETTER); //open document doc.open(); //create a paragraph DateFormat dateFormat2 = new SimpleDateFormat("dd/MM/yyyy"); String sd2 = dateFormat2.format(pBeginDateChooser.getDate()); String ed2 = dateFormat2.format(pEndDateChooser.getDate()); Image image = Image.getInstance("src/Images/logo for pdf.png"); Font font1 = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD); Paragraph paragraph = new Paragraph(); Paragraph paragraph2 = new Paragraph("This report was generated by " + loginGUI.username + " at " + d + "\nYou can see all projects from " + sd2 + " to " + ed2); image.setAlignment(Image.RIGHT); doc.add(image); //specify column widths float[] columnWidths = { 2f, 2f, 2f, 2f, 2f }; //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); // set table width a percentage of the page width table.setWidthPercentage(100f); //insert column headings insertCell(table, "Project ID", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Project Name", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Start Date", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Due Date", Element.ALIGN_CENTER, 1, bfBold12); insertCell(table, "Status", Element.ALIGN_CENTER, 1, bfBold12); table.setHeaderRows(1); //insert an empty row /* insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);*/ //create section heading by cell merging /* insertCell(table, "New York Orders ...", Element.ALIGN_LEFT, 4, bfBold12);*/ /*double orderTotal, total = 0;*/ String add1, add2, add3, add4, add5; DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd"); String sd = dateFormat1.format(pBeginDateChooser.getDate()); String ed = dateFormat1.format(pEndDateChooser.getDate()); if (report_status.equals("All")) { try { String sql = "select project_id,project_name,start_date,due_date,status from projects where due_date >= '" + sd + "' and due_date <= '" + ed + "' and start_date >= '" + sd + "'and start_date <= '" + ed + "'"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { add1 = rs.getString("project_id"); add2 = rs.getString("project_name"); add3 = dateFormat.format(rs.getDate("start_date")); add4 = dateFormat.format(rs.getDate("due_date")); add5 = rs.getString("status"); insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } else { try { String sql = "select project_id,project_name,start_date,due_date,status from projects where status = '" + report_status + "' and due_date >= '" + sd + "' and due_date <= '" + ed + "' and start_date >= '" + sd + "'and start_date <= '" + ed + "'"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { add1 = rs.getString("project_id"); add2 = rs.getString("project_name"); add3 = dateFormat.format(rs.getDate("start_date")); add4 = dateFormat.format(rs.getDate("due_date")); add5 = rs.getString("status"); insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12); insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } //add the PDF table to the paragraph paragraph2.add(table); // add the paragraph to the document doc.add(new Paragraph("\nProject Status Report " + dt + "\n", font1)); doc.add(paragraph2); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } finally { if (doc != null) { //close the document doc.close(); JOptionPane.showMessageDialog(null, "Report No " + repID + " Generated!"); } if (docWriter != null) { //close the writer docWriter.close(); } } saveToDB(report_status, date, repID); }
From source file:com.carfinance.module.common.controller.DocumentDownloadController.java
/** * ???PDF//w ww . java2 s. c om * @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 w w . j av a 2 s. com*/ * @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 va2s . c o 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.github.ukase.service.PdfRenderer.java
License:Open Source License
@Autowired private PdfRenderer(WaterMarkSettings settings, ResourceProvider provider) throws IOException, DocumentException { this.provider = provider; this.waterMark = settings; BaseFont baseFont = BaseFont.createFont(provider.getDefaultFont(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); this.font = new Font(baseFont, waterMark.getSize(), 0, BaseColor.LIGHT_GRAY); }
From source file:com.gp.cong.logisoft.lcl.report.LclVoyageNotificationPdfCreator.java
public PdfPTable thankyouMsg(String contextPath) throws DocumentException, Exception { BaseFont palationRomanBase = BaseFont.createFont(contextPath + "/ttf/palabi.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);//from w w w .j av a 2 s.c o m Font palatinoRomanSmallFont = new Font(palationRomanBase, 8.5f, Font.ITALIC, new BaseColor(00, 102, 12)); table = new PdfPTable(1); table.setWidthPercentage(100f); table.addCell(createEmptyCell(0, 10f, 0)); cell = new PdfPCell(); cell.setBorder(0); Paragraph pContent = new Paragraph(8f, "Thank you for choosing Econocaribe Consolidators, Inc. for your international shipping needs. \n Please contact us if you have any questions at 1-866-ECONO-IT (866-326-6648) or visit us at www.econocaribe.com.", palatinoRomanSmallFont); pContent.setAlignment(Element.ALIGN_CENTER); cell.addElement(pContent); table.addCell(cell); return table; }
From source file:com.nlbhub.nlb.domain.export.hypertext.document.PDFFont.java
License:Open Source License
public PDFFont(float size, Style style, RGBColor color) throws HTDocumentException { try {/*from w w w.j a va2s . c o m*/ BaseFont baseFont = (BaseFont.createFont("fonts/ttf/dejavu/DejaVuSans.ttf", "cp1251", BaseFont.EMBEDDED)); int iStyle; switch (style) { case BOLD: iStyle = Font.BOLD; break; case ITALIC: iStyle = Font.ITALIC; break; case UNDERLINE: iStyle = Font.UNDERLINE; break; default: iStyle = Font.NORMAL; break; } m_font = new Font(baseFont, size, iStyle, new BaseColor(color.getRed(), color.getGreen(), color.getBlue())); } catch (DocumentException | IOException e) { throw new HTDocumentException("Error while creating PDF font", e); } }
From source file:com.photoshop.misc.Factuurgenerator.java
private void creatCell(String cellnaam, PdfPTable table, boolean header) { if (header == true) { Font font = new Font(FontFamily.HELVETICA, 12, Font.BOLD, BaseColor.WHITE); PdfPCell c1 = new PdfPCell(new Phrase(cellnaam, font)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBackgroundColor(new BaseColor(0, 121, 182)); c1.setMinimumHeight(20);/*from w w w.j av a 2 s.c o m*/ table.addCell(c1); } if (header == false) { PdfPCell c1 = new PdfPCell(new Phrase(cellnaam)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } }