List of usage examples for com.itextpdf.text Font BOLD
int BOLD
To view the source code for com.itextpdf.text Font BOLD.
Click Source Link
From source file:digiho.DigiHoInitial1.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: jDate1.setText(""); Calendar timer = Calendar.getInstance(); timer.getTime();//from w w w.j a v a2 s. com SimpleDateFormat Tdate = new SimpleDateFormat("dd-MMM-yyy"); jDate1.setText(Tdate.format(timer.getTime())); Document doc = new Document(); try { PdfWriter.getInstance(doc, new FileOutputStream("f:\\DiGiho\\Complaint From\\" + jCustomer1.getText() + ".pdf")); doc.open(); doc.add(new Paragraph("\n", FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.DARK_GRAY))); doc.add(new Paragraph("\n\n\n\n\n\n\n\n\n\n")); doc.add(new Phrase("Customer ID.: ")); doc.add(new Phrase(jCustomer1.getText(), FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); doc.add(new Phrase(" Date: " + jDate1.getText() + " \n\n")); doc.add(new Phrase("Name: ")); doc.add(new Phrase(jName1.getText() + ". " + jName2.getText() + " " + jName3.getText(), FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); doc.add(new Phrase("\nFather's Name: ")); doc.add(new Phrase(jFatherName1.getText(), FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); doc.add(new Phrase("\nAddress: ")); doc.add(new Phrase(jAddress1.getText(), FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); doc.add(new Phrase("\nBlock: ")); doc.add(new Phrase(jBlock1.getText(), FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); doc.add(new Phrase("\nCity: ")); doc.add(new Phrase(jCity1.getText(), FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); doc.add(new Phrase("\nDistrict: ")); doc.add(new Phrase(jDistrict1.getText(), FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); doc.add(new Phrase("\nMoblie No.: ")); doc.add(new Phrase(jMobile1.getText(), FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); doc.add(new Paragraph("\n\n\n\n\n\n")); doc.add(new Paragraph(" (1) " + jTextField2.getText())); doc.add(new Paragraph(" (2) " + jcomplain1.getText())); doc.add(new Paragraph(" (3) " + jcomplain3.getText())); doc.add(new Paragraph(" (4) " + jcomplain4.getText())); doc.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (FileNotFoundException ex) { Logger.getLogger(DigiHoInitial1.class.getName()).log(Level.SEVERE, null, ex); } JOptionPane.showMessageDialog(null, "File has been created", "deeps message", JOptionPane.WARNING_MESSAGE); }
From source file:direccion.GeneradorFormato.java
@Override public void onEndPage(PdfWriter writer, Document document) { Rectangle rect = writer.getBoxSize("art"); Image imghead = null;/* w w w.j a va 2 s . co m*/ PdfContentByte cbhead = null; // try { // imghead = Image.getInstance("LogoSapito5.png"); // imghead.setAbsolutePosition(0, 0); // imghead.setAlignment(Image.ALIGN_CENTER); // imghead.scalePercent(10f); // cbhead = writer.getDirectContent(); // PdfTemplate tp = cbhead.createTemplate(100, 150); // tp.addImage(imghead); // cbhead.addTemplate(tp, 100, 715); // } catch (BadElementException e) { // e.printStackTrace(); // } catch (IOException e) { // e.printStackTrace(); // } catch (DocumentException e) { // e.printStackTrace(); // } Phrase headPhraseImg = new Phrase(cbhead + "", FontFactory.getFont(FontFactory.TIMES_ROMAN, 7, Font.NORMAL)); Calendar c1 = Calendar.getInstance(); Calendar c2 = new GregorianCalendar(); String dia, mes, annio; dia = Integer.toString(c1.get(Calendar.DATE)); mes = Integer.toString(c1.get(Calendar.MONTH)); annio = Integer.toString(c1.get(Calendar.YEAR)); Date fecha = new Date(); String fechis = dia + "/" + mes + "/" + annio; Paragraph parrafo5 = new Paragraph(fechis, FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLACK)); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(parrafo5), rect.getRight(450), rect.getTop(-80), 0); Paragraph parrafo7 = new Paragraph("Empresa Sapito S.A. de C.V.", FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK)); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(parrafo7), rect.getBottom(250), rect.getTop(-60), 0); Paragraph parrafo8 = new Paragraph("Reporte algoooooo", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD, BaseColor.BLACK)); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(parrafo8), rect.getBottom(250), rect.getTop(-40), 0); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_BOTTOM, new Phrase( " _____________________________________________________________________________________ "), rect.getBorder(), rect.getTop(650), 0); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_BOTTOM, new Phrase( " _____________________________________________________________________________________ "), rect.getBorder(), rect.getTop(-24), 0); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_BOTTOM, new Phrase( " _____________________________________________________________________________________ "), rect.getBorder(), rect.getTop(-20), 0); Paragraph parrafo6 = new Paragraph(String.format("Pg %d", writer.getPageNumber()), FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLACK)); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(parrafo6), rect.getRight(-35), rect.getTop(-80), 0); }
From source file:documentos.PlanillaServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//www . j av a 2s . co m * * @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, SQLException { response.setContentType("application/pdf"); Connection conexion = null; HttpSession session = request.getSession(true); try { conexion = ds.getConnection(); edificioDAO edifDAO = new edificioDAO(); edifDAO.setConexion(conexion); usuarioDAO usuDAO = new usuarioDAO(); usuDAO.setConexion(conexion); //obtener variable boolean error = false; String idString = (String) request.getParameter("id_edificio"); int idEdificio = 0; try { idEdificio = Integer.parseInt(idString); } catch (Exception ex) { System.out.println("Error al convertir variables :" + ex); error = true; } //obtener datos de edificio segun el id edificio edif = new edificio(); edif = edifDAO.findbyIdEdificio(idEdificio); DetalleEdificioDAO detEdifDAO = new DetalleEdificioDAO(); detEdifDAO.setConexion(conexion); administradorDAO adminDAO = new administradorDAO(); adminDAO.setConexion(conexion); //obtener admin Edificio administrador admin = new administrador(); admin = adminDAO.findbyIdEdificio(idEdificio); //obtener datos de detalleEdif detalleEdificio detalleEdif = new detalleEdificio(); detalleEdif = detEdifDAO.findbyIdEdificio(idEdificio); //obtener datos de usuario segun id edificio usuario usuario = new usuario(); usuario = usuDAO.findbyIdUsuarios(edif.getIdUsuario()); //guardar datos de edif en variables separadas String nombreVendedor = usuario.getNombre(); String apellidoVendedor = usuario.getApellido(); int annoNorma = edif.getAnoEdificio(); String ubicacionMed = detalleEdif.getUbicacionMedidores(); String ciige = detalleEdif.getCiigeAnterior(); String testDePruebas = detalleEdif.getDespiche(); String nombreEdif = edif.getNombreEdificio(); String correo = admin.getEmailAdmin(); String fonoAdmin = admin.getTelefonoAdmin(); String fonoEdif = edif.getTelefonoEdificio(); String rutEdif = edif.getRutEdificio(); String dirEdif = edif.getDireccionEdificio(); String nomAdmin = admin.getNombreAdmin(); String rutAdmin = admin.getRutAdmin(); int cantidadDe = edif.getCantCasas() + edif.getCantDepartamentos() + edif.getCantLocales() + edif.getCantLavanderias(); int cantPisos = edif.getCantPisos(); int idEmpresaGas = edif.getIdGas(); //determinar el nombre de la empresa de gas segun su id String empresagas = ""; if (idEmpresaGas == 1) { empresagas = "GASVALPO"; } if (idEmpresaGas == 2) { empresagas = "LIPIGAS"; } if (idEmpresaGas == 3) { empresagas = "ABASTIBLE"; } if (idEmpresaGas == 4) { empresagas = "GASCO"; } if (idEmpresaGas == 5) { empresagas = "OTROS"; } int annoEdif = edif.getAnoEdificio(); int potencia = edif.getPotenciaReal(); int cantidaConductos = edif.getCantConductos(); int cantidadCalderas = edif.getCantCalderas(); //Crear documento Document document = new Document(); Image logo = Image.getInstance(getClass().getResource("logo.png")); PdfWriter.getInstance(document, response.getOutputStream()); Font fuenteNegrita = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD); Font fuenteNormal = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL); Font fuenteEPiePagina = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.BOLD); Font fuentePiePagina = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD); // step 3 document.open(); // step 4 logo.setAbsolutePosition(270f, 750f); logo.scalePercent(65f); PdfPTable tablaEncabezado = new PdfPTable(2); PdfPTable tablaContenido = new PdfPTable(2); tablaEncabezado.addCell(new Paragraph("PLANILLA CIIG-e INSPECCIN PERIODICA")); tablaEncabezado.addCell(logo); tablaContenido.setSpacingBefore(15); tablaContenido.setSpacingAfter(20); tablaContenido.addCell(new Paragraph("VENDEDORA", fuenteNormal)); tablaContenido.addCell(new Paragraph(nombreVendedor + " " + apellidoVendedor, fuenteNormal)); tablaContenido.addCell(new Paragraph("AO DEL EDIFICIO Y NORMA APLICAR", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(annoEdif), fuenteNormal)); tablaContenido .addCell(new Paragraph("UBICACIN MEDIDORES: EN LOS PISOS, FUERA DEL EDIFICO", fuenteNormal)); tablaContenido.addCell(new Paragraph(ubicacionMed, fuenteNormal)); tablaContenido .addCell(new Paragraph("NRO CIIGE DE LA INSPECCION ANTERIOR (VER PAGINA SEC)", fuenteNormal)); tablaContenido.addCell(new Paragraph(ciige, fuenteNormal)); tablaContenido.addCell(new Paragraph("T DE PRUEBAS, DESPICHE OTRO (COCINA)", fuenteNormal)); tablaContenido.addCell(new Paragraph(testDePruebas, fuenteNormal)); tablaContenido.addCell(new Paragraph("NOMBRE: EDIFICIO, CONDOMINIO, PROPIETARIO, ETC.", fuenteNormal)); tablaContenido.addCell(new Paragraph(nombreEdif, fuenteNormal)); tablaContenido.addCell(new Paragraph("CORREO ELECTRONICO", fuenteNormal)); tablaContenido.addCell(new Paragraph(correo, fuenteNormal)); tablaContenido.addCell(new Paragraph("FONO ADMINISTRADOR /FONO EDIFICIO", fuenteNormal)); tablaContenido.addCell(new Paragraph("Fono Administrador :" + fonoAdmin + " Fono Edificio :" + fonoEdif, fuenteNormal)); tablaContenido.addCell(new Paragraph("R.U.T EDIFICIO, CONDOMINIO, PROPIETARIOS, ETC.", fuenteNormal)); tablaContenido.addCell(new Paragraph(rutEdif, fuenteNormal)); tablaContenido.addCell(new Paragraph("DIRECCIN DEL EDIFICO", fuenteNormal)); tablaContenido.addCell(new Paragraph(dirEdif, fuenteNormal)); tablaContenido.addCell(new Paragraph("NOMBRE ADMINISTRADOR, PROPIETARIO, ETC.", fuenteNormal)); tablaContenido.addCell(new Paragraph(nomAdmin, fuenteNormal)); tablaContenido.addCell(new Paragraph("RUT: ADMINISTRADOR, PROPIETARIO, ETC.", fuenteNormal)); tablaContenido.addCell(new Paragraph(rutAdmin, fuenteNormal)); tablaContenido.addCell(new Paragraph("CANTIDAD DE: DEPTOS, CASAS, LOCALES, ETC.", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(cantidadDe), fuenteNormal)); tablaContenido.addCell(new Paragraph("CANTIDAD DE PISOS INMUEBLE", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(cantPisos), fuenteNormal)); tablaContenido.addCell(new Paragraph("EMPRESA DISTRIBUIDORA DE GAS", fuenteNormal)); tablaContenido.addCell(new Paragraph(empresagas, fuenteNormal)); tablaContenido.addCell(new Paragraph("CANTIDAD DE INSTALACIONES", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(cantidadDe), fuenteNormal)); tablaContenido.addCell(new Paragraph("TIPO DE ARTEFACTOS INSTALADOS", fuenteNormal)); tablaContenido.addCell(new Paragraph("", fuenteNormal)); tablaContenido.addCell(new Paragraph("POTENCIA TOTAL INSTALADA", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(potencia), fuenteNormal)); tablaContenido.addCell(new Paragraph("CANTIDAD DE CONDUCTOS COLECTIVOS", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(cantidaConductos), fuenteNormal)); tablaContenido.addCell(new Paragraph("CANTIDAD DE CALDERAS CENTRALES", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(cantidadCalderas), fuenteNormal)); document.add(tablaEncabezado); document.add(tablaContenido); Paragraph textoIng = new Paragraph("IngeneriaRSLimitada", fuenteEPiePagina); textoIng.setAlignment(Element.ALIGN_CENTER); Paragraph textPie = new Paragraph( "Calle Montaa 754 Oficina 37-A Via Del Mar / ingenieria.sr@gmail.com - Fono 032-2697175 / 92564059", fuentePiePagina); textPie.setAlignment(Element.ALIGN_CENTER); document.add(textoIng); document.add(textPie); document.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } }
From source file:domain.Pdfmaker.java
public void makePdf() { Document doc = new Document(); doc.setPageSize(PageSize.A4);//from w w w . j a v a 2s . com try { PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(test.getTitle() + ".pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_7); doc.open(); Font f = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.BOLD, new BaseColor(0, 0, 0)); Paragraph title = new Paragraph("TEST TITLE", f); title.setAlignment(Element.ALIGN_CENTER); doc.addCreator("Arne De Bremme"); //make table PdfPTable table = new PdfPTable(4); table.setTotalWidth(550f); table.setLockedWidth(true); table.setHeaderRows(1); Paragraph p = new Paragraph(test.getTitle()); p.setAlignment(Element.ALIGN_CENTER); PdfPCell cell = new PdfPCell(p); cell.setGrayFill(0.7f); cell.setColspan(4); table.addCell(cell); table.addCell(test.getClassGroup().getGroupName()); PdfPCell cell2 = new PdfPCell(new Paragraph(test.getDescription())); cell2.setColspan(2); cell2.setRowspan(2); table.addCell(cell2); PdfPCell cell3 = new PdfPCell(new Paragraph("DD " + test.getStartDate().getDay() + "/" + test.getStartDate().getMonth() + "/" + test.getStartDate().getYear())); cell3.setRowspan(2); table.addCell(cell3); table.addCell(new Paragraph("Test " + test.getTestId())); doc.add(table); doc.add(Chunk.NEWLINE); for (Exercise e : ex) { Paragraph par = new Paragraph(); par.add("Vraag " + counter); par.add(Chunk.TABBING); par.add(Chunk.TABBING); par.add(Chunk.TABBING); par.add(Chunk.TABBING); par.add(e.getPunten() + "/"); doc.add(par); doc.add(new Paragraph("Klimatogram " + e.getClimateChart().getLocation() + " " + e.getPunten())); Robot r = new Robot(); Desktop.getDesktop().browse(new URI( "http://climatechart.azurewebsites.net/ClimateChart/ShowExercises?selectedYear=1&continentId=" + e.getClimateChart().getCountry().getContinent().getId() + "&countryId=" + e.getClimateChart().getCountry().getContinent().getId() + "&climateId=" + e.getClimateChart().getId())); TimeUnit.SECONDS.sleep(6); BufferedImage bi = r.createScreenCapture( new Rectangle(Toolkit.getDefaultToolkit().getScreenSize().width * 7 / 10, Toolkit.getDefaultToolkit().getScreenSize().width * 8 / 14)); File file = new File("screenCapture" + counter + ".jpg"); ImageIO.write(bi, "jpg", file); Image img = Image.getInstance("screenCapture.jpg"); img.scaleAbsolute(400, 300); doc.add(img); doc.add(Chunk.NEWLINE); doc.add(new Paragraph(e.getNaam())); doc.add(Chunk.NEXTPAGE); counter++; } doc.close(); File filz = new File(test.getTitle() + ".pdf"); Desktop.getDesktop().open(filz); } catch (Exception e) { } }
From source file:ECS.create.java
create() { //geting the file path from Page. String dpath = Page.dpath;// ww w . jav a2s . c o m try { //define program "information" as data information data = new information(); //crate a PDF File Document cs = new Document(); //locate where the PDF save. FileOutputStream local = new FileOutputStream(dpath); //New PDF location PdfWriter writer = PdfWriter.getInstance(cs, local); //Edit Propety of the PDF cs.addTitle("Title@CoverSheet"); cs.addAuthor("Author@rensanning"); cs.addSubject("Subject@iText sample"); cs.addKeywords("Keywords@iText"); cs.addCreator("Creator@iText"); //Seting the Font of the text in the PDF Font title = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD); //Font stitle = new Font(Font.FontFamily.COURIER, 18,Font.ITALIC | Font.UNDERLINE); Font stitle = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD); Font usual = new Font(Font.FontFamily.TIMES_ROMAN, 18); // open the PDF File cs.open(); PdfContentByte canvas = writer.getDirectContent(); // insert the information in the PDF //group the information into paragrph Paragraph sinfo = new Paragraph(); //using the data form the database which geting by program "information" sinfo.add(new Chunk("Name: " + data.fn + " " + data.ln, title)); //cs.add(Chunk.NEWLINE); sinfo.add(new Chunk(" ")); sinfo.add(new Chunk("SID: " + data.sid, title)); sinfo.setLeading(40); //sinfo.add(Chunk.NEWLINE); cs.add(sinfo); Paragraph cinfo = new Paragraph(); cinfo.add(new Chunk("Course: " + data.cid + " " + data.cn, stitle)); cinfo.setLeading(30); cinfo.add(Chunk.NEWLINE); cs.add(cinfo); Paragraph minfo = new Paragraph(); minfo.add(new Chunk("Module: ", stitle)); minfo.add(new Chunk(data.mid + " " + data.mn, usual)); minfo.setLeading(30); minfo.add(Chunk.NEWLINE); cs.add(minfo); // insert the information in the PDF Paragraph cwinfo = new Paragraph(); cwinfo.add(new Chunk("Coursework ID: ", stitle)); cwinfo.add(new Chunk(data.cwid, usual)); cwinfo.add(Chunk.NEWLINE); cwinfo.add(new Chunk("Coursework Tile: ", stitle)); cwinfo.add(new Chunk(data.cwt, usual)); cwinfo.add(Chunk.NEWLINE); cwinfo.add(new Chunk("Coursework Deadline is on ", stitle)); cwinfo.add(new Chunk(data.cwed, usual)); cwinfo.setLeading(30); cs.add(cwinfo); cs.add(new Paragraph("Rule: \n" + " I am the Boss", usual)); //Phrase phrase1= new Phrase("This is sentence 1. ", title); //ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase1, 30, 600, 0); //cs.add(new Paragraph("Name: " + data.fn + " " + data.ln, title)); //cs.add(new Chunk("SID: " + data.sid)); //Close the PDF file cs.close(); } catch (DocumentException | FileNotFoundException ex) { System.out.println(ex); } }
From source file:edu.ksu.cs.a4vm.bse.reporter.Reporter.java
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(null); if (option == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile() != null) { File3 = chooser.getSelectedFile().getAbsolutePath(); }// w w w. ja v a2 s. c o m try { br1 = new BufferedReader(new FileReader(f)); BufferedReader b1 = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException ex) { } String line = ""; bull1 = new String[number_of_rows - 1][]; int k = 0; BufferedReader br3 = null; try { br3 = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException ex) { } try { while ((line = br3.readLine()) != null) { // use comma as separator String Bull[] = line.split(","); if (k != 0) { System.out.println(Bull.length); bull1[k - 1] = new String[Bull.length]; for (int j = 0; j < Bull.length; j++) { bull1[k - 1][j] = 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(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 6); Font bfBold20 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); Font bfBold25 = new Font(Font.FontFamily.TIMES_ROMAN, 15, 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(bfBold25); 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][62] + " " + bull1[1][63] + "\n\n\tRanch: " + bull1[1][64] + "\n\n\tAddress: " + bull1[1][55] + "\n\n\tCity: " + bull1[1][57] + "\n\n\tState: " + bull1[1][60] + "\tZip: " + bull1[1][61] + "\n\n\tPhone: " + bull1[1][59] + "\n\n"; table1.addCell(getCell(temp1, PdfPCell.ALIGN_LEFT)); doc.add(table1); if (dlm3.size() == 1) { String str; str = dlm3.get(0).toString(); String[] parts = str.split(":"); String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; String[][] temp = new String[25][6]; temp[0][0] = "Tag"; temp[0][1] = bull1[row][7]; temp[0][2] = "Comments"; temp[0][3] = ""; temp[0][4] = "Total Count"; temp[0][5] = ""; temp[1][0] = "Tatoo"; temp[1][1] = bull1[row][8]; temp[1][2] = "All Normal"; temp[1][3] = "Yes"; temp[2][0] = "RFID"; temp[2][1] = bull1[row][6]; temp[2][2] = "Eyes"; temp[2][3] = bull1[row][10]; temp[3][0] = "Lot#"; temp[3][1] = bull1[row][5]; temp[3][2] = "Feet"; temp[3][3] = bull1[row][12]; temp[4][0] = "Brand"; temp[4][1] = bull1[row][2]; temp[4][2] = "Legs"; temp[4][3] = bull1[row][14]; temp[5][0] = "Date of Birth"; temp[5][1] = bull1[row][4]; temp[5][2] = "Testicals"; temp[5][3] = bull1[row][16]; temp[6][0] = "Age"; temp[6][1] = bull1[row][0]; temp[6][2] = "Accessory Sex Glands"; temp[6][3] = bull1[row][18]; temp[7][0] = "Breed"; temp[7][1] = bull1[row][3]; temp[7][2] = "Inguinal"; temp[7][3] = bull1[row][20]; temp[8][0] = "Other"; temp[8][1] = bull1[row][9]; temp[8][2] = "Scrotal"; temp[8][3] = bull1[row][22]; temp[9][0] = "Clinic Info"; temp[9][1] = "xx"; temp[9][2] = "Epidydimides"; temp[9][3] = bull1[row][24]; temp[10][4] = "Measurements"; temp[10][5] = "xx"; temp[10][0] = "Clinic Name"; temp[10][1] = bull1[row][73]; temp[10][2] = "Penis"; temp[10][3] = bull1[row][26]; temp[11][4] = "Scrotal Cirumference"; temp[11][5] = bull1[row][54]; temp[11][0] = "Veterinarian Name"; temp[11][1] = bull1[row][74] + " " + bull1[row][74]; temp[11][2] = "Prepuce"; temp[11][3] = bull1[row][28]; temp[12][4] = "Body Condition"; temp[12][5] = bull1[row][47]; temp[12][0] = "Address"; temp[12][1] = bull1[row][66] + " " + bull1[row][67]; temp[12][2] = "Scrotum"; temp[12][3] = bull1[row][30]; temp[13][4] = "Pelvic X Measure"; temp[13][5] = bull1[row][52]; temp[13][0] = "City"; temp[13][1] = bull1[row][68]; temp[13][2] = "Sex Drive"; temp[13][3] = "xx"; temp[14][4] = "Pelvic Y Measure"; temp[14][5] = bull1[row][53]; temp[14][0] = "State"; temp[14][1] = bull1[row][71]; temp[14][2] = "Breeding seasons used"; temp[14][3] = bull1[row][40]; temp[15][4] = "Hip Hight"; temp[15][5] = bull1[row][50]; temp[15][0] = "Zip Code"; temp[15][1] = bull1[row][72]; temp[15][2] = "Performance last season"; temp[15][3] = bull1[row][38]; temp[16][4] = "Frame Score"; temp[16][5] = bull1[row][49]; temp[16][0] = "Email"; temp[16][1] = bull1[row][69]; temp[16][2] = "Single or Multi sire"; temp[16][3] = bull1[row][41]; temp[17][4] = "Other"; temp[17][5] = bull1[row][48]; temp[17][0] = "Phone"; temp[17][1] = bull1[row][70]; temp[17][2] = "Other"; temp[17][3] = bull1[row][39]; temp[18][4] = "Motility"; temp[18][5] = "xx"; temp[18][0] = "Classification"; temp[18][1] = bull1[row][35]; temp[18][2] = "Comments"; temp[18][3] = bull1[row][37]; temp[19][4] = "Individual Motility"; temp[19][5] = bull1[row][45]; temp[19][0] = "Comments"; temp[19][1] = bull1[row][36]; temp[19][2] = ""; temp[19][3] = ""; temp[20][4] = "Motility %"; temp[20][5] = bull1[row][46]; temp[20][0] = ""; temp[20][1] = ""; temp[20][2] = ""; temp[20][3] = ""; temp[21][4] = "Gross Motility"; temp[21][5] = bull1[row][44]; temp[21][0] = ""; temp[21][1] = ""; temp[21][2] = ""; temp[21][3] = ""; for (int i = 9; i <= 29; i += 2) { if (bull1[row][i].equals("FALSE")) { temp[1][4] = "No"; break; } } int i; int total = 0; for (i = 77; i < header.length && i < bull1[row].length; i++) { temp[i - 76][4] = header[i].split("_")[1]; temp[i - 76][5] = bull1[row][i]; total += Integer.parseInt(bull1[row][i]); } temp[0][5] = Integer.toString(total); for (int j = i; j <= 85; j++) { temp[j - 76][4] = ""; temp[j - 76][5] = ""; } PdfPTable table = new PdfPTable(6); PdfPCell cell11, cell12, cell13; cell11 = new PdfPCell( new Phrase("Bull Info", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell11.setColspan(2); cell11.setHorizontalAlignment(Element.ALIGN_CENTER); cell11.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell11); cell12 = new PdfPCell( new Phrase("Physical Exam", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell12.setColspan(2); cell12.setHorizontalAlignment(Element.ALIGN_CENTER); cell12.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell12); cell13 = new PdfPCell( new Phrase("Morphology", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell13.setColspan(2); cell13.setHorizontalAlignment(Element.ALIGN_CENTER); cell13.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell13); for (int l = 0; l <= 21; l++) { for (int j = 0; j < 6; j++) { // System.out.println(l+" "+j); if (!temp[l][j].equals("xx") && temp[l][j] != null) { cell = new PdfPCell( new Phrase(temp[l][j], FontFactory.getFont(FontFactory.TIMES_ROMAN, 10))); cell.setBorder(PdfPCell.NO_BORDER); if ((l == 9 && j == 0) || (l == 13 && j == 2) || (l == 10 && j == 4) || (l == 18 && j == 4)) { cell = new PdfPCell(new Phrase(temp[l][j], FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setColspan(2); } table.addCell(cell); } } } table.setWidthPercentage(90f); Reporter re; re = new Reporter(); doc.add(table); if (jCheckBox2.isSelected() || jCheckBox1.isSelected()) doc.newPage(); } else { //specify column widths int temp = dlm2.size(); float[] columnWidths = new float[temp]; for (int x = 0; x < columnWidths.length; x++) { columnWidths[x] = 2f; } //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(); re.insertCell(table, "Bull Info", Element.ALIGN_CENTER, 1, bfBold12); for (int i = 0; i < dlm2.size(); i++) { String[] parts = dlm2.get(i).toString().split(": "); String part2 = parts[1]; re.insertCell(table, newhead[Integer.parseInt(part2)], 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 = 0; x < dlm3.size(); x++) { String str = dlm3.get(x).toString(); //System.out.println(str); String[] parts = str.split(":"); String part2 = parts[1]; // System.out.println(part2); int row = Integer.parseInt(part2) - 1; re.insertCell(table, Bulls[row], Element.ALIGN_CENTER, 1, bf12); for (int i = 0; i < dlm2.getSize(); i++) { for (int j = 0; j < header.length && j < bull1[row].length; j++) { String str1 = dlm2.get(i).toString(); String[] p1 = str1.split(": "); String p2 = p1[0]; if (p2.equals(header[j])) { re.insertCell(table, bull1[row][j], Element.ALIGN_CENTER, 1, bf12); } } } // re.insertCell(table, bull1[x][7] , Element.ALIGN_CENTER, 1, bf12); } doc.add(table); } if (jCheckBox2.isSelected()) { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); for (int i = 0; i < dlm3.size(); i++) { String str = dlm3.get(i).toString(); System.out.println(str); String[] parts = str.split(":"); String part1 = parts[0]; String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; float total = (float) 0.0; for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (bull1[row][j].equals("")) { continue; } else { total += Integer.parseInt(bull1[row][j]); } } System.out.println(total); for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (!bull1[row][j].equals("")) { String[] Parts = header[j].split("_"); String Part2 = Parts[1]; dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, Part2, part1); } else { dataSet.setValue(0, "Percent", header[j]); } } } JFreeChart chart = ChartFactory.createBarChart("Multi Bull Morphology Chart ", "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, true, true, false); if (dlm3.size() > 12) { doc.newPage(); } PdfContentByte contentByte = docWriter.getDirectContent(); PdfTemplate template = contentByte.createTemplate(325, 250); PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250); Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250); chart.draw(graphics2d, rectangle2d); graphics2d.dispose(); contentByte.addTemplate(template, 0, 0); } if (jCheckBox1.isSelected()) { for (int i = 0; i < dlm3.size(); i++) { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); String str = dlm3.get(i).toString(); System.out.println(str); String[] parts = str.split(":"); String part1 = parts[0]; String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; float total = (float) 0.0; for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (bull1[row][j].equals("")) { continue; } else { total += Integer.parseInt(bull1[row][j]); } } System.out.println(total); for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (!bull1[row][j].equals("")) { String[] Parts = header[j].split("_"); String Part2 = Parts[1]; dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, "Percent", Part2); } else { dataSet.setValue(0, "Percent", header[j]); } } JFreeChart chart = ChartFactory.createBarChart("Single Bull Morphology Chart " + part1, "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false); if ((dlm3.size() > 12 && i == 0) || jCheckBox2.isSelected()) { doc.newPage(); } PdfContentByte contentByte = docWriter.getDirectContent(); PdfTemplate template = contentByte.createTemplate(325, 250); PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250); Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250); chart.draw(graphics2d, rectangle2d); graphics2d.dispose(); contentByte.addTemplate(template, 0, 0); doc.newPage(); } } } catch (DocumentException dex) { dex.printStackTrace(); } catch (FileNotFoundException ex) { Logger.getLogger(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ReporterArchive.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: }
From source file:edu.ksu.cs.a4vm.bse.reporter.Reporter.java
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: // build a controller SwingController controller = new SwingController(); // Build a SwingViewFactory configured with the controller SwingViewBuilder factory = new SwingViewBuilder(controller); // Use the factory to build a JPanel that is pre-configured //with a complete, active Viewer UI. JPanel viewerComponentPanel = factory.buildViewerPanel(); // add copy keyboard command ComponentKeyBinding.install(controller, viewerComponentPanel); // add interactive mouse link annotation support via callback controller.getDocumentViewController().setAnnotationCallback( new org.icepdf.ri.common.MyAnnotationCallback(controller.getDocumentViewController())); // Create a JFrame to display the panel in JFrame window = new JFrame("Using the Viewer Component"); window.getContentPane().add(viewerComponentPanel); window.pack();/*from w w w. j av a2s . co m*/ window.setVisible(true); String Path; JFileChooser chooser = new JFileChooser(); FileSystemView view = chooser.getFileSystemView(); Path = view.getDefaultDirectory() + "/reporter.pdf"; try { br1 = new BufferedReader(new FileReader(f)); BufferedReader b1 = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException ex) { } String line = ""; bull1 = new String[number_of_rows - 1][]; int k = 0; BufferedReader br3 = null; try { br3 = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException ex) { } try { while ((line = br3.readLine()) != null) { // use comma as separator String Bull[] = line.split(","); if (k != 0) { System.out.println(Bull.length); bull1[k - 1] = new String[Bull.length]; for (int j = 0; j < Bull.length; j++) { bull1[k - 1][j] = 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(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 6); Font bfBold20 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); //file path docWriter = PdfWriter.getInstance(doc, new FileOutputStream(Path)); //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][62] + " " + bull1[1][63] + "\n\n\tRanch: " + bull1[1][64] + "\n\n\tAddress: " + bull1[1][55] + "\n\n\tCity: " + bull1[1][57] + "\n\n\tState: " + bull1[1][60] + "\tZip: " + bull1[1][61] + "\n\n\tPhone: " + bull1[1][59] + "\n\n"; table1.addCell(getCell(temp1, PdfPCell.ALIGN_LEFT)); doc.add(table1); if (dlm3.size() == 1) { String str; str = dlm3.get(0).toString(); String[] parts = str.split(":"); String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; String[][] temp = new String[25][6]; temp[0][0] = "Tag"; temp[0][1] = bull1[row][7]; temp[0][2] = "Comments"; temp[0][3] = ""; temp[0][4] = "Total Count"; temp[0][5] = ""; temp[1][0] = "Tatoo"; temp[1][1] = bull1[row][8]; temp[1][2] = "All Normal"; temp[1][3] = "Yes"; temp[2][0] = "RFID"; temp[2][1] = bull1[row][6]; temp[2][2] = "Eyes"; temp[2][3] = bull1[row][10]; temp[3][0] = "Lot#"; temp[3][1] = bull1[row][5]; temp[3][2] = "Feet"; temp[3][3] = bull1[row][12]; temp[4][0] = "Brand"; temp[4][1] = bull1[row][2]; temp[4][2] = "Legs"; temp[4][3] = bull1[row][14]; temp[5][0] = "Date of Birth"; temp[5][1] = bull1[row][4]; temp[5][2] = "Testicals"; temp[5][3] = bull1[row][16]; temp[6][0] = "Age"; temp[6][1] = bull1[row][0]; temp[6][2] = "Accessory Sex Glands"; temp[6][3] = bull1[row][18]; temp[7][0] = "Breed"; temp[7][1] = bull1[row][3]; temp[7][2] = "Inguinal"; temp[7][3] = bull1[row][20]; temp[8][0] = "Other"; temp[8][1] = bull1[row][9]; temp[8][2] = "Scrotal"; temp[8][3] = bull1[row][22]; temp[9][0] = "Clinic Info"; temp[9][1] = "xx"; temp[9][2] = "Epidydimides"; temp[9][3] = bull1[row][24]; temp[10][4] = "Measurements"; temp[10][5] = "xx"; temp[10][0] = "Clinic Name"; temp[10][1] = bull1[row][73]; temp[10][2] = "Penis"; temp[10][3] = bull1[row][26]; temp[11][4] = "Scrotal Cirumference"; temp[11][5] = bull1[row][54]; temp[11][0] = "Veterinarian Name"; temp[11][1] = bull1[row][74] + " " + bull1[row][74]; temp[11][2] = "Prepuce"; temp[11][3] = bull1[row][28]; temp[12][4] = "Body Condition"; temp[12][5] = bull1[row][47]; temp[12][0] = "Address"; temp[12][1] = bull1[row][66] + " " + bull1[row][67]; temp[12][2] = "Scrotum"; temp[12][3] = bull1[row][30]; temp[13][4] = "Pelvic X Measure"; temp[13][5] = bull1[row][52]; temp[13][0] = "City"; temp[13][1] = bull1[row][68]; temp[13][2] = "Sex Drive"; temp[13][3] = "xx"; temp[14][4] = "Pelvic Y Measure"; temp[14][5] = bull1[row][53]; temp[14][0] = "State"; temp[14][1] = bull1[row][71]; temp[14][2] = "Breeding seasons used"; temp[14][3] = bull1[row][40]; temp[15][4] = "Hip Hight"; temp[15][5] = bull1[row][50]; temp[15][0] = "Zip Code"; temp[15][1] = bull1[row][72]; temp[15][2] = "Performance last season"; temp[15][3] = bull1[row][38]; temp[16][4] = "Frame Score"; temp[16][5] = bull1[row][49]; temp[16][0] = "Email"; temp[16][1] = bull1[row][69]; temp[16][2] = "Single or Multi sire"; temp[16][3] = bull1[row][41]; temp[17][4] = "Other"; temp[17][5] = bull1[row][48]; temp[17][0] = "Phone"; temp[17][1] = bull1[row][70]; temp[17][2] = "Other"; temp[17][3] = bull1[row][39]; temp[18][4] = "Motility"; temp[18][5] = "xx"; temp[18][0] = "Classification"; temp[18][1] = bull1[row][35]; temp[18][2] = "Comments"; temp[18][3] = bull1[row][37]; temp[19][4] = "Individual Motility"; temp[19][5] = bull1[row][45]; temp[19][0] = "Comments"; temp[19][1] = bull1[row][36]; temp[19][2] = ""; temp[19][3] = ""; temp[20][4] = "Motility %"; temp[20][5] = bull1[row][46]; temp[20][0] = ""; temp[20][1] = ""; temp[20][2] = ""; temp[20][3] = ""; temp[21][4] = "Gross Motility"; temp[21][5] = bull1[row][44]; temp[21][0] = ""; temp[21][1] = ""; temp[21][2] = ""; temp[21][3] = ""; for (int i = 9; i <= 29; i += 2) { if (bull1[row][i].equals("FALSE")) { temp[1][4] = "No"; break; } } int i; int total = 0; for (i = 77; i < header.length && i < bull1[row].length; i++) { temp[i - 76][4] = header[i].split("_")[1]; temp[i - 76][5] = bull1[row][i]; total += Integer.parseInt(bull1[row][i]); } temp[0][5] = Integer.toString(total); for (int j = i; j <= 85; j++) { temp[j - 76][4] = ""; temp[j - 76][5] = ""; } PdfPTable table = new PdfPTable(6); PdfPCell cell11, cell12, cell13; cell11 = new PdfPCell(new Phrase("Bull Info", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell11.setColspan(2); cell11.setHorizontalAlignment(Element.ALIGN_CENTER); cell11.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell11); cell12 = new PdfPCell( new Phrase("Physical Exam", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell12.setColspan(2); cell12.setHorizontalAlignment(Element.ALIGN_CENTER); cell12.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell12); cell13 = new PdfPCell(new Phrase("Morphology", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell13.setColspan(2); cell13.setHorizontalAlignment(Element.ALIGN_CENTER); cell13.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell13); for (int l = 0; l <= 21; l++) { for (int j = 0; j < 6; j++) { // System.out.println(l+" "+j); if (!temp[l][j].equals("xx") && temp[l][j] != null) { cell = new PdfPCell( new Phrase(temp[l][j], FontFactory.getFont(FontFactory.TIMES_ROMAN, 10))); cell.setBorder(PdfPCell.NO_BORDER); if ((l == 9 && j == 0) || (l == 13 && j == 2) || (l == 10 && j == 4) || (l == 18 && j == 4)) { cell = new PdfPCell( new Phrase(temp[l][j], FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setColspan(2); } table.addCell(cell); } } } table.setWidthPercentage(90f); Reporter re; re = new Reporter(); doc.add(table); if (jCheckBox2.isSelected() || jCheckBox1.isSelected()) doc.newPage(); } else { //specify column widths int temp = dlm2.size(); float[] columnWidths = new float[temp + 1]; for (int x = 0; x < columnWidths.length; x++) { columnWidths[x] = 2f; } //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(); re.insertCell(table, "Bull Info", Element.ALIGN_CENTER, 1, bfBold12); for (int i = 0; i < dlm2.size(); i++) { String[] parts = dlm2.get(i).toString().split(": "); String part2 = parts[1]; re.insertCell(table, newhead[Integer.parseInt(part2)], 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 = 0; x < dlm3.size(); x++) { String str = dlm3.get(x).toString(); //System.out.println(str); String[] parts = str.split(":"); String part2 = parts[1]; // System.out.println(part2); int row = Integer.parseInt(part2) - 1; re.insertCell(table, Bulls[row], Element.ALIGN_CENTER, 1, bf12); for (int i = 0; i < dlm2.getSize(); i++) { for (int j = 0; j < header.length && j < bull1[row].length; j++) { String str1 = dlm2.get(i).toString(); String[] p1 = str1.split(": "); String p2 = p1[0]; if (p2.equals(header[j])) { re.insertCell(table, bull1[row][j], Element.ALIGN_CENTER, 1, bf12); } } } // re.insertCell(table, bull1[x][7] , Element.ALIGN_CENTER, 1, bf12); } doc.add(table); } if (jCheckBox2.isSelected()) { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); for (int i = 0; i < dlm3.size(); i++) { String str = dlm3.get(i).toString(); System.out.println(str); String[] parts = str.split(":"); String part1 = parts[0]; String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; float total = (float) 0.0; for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (bull1[row][j].equals("")) { continue; } else { total += Integer.parseInt(bull1[row][j]); } } System.out.println(total); for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (!bull1[row][j].equals("")) { String[] Parts = header[j].split("_"); String Part2 = Parts[1]; dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, Part2, part1); } else { dataSet.setValue(0, "Percent", header[j]); } } } JFreeChart chart = ChartFactory.createBarChart("Multi Bull Morphology Chart ", "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, true, true, false); if (dlm3.size() > 12) { doc.newPage(); } PdfContentByte contentByte = docWriter.getDirectContent(); PdfTemplate template = contentByte.createTemplate(325, 250); PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250); Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250); chart.draw(graphics2d, rectangle2d); graphics2d.dispose(); contentByte.addTemplate(template, 0, 0); } if (jCheckBox1.isSelected()) { for (int i = 0; i < dlm3.size(); i++) { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); String str = dlm3.get(i).toString(); System.out.println(str); String[] parts = str.split(":"); String part1 = parts[0]; String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; float total = (float) 0.0; for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (bull1[row][j].equals("")) { continue; } else { total += Integer.parseInt(bull1[row][j]); } } System.out.println(total); for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (!bull1[row][j].equals("")) { String[] Parts = header[j].split("_"); String Part2 = Parts[1]; dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, "Percent", Part2); } else { dataSet.setValue(0, "Percent", header[j]); } } JFreeChart chart = ChartFactory.createBarChart("Single Bull Morphology Chart " + part1, "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false); if ((dlm3.size() > 12 && i == 0) || jCheckBox2.isSelected()) { doc.newPage(); } PdfContentByte contentByte = docWriter.getDirectContent(); PdfTemplate template = contentByte.createTemplate(325, 250); PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250); Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250); chart.draw(graphics2d, rectangle2d); graphics2d.dispose(); contentByte.addTemplate(template, 0, 0); doc.newPage(); } } } catch (DocumentException dex) { dex.printStackTrace(); JOptionPane.showMessageDialog(null, dex); } catch (FileNotFoundException ex) { Logger.getLogger(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(null, ex); } catch (IOException ex) { Logger.getLogger(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(null, "ex"); } finally { if (doc != null) { //close the document doc.close(); } if (docWriter != null) { //close the writer docWriter.close(); } } controller.openDocument(Path); }
From source file:edu.ksu.cs.a4vm.bse.reporter.Reporter.java
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: // build a controller SwingController controller = new SwingController(); // Build a SwingViewFactory configured with the controller SwingViewBuilder factory = new SwingViewBuilder(controller); // Use the factory to build a JPanel that is pre-configured //with a complete, active Viewer UI. JPanel viewerComponentPanel = factory.buildViewerPanel(); // add copy keyboard command ComponentKeyBinding.install(controller, viewerComponentPanel); // add interactive mouse link annotation support via callback controller.getDocumentViewController().setAnnotationCallback( new org.icepdf.ri.common.MyAnnotationCallback(controller.getDocumentViewController())); // Create a JFrame to display the panel in JFrame window = new JFrame("Using the Viewer Component"); window.getContentPane().add(viewerComponentPanel); window.pack();/* ww w.j a va2 s . com*/ window.setVisible(true); String Path; JFileChooser fr = new JFileChooser(); FileSystemView fw = fr.getFileSystemView(); // System.out.println(fw.getDefaultDirectory()); Path = fw.getDefaultDirectory() + "/reporter.pdf"; try { br1 = new BufferedReader(new FileReader(f)); BufferedReader b1 = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException ex) { } String line = ""; bull1 = new String[number_of_rows - 1][]; int k = 0; BufferedReader br3 = null; try { br3 = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException ex) { } try { while ((line = br3.readLine()) != null) { // use comma as separator String Bull[] = line.split(","); if (k != 0) { System.out.println(Bull.length); bull1[k - 1] = new String[Bull.length]; for (int j = 0; j < Bull.length; j++) { bull1[k - 1][j] = 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(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 6); Font bfBold20 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); //file path docWriter = PdfWriter.getInstance(doc, new FileOutputStream(Path)); //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][62] + " " + bull1[1][63] + "\n\n\tRanch: " + bull1[1][64] + "\n\n\tAddress: " + bull1[1][55] + "\n\n\tCity: " + bull1[1][57] + "\n\n\tState: " + bull1[1][60] + "\tZip: " + bull1[1][61] + "\n\n\tPhone: " + bull1[1][59] + "\n\n"; table1.addCell(getCell(temp1, PdfPCell.ALIGN_LEFT)); doc.add(table1); if (dlm3.size() == 1) { String str; str = dlm3.get(0).toString(); String[] parts = str.split(":"); String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; String[][] temp = new String[25][6]; temp[0][0] = "Tag"; temp[0][1] = bull1[row][7]; temp[0][2] = "Comments"; temp[0][3] = ""; temp[0][4] = "Total Count"; temp[0][5] = ""; temp[1][0] = "Tatoo"; temp[1][1] = bull1[row][8]; temp[1][2] = "All Normal"; temp[1][3] = "Yes"; temp[2][0] = "RFID"; temp[2][1] = bull1[row][6]; temp[2][2] = "Eyes"; temp[2][3] = bull1[row][10]; temp[3][0] = "Lot#"; temp[3][1] = bull1[row][5]; temp[3][2] = "Feet"; temp[3][3] = bull1[row][12]; temp[4][0] = "Brand"; temp[4][1] = bull1[row][2]; temp[4][2] = "Legs"; temp[4][3] = bull1[row][14]; temp[5][0] = "Date of Birth"; temp[5][1] = bull1[row][4]; temp[5][2] = "Testicals"; temp[5][3] = bull1[row][16]; temp[6][0] = "Age"; temp[6][1] = bull1[row][0]; temp[6][2] = "Accessory Sex Glands"; temp[6][3] = bull1[row][18]; temp[7][0] = "Breed"; temp[7][1] = bull1[row][3]; temp[7][2] = "Inguinal"; temp[7][3] = bull1[row][20]; temp[8][0] = "Other"; temp[8][1] = bull1[row][9]; temp[8][2] = "Scrotal"; temp[8][3] = bull1[row][22]; temp[9][0] = "Clinic Info"; temp[9][1] = "xx"; temp[9][2] = "Epidydimides"; temp[9][3] = bull1[row][24]; temp[10][4] = "Measurements"; temp[10][5] = "xx"; temp[10][0] = "Clinic Name"; temp[10][1] = bull1[row][73]; temp[10][2] = "Penis"; temp[10][3] = bull1[row][26]; temp[11][4] = "Scrotal Cirumference"; temp[11][5] = bull1[row][54]; temp[11][0] = "Veterinarian Name"; temp[11][1] = bull1[row][74] + " " + bull1[row][75]; temp[11][2] = "Prepuce"; temp[11][3] = bull1[row][28]; temp[12][4] = "Body Condition"; temp[12][5] = bull1[row][47]; temp[12][0] = "Address"; temp[12][1] = bull1[row][66] + " " + bull1[row][67]; temp[12][2] = "Scrotum"; temp[12][3] = bull1[row][30]; temp[13][4] = "Pelvic X Measure"; temp[13][5] = bull1[row][52]; temp[13][0] = "City"; temp[13][1] = bull1[row][68]; temp[13][2] = "Sex Drive"; temp[13][3] = "xx"; temp[14][4] = "Pelvic Y Measure"; temp[14][5] = bull1[row][53]; temp[14][0] = "State"; temp[14][1] = bull1[row][71]; temp[14][2] = "Breeding seasons used"; temp[14][3] = bull1[row][40]; temp[15][4] = "Hip Hight"; temp[15][5] = bull1[row][50]; temp[15][0] = "Zip Code"; temp[15][1] = bull1[row][72]; temp[15][2] = "Performance last season"; temp[15][3] = bull1[row][38]; temp[16][4] = "Frame Score"; temp[16][5] = bull1[row][49]; temp[16][0] = "Email"; temp[16][1] = bull1[row][69]; temp[16][2] = "Single or Multi sire"; temp[16][3] = bull1[row][41]; temp[17][4] = "Other"; temp[17][5] = bull1[row][48]; temp[17][0] = "Phone"; temp[17][1] = bull1[row][70]; temp[17][2] = "Other"; temp[17][3] = bull1[row][39]; temp[18][4] = "Motility"; temp[18][5] = "xx"; temp[18][0] = "Classification"; temp[18][1] = bull1[row][35]; temp[18][2] = "Comments"; temp[18][3] = bull1[row][37]; temp[19][4] = "Individual Motility"; temp[19][5] = bull1[row][45]; temp[19][0] = "Comments"; temp[19][1] = bull1[row][36]; temp[19][2] = ""; temp[19][3] = ""; temp[20][4] = "Motility %"; temp[20][5] = bull1[row][46]; temp[20][0] = ""; temp[20][1] = ""; temp[20][2] = ""; temp[20][3] = ""; temp[21][4] = "Gross Motility"; temp[21][5] = bull1[row][44]; temp[21][0] = ""; temp[21][1] = ""; temp[21][2] = ""; temp[21][3] = ""; for (int i = 9; i <= 29; i += 2) { if (bull1[row][i].equals("FALSE")) { temp[1][4] = "No"; break; } } int i; int total = 0; for (i = 77; i < header.length && i < bull1[row].length; i++) { temp[i - 76][4] = header[i].split("_")[1]; temp[i - 76][5] = bull1[row][i]; total += Integer.parseInt(bull1[row][i]); } temp[0][5] = Integer.toString(total); for (int j = i; j <= 85; j++) { temp[j - 76][4] = ""; temp[j - 76][5] = ""; } PdfPTable table = new PdfPTable(6); PdfPCell cell11, cell12, cell13; cell11 = new PdfPCell(new Phrase("Bull Info", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell11.setColspan(2); cell11.setHorizontalAlignment(Element.ALIGN_CENTER); cell11.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell11); cell12 = new PdfPCell( new Phrase("Physical Exam", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell12.setColspan(2); cell12.setHorizontalAlignment(Element.ALIGN_CENTER); cell12.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell12); cell13 = new PdfPCell(new Phrase("Morphology", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell13.setColspan(2); cell13.setHorizontalAlignment(Element.ALIGN_CENTER); cell13.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell13); for (int l = 0; l <= 21; l++) { for (int j = 0; j < 6; j++) { // System.out.println(l+" "+j); if (!temp[l][j].equals("xx") && temp[l][j] != null) { cell = new PdfPCell( new Phrase(temp[l][j], FontFactory.getFont(FontFactory.TIMES_ROMAN, 10))); cell.setBorder(PdfPCell.NO_BORDER); if ((l == 9 && j == 0) || (l == 13 && j == 2) || (l == 10 && j == 4) || (l == 18 && j == 4)) { cell = new PdfPCell( new Phrase(temp[l][j], FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setColspan(2); } table.addCell(cell); } } } table.setWidthPercentage(90f); Reporter re; re = new Reporter(); doc.add(table); if (jCheckBox2.isSelected() || jCheckBox1.isSelected()) doc.newPage(); } else { //specify column widths int temp = dlm2.size(); float[] columnWidths = new float[temp]; for (int x = 0; x < columnWidths.length; x++) { columnWidths[x] = 2f; } //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(); re.insertCell(table, "Bull Info", Element.ALIGN_CENTER, 1, bfBold12); for (int i = 0; i < dlm2.size(); i++) { String[] parts = dlm2.get(i).toString().split(": "); String part2 = parts[1]; re.insertCell(table, newhead[Integer.parseInt(part2)], 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 = 0; x < dlm3.size(); x++) { String str = dlm3.get(x).toString(); //System.out.println(str); String[] parts = str.split(":"); String part2 = parts[1]; // System.out.println(part2); int row = Integer.parseInt(part2) - 1; re.insertCell(table, Bulls[row], Element.ALIGN_CENTER, 1, bf12); for (int i = 0; i < dlm2.getSize(); i++) { for (int j = 0; j < header.length && j < bull1[row].length; j++) { String str1 = dlm2.get(i).toString(); String[] p1 = str1.split(": "); String p2 = p1[0]; if (p2.equals(header[j])) { re.insertCell(table, bull1[row][j], Element.ALIGN_CENTER, 1, bf12); } } } // re.insertCell(table, bull1[x][7] , Element.ALIGN_CENTER, 1, bf12); } doc.add(table); } if (jCheckBox2.isSelected()) { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); for (int i = 0; i < dlm3.size(); i++) { String str = dlm3.get(i).toString(); System.out.println(str); String[] parts = str.split(":"); String part1 = parts[0]; String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; float total = (float) 0.0; for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (bull1[row][j].equals("")) { continue; } else { total += Integer.parseInt(bull1[row][j]); } } System.out.println(total); for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (!bull1[row][j].equals("")) { String[] Parts = header[j].split("_"); String Part2 = Parts[1]; dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, Part2, part1); } else { dataSet.setValue(0, "Percent", header[j]); } } } JFreeChart chart = ChartFactory.createBarChart("Multi Bull Morphology Chart ", "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, true, true, false); if (dlm3.size() > 12) { doc.newPage(); } PdfContentByte contentByte = docWriter.getDirectContent(); PdfTemplate template = contentByte.createTemplate(325, 250); PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250); Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250); chart.draw(graphics2d, rectangle2d); graphics2d.dispose(); contentByte.addTemplate(template, 0, 0); } if (jCheckBox1.isSelected()) { for (int i = 0; i < dlm3.size(); i++) { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); String str = dlm3.get(i).toString(); System.out.println(str); String[] parts = str.split(":"); String part1 = parts[0]; String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; float total = (float) 0.0; for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (bull1[row][j].equals("")) { continue; } else { total += Integer.parseInt(bull1[row][j]); } } System.out.println(total); for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (!bull1[row][j].equals("")) { String[] Parts = header[j].split("_"); String Part2 = Parts[1]; dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, "Percent", Part2); } else { dataSet.setValue(0, "Percent", header[j]); } } JFreeChart chart = ChartFactory.createBarChart("Single Bull Morphology Chart " + part1, "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false); if ((dlm3.size() > 12 && i == 0) || jCheckBox2.isSelected()) { doc.newPage(); } PdfContentByte contentByte = docWriter.getDirectContent(); PdfTemplate template = contentByte.createTemplate(325, 250); PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250); Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250); chart.draw(graphics2d, rectangle2d); graphics2d.dispose(); contentByte.addTemplate(template, 0, 0); doc.newPage(); } } } catch (DocumentException dex) { dex.printStackTrace(); } catch (FileNotFoundException ex) { Logger.getLogger(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex); } finally { if (doc != null) { //close the document doc.close(); } if (docWriter != null) { //close the writer docWriter.close(); } } controller.openDocument(Path); }
From source file:edu.ksu.cs.a4vm.bse.reporter.ReporterArchive.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(); }/*ww w.j av a 2 s .c o m*/ 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(ReporterArchive.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); ReporterArchive re; re = new ReporterArchive(); //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(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ReporterArchive.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:edu.uc.modulocontable.general.GenerarKardexPDF.java
private void totalDetalleDocumento() throws DocumentException { PdfPTable tablePanelInicial = new PdfPTable(11); tablePanelInicial.setWidthPercentage(100); tablePanelInicial.getDefaultCell().setBorder(0); titulo4.setTexto(""); tablePanelInicial.addCell(titulo4.getElemento()); titulo4.setTexto(""); tablePanelInicial.addCell(titulo4.getElemento()); titulo4.setTexto(""); tablePanelInicial.addCell(titulo4.getElemento()); PdfPCell cell = new PdfPCell(new Paragraph("Total", FontFactory.getFont("arial", 9, Font.BOLD))); cell.setHorizontalAlignment(1);/*from w w w . j a v a 2 s . c o m*/ cell.setBorder(0); tablePanelInicial.addCell(cell); cell = new PdfPCell( new Paragraph(String.valueOf(getCantidadEntrada()), FontFactory.getFont("arial", 8, Font.BOLD))); cell.setHorizontalAlignment(1); cell.setBorder(0); tablePanelInicial.addCell(cell); titulo4.setTexto(""); tablePanelInicial.addCell(titulo4.getElemento()); cell = new PdfPCell( new Paragraph(String.valueOf(getCantidadSalida()), FontFactory.getFont("arial", 8, Font.BOLD))); cell.setHorizontalAlignment(2); cell.setBorder(0); tablePanelInicial.addCell(cell); titulo4.setTexto(""); tablePanelInicial.addCell(titulo4.getElemento()); titulo4.setTexto(""); tablePanelInicial.addCell(titulo4.getElemento()); titulo4.setTexto(String.valueOf(getSaldoCantidad())); tablePanelInicial.addCell(titulo4.getElemento()); cell = new PdfPCell( new Paragraph("$ " + String.valueOf(getSaldoTotal()), FontFactory.getFont("arial", 8, Font.BOLD))); cell.setHorizontalAlignment(1); cell.setBorder(0); tablePanelInicial.addCell(cell); documento.add(tablePanelInicial); documento.add(espacioBlanco.getElemento()); documento.add(lineaNormal.getLinea()); }