List of usage examples for com.itextpdf.text Font Font
public Font(final FontFamily family)
From source file:KTCNPM.ExportFile.java
public void exportFile(ArrayList<String> list, ArrayList<String> listTAW, ArrayList<String> listTBF, ArrayList<String> listTCF, ArrayList<String> listEF, ArrayList<String> listG) throws IOException { Document document = new Document(); try {//from w w w . j a va 2 s. c o m String fileSRC = "E:\\KTCNPM.pdf"; File file = new File(fileSRC); if (file.exists()) { file.delete(); } else { file.createNewFile(); } PdfWriter.getInstance(document, new FileOutputStream(fileSRC)); document.open(); Font f1 = new Font( BaseFont.createFont("/newpackage/vuArialBold.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); Font f2 = new Font( BaseFont.createFont("/newpackage/vuArial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); f2.setSize(9); f1.setSize(13); Paragraph paragraph2 = new Paragraph("", f2); Paragraph paragraph3 = new Paragraph(); paragraph2.setIndentationLeft(80); paragraph2.setIndentationRight(80); paragraph2.setAlignment(Element.ALIGN_LEFT); paragraph2.setSpacingAfter(15); Phrase phrase2 = new Phrase("Tn phn m?m: Tnh chi ph phn m?m"); Phrase phrase3 = new Phrase(" "); paragraph3.add(phrase3); paragraph2.add(phrase2); //Phu luc 3 Phrase phrase5 = new Phrase( "Ph lc III: Bng tnh ton im cc tc nhn (actors) tng tc, trao i thng tin"); Paragraph paragraph5 = new Paragraph("", f1); paragraph5.setIndentationLeft(80); paragraph5.setIndentationRight(80); paragraph5.setAlignment(Element.ALIGN_CENTER); paragraph5.setSpacingAfter(10); paragraph5.add(phrase5); document.add(paragraph5); document.add(paragraph2); PdfPTable table3 = new PdfPTable(5); table3.setWidthPercentage(400 / 5.23f); table3.setWidths(new int[] { 1, 5, 3, 2, 3 }); for (int i = 0; i < listTAW.size(); i++) { Paragraph p = new Paragraph(listTAW.get(i), f2); PdfPCell data = new PdfPCell(p); table3.addCell(data); } document.add(table3); document.add(paragraph3); document.add(paragraph3); document.add(paragraph3); // phu luc 4 Phrase phrase41 = new Phrase( "Ph lc IV: Bng tnh ton im cc tr?ng hp s dung (use case)"); Paragraph paragraph41 = new Paragraph("", f1); paragraph41.setIndentationLeft(80); paragraph41.setIndentationRight(80); paragraph41.setAlignment(Element.ALIGN_CENTER); paragraph41.setSpacingAfter(10); paragraph41.add(phrase41); document.add(paragraph41); document.add(paragraph2); PdfPTable table4 = new PdfPTable(4); table4.setWidthPercentage(400 / 5.23f); table4.setWidths(new int[] { 1, 3, 3, 4 }); for (int i = 0; i < listTBF.size(); i++) { PdfPCell data = new PdfPCell(new Paragraph(listTBF.get(i), f2)); table4.addCell(data); } document.add(table4); document.add(paragraph3); document.add(paragraph3); document.add(paragraph3); // phu luc 5 Phrase phrase51 = new Phrase( "Ph lc V: Bng tnh ton h s phc tp k thut - cng ngh"); Paragraph paragraph51 = new Paragraph("", f1); paragraph51.setIndentationLeft(80); paragraph51.setIndentationRight(80); paragraph51.setAlignment(Element.ALIGN_CENTER); paragraph51.setSpacingAfter(10); paragraph51.add(phrase51); document.add(paragraph51); document.add(paragraph2); PdfPTable table5 = new PdfPTable(5); table5.setWidthPercentage(400 / 5.23f); table5.setWidths(new int[] { 1, 6, 2, 2, 2 }); for (int i = 0; i < listTCF.size(); i++) { PdfPCell data = new PdfPCell(new Paragraph(listTCF.get(i), f2)); table5.addCell(data); } document.add(table5); document.add(paragraph3); document.add(paragraph3); document.add(paragraph3); //phu luc 6 Phrase phrase61 = new Phrase( "Ph lc VI: Bng tnh ton h s tc ng mi tr?ng v nhm lm vic, h s phc tp v? mi tr?ng"); Paragraph paragraph61 = new Paragraph("", f1); paragraph61.setIndentationLeft(80); paragraph61.setIndentationRight(80); paragraph61.setAlignment(Element.ALIGN_CENTER); paragraph61.setSpacingAfter(10); paragraph61.add(phrase61); document.add(paragraph61); document.add(paragraph2); PdfPTable table6 = new PdfPTable(6); table6.setWidthPercentage(400 / 5.23f); table6.setWidths(new int[] { 1, 6, 2, 2, 2, 3 }); for (int i = 0; i < listEF.size(); i++) { PdfPCell data = new PdfPCell(new Paragraph(listEF.get(i), f2)); table6.addCell(data); } document.add(table6); document.add(paragraph3); document.add(paragraph3); document.add(paragraph3); //phu luc 7 Phrase phrase7 = new Phrase("Ph lc VII: Bng tnh ton gi tr phn m?m"); Paragraph paragraph7 = new Paragraph("", f1); paragraph7.setIndentationLeft(80); paragraph7.setIndentationRight(80); paragraph7.setAlignment(Element.ALIGN_CENTER); paragraph7.setSpacingAfter(10); paragraph7.add(phrase7); document.add(paragraph7); document.add(paragraph2); PdfPTable table7 = new PdfPTable(5); table7.setWidthPercentage(400 / 5.23f); table7.setWidths(new int[] { 1, 5, 5, 4, 2 }); for (int i = 0; i < listG.size(); i++) { PdfPCell data = new PdfPCell(new Paragraph(listG.get(i), f2)); table7.addCell(data); } document.add(table7); document.add(paragraph3); document.add(paragraph3); document.add(paragraph3); // phu luc 8 Paragraph paragraph1 = new Paragraph("", f1); paragraph1.setIndentationLeft(80); paragraph1.setIndentationRight(80); paragraph1.setAlignment(Element.ALIGN_CENTER); paragraph1.setSpacingAfter(10); Phrase phrase1 = new Phrase("Ph lc VIII: Bng tng hp chi ph phn m?m"); paragraph1.add(phrase1); document.add(paragraph1); document.add(paragraph2); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(400 / 5.23f); table.setWidths(new int[] { 1, 5, 3, 4, 2 }); for (int i = 0; i < list.size(); i++) { PdfPCell data = new PdfPCell(new Paragraph(list.get(i), f2)); table.addCell(data); } document.add(table); document.close(); } catch (DocumentException | FileNotFoundException e) { } }
From source file:Login.ventas.fproyectos.java
/** * Creates new form cliente//from w w w . ja v a2 s . c o m * @param user */ public fproyectos(Login user) { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); @SuppressWarnings("MismatchedReadAndWriteOfArray") String[] fecha = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }; initComponents(); Calendar rightNow = Calendar.getInstance(); int ccyy = rightNow.get(Calendar.YEAR); int month = rightNow.get(Calendar.MONTH); setSize(d.width, d.height - 95); this.usuario = user; add(f); f.setLocation(jPanel1.getX(), jPanel1.getY()); add(f3); f3.setLocation(jPanel1.getX(), jPanel1.getY()); add(f4); f4.setLocation(jPanel1.getX(), jPanel1.getY()); add(f5); f5.setLocation(jPanel1.getX(), jPanel1.getY()); add(f2); f2.setLocation(jPanel1.getX(), jPanel1.getY()); f2.getjButton1().addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { ServiceHb helper = new ServiceHb(); helper.iniciarTransaccion(); Fcomisiones fc = helper.getFcomisiones(idcliente, idinstalacion); if (helper.getFcomisiones(idcliente, idinstalacion) == null) { fc = new Fcomisiones(); Calendar d = Calendar.getInstance(); fc.setFecha(new java.sql.Date(d.getTime().getTime())); fc.setClientes( (Clientes) helper.obtenerObjeto(Clientes.class, Integer.parseInt(idcliente))); fc.setInstalacion((Instalacion) helper.obtenerObjeto(Instalacion.class, Integer.parseInt(idinstalacion))); fc.setRentabilidad(f2.getjLabel20().getText()); fc.setValor1(f2.getjLabel11().getText().substring(2, f2.getjLabel11().getText().length())); fc.setValor2(f2.getjLabel2().getText().substring(3, f2.getjLabel2().getText().length())); fc.setDiferido(f2.getjLabel4().getText()); fc.setDias(numeroinstala); helper.crearObjeto(fc); helper.confirmarTransaccion(); helper.cerrarSesion(); JOptionPane.showMessageDialog(null, "Comision prepara con fecha " + Funcion.DateFormatSql(d.getTime())); } else { Calendar d = Calendar.getInstance(); fc.setFecha(new java.sql.Date(d.getTime().getTime())); fc.setRentabilidad(f2.getjLabel20().getText()); fc.setValor1(f2.getjLabel11().getText().substring(2, f2.getjLabel11().getText().length())); fc.setValor2(f2.getjLabel2().getText().substring(3, f2.getjLabel2().getText().length())); fc.setDiferido(f2.getjLabel4().getText()); fc.setDias(numeroinstala); helper.actualizarObjeto(fc); helper.confirmarTransaccion(); helper.cerrarSesion(); JOptionPane.showMessageDialog(null, "Actualizado / Comision prepara con fecha " + Funcion.DateFormatSql(d.getTime())); } } catch (Exception io) { System.out.println(io); } } }); f2.getjButton2().addMouseListener(new java.awt.event.MouseAdapter() { @Override @SuppressWarnings("UseSpecificCatch") public void mouseClicked(MouseEvent e) { float ancho = 0; try { Document documento = new Document(PageSize.A4, 0, 0, 0, 0); ancho = documento.getPageSize().getWidth() - 100; FileOutputStream ficheroPdf; PdfWriter writer = null; PdfWriter writer2 = null; String direccion = ""; Calendar now2 = Calendar.getInstance(); try { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); //Mostrar la ventana para abrir archivo y recoger la respuesta //En el parmetro del showOpenDialog se indica la ventana // al que estar asociado. Con el valor this se asocia a la // ventana que la abre. int respuesta = chooser.showOpenDialog(null); String cadena = ""; if (respuesta == JFileChooser.APPROVE_OPTION) { direccion = chooser.getSelectedFile().getAbsolutePath(); } Calendar d = Calendar.getInstance(); ficheroPdf = new FileOutputStream(direccion + "/" + idcliente + idinstalacion + ".pdf"); writer = PdfWriter.getInstance(documento, ficheroPdf); } catch (IOException ex) { System.out.println(ex.toString()); } ServiceHb helper = null; try { List<Productos> lt = null; helper = new ServiceHb(); helper.iniciarTransaccion(); PdfPTable tabla; PdfPCell casilla; PdfPTable salto = null; PdfPCell celda; Font fontpersonalizado = FontFactory.getFont("ARIAL", 7, Font.BOLD); Font fontpersonalizado2 = FontFactory.getFont("ARIAL", 7, Font.NORMAL); documento.open(); PdfContentByte canvas = writer.getDirectContent(); fondos(documento, canvas); //Materiales double total = 0; double total2 = 0; double total3 = 0; double total4 = 0; double total5 = 0; tabla = new PdfPTable(6); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); celda = new PdfPCell(new Paragraph("ADQUISICION DE MATERIALES")); celda.setColspan(6); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBorder(PdfPCell.NO_BORDER); tabla.addCell(celda); float pagina = documento.getPageSize().getHeight() - 140; final float max = pagina; pagina = pagina - tabla.getRow(0).calculateHeights(); if (ltart != null) { Object nuevo2[] = { "FECHA", "DETALLE", "CANT.", "PRECIO", "SUBTOTAL", "TOTAL DIARIO" }; for (Object obj : nuevo2) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(1).calculateHeights(); int tam = 0; double diario = 0; int turno = 0; for (int i = 0; i < ltart.size(); i++) { turno = 0; fact = helper.getFacturafecha(ltart.get(i).getIdfactura()); String fecha = ""; if (fact != null) { fecha = Funcion.DateFormatSql(fact.getFecha()); } if ((i + 1) == ltart.size()) { diario = diario + Double.parseDouble(ltart.get(i).getTotal()); turno = 1; } else { fact2 = helper.getFacturafecha(ltart.get(i + 1).getIdfactura()); String fecha2 = ""; if (fact2 != null) { fecha2 = Funcion.DateFormatSql(fact2.getFecha()); if (fecha.equalsIgnoreCase(fecha2)) { diario = diario + Double.parseDouble(ltart.get(i).getTotal()); } else { diario = diario + Double.parseDouble(ltart.get(i).getTotal()); turno = 1; } } } String uni = "$ " + df.format(Double.parseDouble(ltart.get(i).getUnitario())) .replace(",", "."); String tot = "$ " + df.format(Double.parseDouble(ltart.get(i).getTotal())).replace(",", "."); total = total + Double.parseDouble(ltart.get(i).getTotal()); if (turno == 0) { Object nuevo[] = { fecha, ltart.get(i).getDescripcion(), ltart.get(i).getCantidad(), uni, tot, "" }; for (Object obj : nuevo) { celda = new PdfPCell( new Paragraph((String) obj, new Font(fontpersonalizado2))); if (((String) obj).equalsIgnoreCase("")) { celda.setBorder(Rectangle.RIGHT); } celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } } else { Object nuevo[] = { fecha, ltart.get(i).getDescripcion(), ltart.get(i).getCantidad(), uni, tot, "$ " + df.format(diario).replace(",", ".") }; int va = 0; for (Object obj : nuevo) { va++; celda = new PdfPCell( new Paragraph((String) obj, new Font(fontpersonalizado2))); if (va == 5) { celda.setBorder(Rectangle.BOTTOM); } celda.setColspan(1); celda.setBorderColor(new Color(195, 195, 195)); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } diario = 0; } pagina = pagina - tabla.getRow(tam).getMaxHeights(); tam++; if (pagina < 11) { salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); documento.add(tabla); documento.newPage(); fondos(documento, canvas); tabla = new PdfPTable(6); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); pagina = max; tam = 0; } } } salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); celda = new PdfPCell(new Paragraph("Total", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell( new Paragraph("Adquisicin de Materiales", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(4); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("$ " + df.format(total).replace(",", "."), new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); documento.add(tabla); documento.newPage(); fondos(documento, canvas); /*Parte 2*/ tabla = new PdfPTable(4); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1, 1 }); celda = new PdfPCell(new Paragraph("MANO DE OBRA TECNICOS")); celda.setColspan(4); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBorder(PdfPCell.NO_BORDER); tabla.addCell(celda); pagina = documento.getPageSize().getHeight() - 140; pagina = pagina - tabla.getRow(0).calculateHeights(); if (list != null) { Object nuevo2[] = { "FECHA", "DETALLE", "CANT.", "SUBTOTAL" }; for (Object obj : nuevo2) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(1).calculateHeights(); int tam = 0; double diario = 0; int turno = 0; for (Ctepagar list1 : list) { if (list1.getDetalle().contains("ci:")) { String fecha = list1.getFecha(); String desc = list1.getDetalle(); String[] cadena = desc.split(" "); String result = ""; int contador = 0; for (String n : cadena) { if (n.contains("ci:")) { result = result + ", "; contador++; } else { result = result + n + " "; } } result = result.substring(0, result.length() - 2); String uni = "$ " + df.format(Double.parseDouble(list1.getValor())).replace(",", "."); String tot = "$ " + df.format(Double.parseDouble(list1.getValor())).replace(",", "."); total2 = total2 + Double.parseDouble(list1.getValor()); Object nuevo[] = { fecha, result, "" + contador, tot }; for (Object obj : nuevo) { celda = new PdfPCell( new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(tam).getMaxHeights(); tam++; if (pagina < 90) { salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado2))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); documento.add(tabla); documento.newPage(); fondos(documento, canvas); tabla = new PdfPTable(4); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1, 1 }); pagina = max; tam = 0; } } } } salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); celda = new PdfPCell(new Paragraph("Total", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("Mano de Obra Tcnicos", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(2); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("$ " + df.format(total2).replace(",", "."), new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); documento.add(tabla); documento.newPage(); fondos(documento, canvas); tabla = new PdfPTable(3); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1 }); celda = new PdfPCell(new Paragraph("TRANSPORTE")); celda.setColspan(3); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBorder(PdfPCell.NO_BORDER); tabla.addCell(celda); pagina = documento.getPageSize().getHeight() - 140; pagina = pagina - tabla.getRow(0).calculateHeights(); if (list != null) { Object nuevo2[] = { "FECHA", "DETALLE", "SUBTOTAL" }; for (Object obj : nuevo2) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(1).calculateHeights(); int tam = 0; for (Ctepagar list1 : list) { if (list1.getDetalle().contains("Transporte")) { String fecha = list1.getFecha(); String desc = list1.getDetalle(); String result = ""; String uni = "$ " + df.format(Double.parseDouble(list1.getValor())).replace(",", "."); String tot = "$ " + df.format(Double.parseDouble(list1.getValor())).replace(",", "."); total3 = total3 + Double.parseDouble(list1.getValor()); Object nuevo[] = { fecha, desc, tot }; for (Object obj : nuevo) { celda = new PdfPCell( new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(tam).getMaxHeights(); tam++; if (pagina < 50) { salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado2))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); documento.add(tabla); documento.newPage(); fondos(documento, canvas); tabla = new PdfPTable(3); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1 }); pagina = max; tam = 0; } } } } salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); celda = new PdfPCell(new Paragraph("Total", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("Transporte", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("$ " + df.format(total3).replace(",", "."), new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); documento.add(tabla); documento.newPage(); fondos(documento, canvas); tabla = new PdfPTable(3); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1 }); celda = new PdfPCell(new Paragraph("COMBUSTIBLE")); celda.setColspan(3); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBorder(PdfPCell.NO_BORDER); tabla.addCell(celda); pagina = documento.getPageSize().getHeight() - 140; pagina = pagina - tabla.getRow(0).calculateHeights(); if (list != null) { Object nuevo2[] = { "FECHA", "DETALLE", "SUBTOTAL" }; for (Object obj : nuevo2) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(1).calculateHeights(); int tam = 0; for (Ctepagar list1 : list) { if (list1.getDetalle().contains("Combustible")) { String fecha = list1.getFecha(); String desc = list1.getDetalle(); String result = ""; String uni = "$ " + df.format(Double.parseDouble(list1.getValor())).replace(",", "."); String tot = "$ " + df.format(Double.parseDouble(list1.getValor())).replace(",", "."); total4 = total4 + Double.parseDouble(list1.getValor()); Object nuevo[] = { fecha, desc, tot }; for (Object obj : nuevo) { celda = new PdfPCell( new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(tam).getMaxHeights(); tam++; if (pagina < 50) { salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); documento.add(tabla); documento.newPage(); fondos(documento, canvas); tabla = new PdfPTable(3); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1 }); pagina = max; tam = 0; } } } } salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); celda = new PdfPCell(new Paragraph("Total", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("Combustible", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("$ " + df.format(total4).replace(",", "."), new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); documento.add(tabla); documento.newPage(); fondos(documento, canvas); //Extras tabla = new PdfPTable(3); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1 }); celda = new PdfPCell(new Paragraph("EXTRAS")); celda.setColspan(3); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBorder(PdfPCell.NO_BORDER); tabla.addCell(celda); pagina = documento.getPageSize().getHeight() - 140; pagina = pagina - tabla.getRow(0).calculateHeights(); if (list != null) { Object nuevo2[] = { "FECHA", "DETALLE", "SUBTOTAL" }; for (Object obj : nuevo2) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(1).calculateHeights(); int tam = 0; for (Ctepagar list1 : list) { if (!list1.getDetalle().contains("Combustible") && !list1.getDetalle().contains("ci:") && !list1.getDetalle().contains("Transporte")) { String fecha = list1.getFecha(); String desc = list1.getDetalle(); String result = ""; String uni = "$ " + df.format(Double.parseDouble(list1.getValor())).replace(",", "."); String tot = "$ " + df.format(Double.parseDouble(list1.getValor())).replace(",", "."); total5 = total5 + Double.parseDouble(list1.getValor()); Object nuevo[] = { fecha, desc, tot }; for (Object obj : nuevo) { celda = new PdfPCell( new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(tam).getMaxHeights(); tam++; if (pagina < 50) { salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); documento.add(tabla); documento.newPage(); fondos(documento, canvas); tabla = new PdfPTable(3); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1 }); pagina = max; tam = 0; } } } } salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); celda = new PdfPCell(new Paragraph("Total", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("Extra", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("$ " + df.format(total5).replace(",", "."), new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); documento.add(tabla); documento.newPage(); fondos(documento, canvas); //Final Vendedor tabla = new PdfPTable(3); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1 }); celda = new PdfPCell(new Paragraph(nombrecliente)); celda.setColspan(3); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBorder(PdfPCell.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("Venta")); celda.setColspan(3); celda.setHorizontalAlignment(Element.ALIGN_LEFT); celda.setBorder(PdfPCell.NO_BORDER); tabla.addCell(celda); pagina = documento.getPageSize().getHeight() - 140; pagina = pagina - tabla.getRow(0).calculateHeights(); Object nuevo2[] = { "FECHA", "DETALLE", "TOTAL" }; for (Object obj : nuevo2) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } Object nuevo3[] = { "", nombreinstalacion, totalinstalacion }; for (Object obj : nuevo3) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } celda = new PdfPCell(new Paragraph("INVERSION", new Font(fontpersonalizado))); celda.setBorder(PdfPCell.NO_BORDER); celda.setColspan(3); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); Object nuevo4[] = { "Uso de Materiales", "", "$ " + df.format(total).replace(",", ".") }; for (Object obj : nuevo4) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorder(PdfPCell.NO_BORDER); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } Object nuevo5[] = { "Mano de obra tcnicos", "", "$ " + df.format(total2).replace(",", ".") }; for (Object obj : nuevo5) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorder(PdfPCell.NO_BORDER); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } Object nuevo6[] = { "Transporte", "", "$ " + df.format(total3).replace(",", ".") }; for (Object obj : nuevo6) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorder(PdfPCell.NO_BORDER); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } Object nuevo7[] = { "Combustible", "", "$ " + df.format(total4).replace(",", ".") }; for (Object obj : nuevo7) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorder(PdfPCell.NO_BORDER); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } Object nuevo71[] = { "Extras", "", "$ " + df.format(total5).replace(",", ".") }; for (Object obj : nuevo71) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorder(PdfPCell.NO_BORDER); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } Object nuevo8[] = { "Total Inversin", "", "$ " + df.format(total + total2 + total3 + total4).replace(",", ".") }; for (Object obj : nuevo8) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorder(PdfPCell.NO_BORDER); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } celda = new PdfPCell(new Paragraph("")); celda.setColspan(3); celda.setHorizontalAlignment(Element.ALIGN_LEFT); celda.setBorder(PdfPCell.NO_BORDER); tabla.addCell(celda); Object nuevo9[] = { "Utilidad del proyecto", "", "$ " + df.format(proyectoval - total - total2 - total3 - total4).replace(",", ".") }; for (Object obj : nuevo9) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado))); celda.setColspan(1); celda.setBorder(PdfPCell.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } Object nuevo10[] = { "Rentabilidad ", "", df.format(porcent).replace(",", ".") + " %" }; for (Object obj : nuevo10) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado))); celda.setBorder(PdfPCell.NO_BORDER); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); documento.add(tabla); /*Fin Parte 3*/ documento.close(); helper.cerrarSesion(); } catch (Exception ex) { documento.close(); } JOptionPane.showMessageDialog(null, "PDF Generado"); } catch (Exception io) { System.out.println(io); } } }); f.getjTable1().addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int row = f.getjTable1().getSelectedRow(); int col = f.getjTable1().getSelectedColumn(); if (col == 4) { f2.setVisible(true); f.setVisible(false); idcliente = f.getjTable1().getValueAt(row, 5).toString(); idinstalacion = f.getjTable1().getValueAt(row, 6).toString(); f2.getjLabel15().setText(f.getjTable1().getValueAt(row, 0).toString()); f2.getjLabel8().setText(f.getjTable1().getValueAt(row, 2).toString()); nombrecliente = f.getjTable1().getValueAt(row, 0).toString(); nombreinstalacion = f.getjTable1().getValueAt(row, 2).toString(); updateTablas up = new updateTablas(1); up.start(); } } }); f5.getjComboBox1().addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { DefaultTableModel temp2 = (DefaultTableModel) f5.getjTable2().getModel(); for (int i = temp2.getRowCount() - 1; i >= 0; i--) { temp2.removeRow(i); } f5.setComi(null); f5.setNinstalacion(""); f5.setNcliente(""); f5.setList(null); f5.setId(""); updateTablas up = new updateTablas(4); up.start(); } }); f3.getjTable1().addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int row = f3.getjTable1().getSelectedRow(); int col = f3.getjTable1().getSelectedColumn(); if (col == 6) { visible(f4); fcomisiones = f3.getjTable1().getValueAt(row, 6).toString(); try { ServiceHb helper = new ServiceHb(); helper.iniciarTransaccion(); Fcomisiones ft = (Fcomisiones) helper.obtenerObjeto(Fcomisiones.class, Integer.parseInt(fcomisiones)); numeroinstala = ft.getDias(); f4.setIdcliente("" + ft.getClientes().getId()); f4.setIdinstalacion("" + ft.getInstalacion().getId()); f4.getDiasint().setText(numeroinstala); helper.cerrarSesion(); } catch (Exception io) { } f4.getjLabel1().setText(fcomisiones); f4.getC1().setText(f3.getjTable1().getValueAt(row, 0).toString()); f4.getC2().setText(f3.getjTable1().getValueAt(row, 1).toString()); double campo1 = Double .parseDouble(f3.getjTable1().getValueAt(row, 3).toString().replace("$ ", "")); double campo2 = Double .parseDouble(f3.getjTable1().getValueAt(row, 4).toString().replace("-$ ", "")); f4.getC3().setText(f3.getjTable1().getValueAt(row, 3).toString()); f4.getC4().setText(f3.getjTable1().getValueAt(row, 4).toString()); f4.getC5().setText(f3.getjTable1().getValueAt(row, 5).toString()); f4.getC6().setText("$ " + df.format((campo1 - campo2)).replace(",", ".")); updateTablas up = new updateTablas(3); up.start(); } } }); setVisible(false); }
From source file:mhp_ph.PHprint.java
License:Open Source License
/** * Print articles as pdf//from w w w .j a v a2 s. c o m * @param ll Articles * @param f Format * @param n Filename */ public static void printPdf(LinkedList<phArt> ll, format f, String n) { Document doc = new Document(PageSize.A4, 50, 50, 50, 50); try { PdfWriter pdf = PdfWriter.getInstance(doc, new FileOutputStream(n)); doc.addSubject("Przegld Historyczny"); doc.open(); BaseFont rr = BaseFont.createFont("FreeSerif.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); BaseFont ii = BaseFont.createFont("FreeSerifItalic.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font r = new Font(rr); Font i = new Font(ii); for (phArt a : ll) { Phrase p = new Phrase(); for (articleEntry e : formatArticle(a, f)) { switch (e.getStyle()) { case normal: { p.add(new Chunk(e.getString(), r)); break; } case italic: { p.add(new Chunk(e.getString(), i)); break; } } } doc.add(new Paragraph(p)); doc.add(new Paragraph("\n")); } doc.add(new Paragraph(" \n")); } catch (Exception e) { } doc.close(); }
From source file:net.digitstar.vanadio.enums.FontType.java
License:Apache License
public final Font getFont() { return new Font(this.font); }
From source file:oop.nhom5.de3.model.IOFilePDF.java
public static boolean writePDF(String text, String fileName) { try {//from w w w.ja va 2 s. c o m // create a new document Document document = new Document(); Font font = new Font( BaseFont.createFont("C:\\Windows\\Fonts\\arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); // create lines of text String[] lines = text.split("\n"); //create Paragraph for (String line : lines) { document.add(new Paragraph(line, font)); } document.close(); return true; } catch (FileNotFoundException | DocumentException e) { e.printStackTrace(); } catch (IOException ex) { Logger.getLogger(IOFilePDF.class.getName()).log(Level.SEVERE, null, ex); } return false; }
From source file:org.qnot.passtab.PDFOutput.java
License:Open Source License
public PDFOutput(boolean withColor) { this.withColor = withColor; try {//from w w w . j a v a 2 s. c o m font = new Font(BaseFont.createFont(PDFOutput.FONT_MONOSPACE, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); fontBold = new Font( BaseFont.createFont(PDFOutput.FONT_MONOSPACE_BOLD, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); } catch (Exception e) { try { font = new Font(BaseFont.createFont()); fontBold = new Font(BaseFont.createFont()); } catch (Exception ignored) { } } font.setSize(DEFAULT_FONT_SIZE); fontBold.setSize(DEFAULT_FONT_SIZE); }