List of usage examples for com.itextpdf.text.pdf PdfPCell setBorder
public void setBorder(final int border)
From source file:model.PDFModel.java
License:Open Source License
public PdfPTable createTablePDFTable(int counter, String raportDate) { JTable resultTable = query.getProductsInTablePDFTable(raportDate, counter); PdfPTable[] tableTable = new PdfPTable[11]; PdfPCell cell, productNameCell, paymentCell, countCell, priceCell; tableTable[counter] = new PdfPTable(4); tableTable[counter].setSpacingBefore(5f); tableTable[counter].setSpacingAfter(5f); totalTablePayment[counter] = 0.00;//from w w w .j a v a 2s.c o m if (resultTable != null) { DefaultTableModel resultTableModel = (DefaultTableModel) resultTable.getModel(); if (resultTableModel.getRowCount() > 0) { cell = new PdfPCell(new Phrase("Stolik " + (counter))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(80, 255, 50)); tableTable[counter].addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); tableTable[counter].addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); tableTable[counter].addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); tableTable[counter].addCell(cell); cell = new PdfPCell(new Phrase("Produkt")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(80, 172, 8)); tableTable[counter].addCell(cell); cell = new PdfPCell(new Phrase("Ilosc")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(80, 172, 8)); tableTable[counter].addCell(cell); cell = new PdfPCell(new Phrase("Cena jednostkowa")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(80, 172, 8)); tableTable[counter].addCell(cell); cell = new PdfPCell(new Phrase("Zaplata")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(80, 172, 8)); tableTable[counter].addCell(cell); for (int i = 0; i < resultTableModel.getRowCount(); i++) { productNameCell = new PdfPCell(new Phrase(resultTableModel.getValueAt(i, 0).toString(), FontFactory.getFont(FontFactory.defaultEncoding, 10, Font.NORMAL, BaseColor.BLACK))); productNameCell.setHorizontalAlignment(Element.ALIGN_CENTER); productNameCell.setBackgroundColor(new BaseColor(80, 135, 8)); tableTable[counter].addCell(productNameCell); countCell = new PdfPCell(new Phrase(String.valueOf(resultTableModel.getValueAt(i, 2)))); countCell.setHorizontalAlignment(Element.ALIGN_CENTER); tableTable[counter].addCell(countCell); double payment = Double.parseDouble(resultTableModel.getValueAt(i, 1).toString()) * Double.parseDouble(resultTableModel.getValueAt(i, 2).toString()); totalTablePayment[counter] += payment; paymentCell = new PdfPCell(new Phrase(String.valueOf(resultTableModel.getValueAt(i, 1)))); paymentCell.setHorizontalAlignment(Element.ALIGN_CENTER); tableTable[counter].addCell(paymentCell); priceCell = new PdfPCell(new Phrase(String.valueOf(payment))); priceCell.setHorizontalAlignment(Element.ALIGN_CENTER); priceCell.setBackgroundColor(new BaseColor(255, 160, 160)); tableTable[counter].addCell(priceCell); } } } if (totalTablePayment[counter] > 0.00) { cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); tableTable[counter].addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); tableTable[counter].addCell(cell); cell = new PdfPCell(new Phrase("SUMA:", FontFactory.getFont(FontFactory.defaultEncoding, 12, Font.NORMAL, BaseColor.BLACK))); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableTable[counter].addCell(cell); cell = new PdfPCell(new Phrase(String.valueOf(totalTablePayment[counter]), FontFactory.getFont(FontFactory.defaultEncoding, 12, Font.BOLD, BaseColor.BLACK))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(255, 50, 50)); tableTable[counter].addCell(cell); } return tableTable[counter]; }
From source file:Modelo.CotizacionDAO.java
public void writePdf(OutputStream outputStream, Cotizacion x, int idcotizacion) throws Exception { DateFormat df = new SimpleDateFormat("dd/MM/YYYY"); Calendar cdos = Calendar.getInstance(); Date datediamas = new Date(); Date dateaniomas = new Date(); cdos.add(Calendar.DATE, 1);//w ww . j av a2 s . c om datediamas = cdos.getTime(); String fechadiamas = df.format(datediamas); cdos.add(Calendar.YEAR, 1); dateaniomas = cdos.getTime(); String fechavencimiento = df.format(dateaniomas); Document document = new Document(PageSize.LETTER, 50, 50, 50, 30); Font boldFontTitulo = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font boldFontTexto = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD); Font FontTexto = new Font(Font.FontFamily.HELVETICA, 10); // document.setPageSize(null); PdfWriter writer = PdfWriter.getInstance(document, outputStream); Image imagen = Image.getInstance("http://54.67.56.185/BSeguros_pa18/img/BSeguroLogo.png"); // Image imagen = Image.getInstance("D:\\ALEX\\Bseguros\\web\\img\\Aseguradoras\\BSeguroLogo.png"); Image imagen2 = Image.getInstance( "http://54.67.56.185/BSeguros_pa18/img/Aseguradoras/" + x.getId_aseguradora() + ".png"); //Image imagen2 = Image.getInstance("D:\\ALEX\\Bseguros\\web\\img\\Aseguradoras\\Mapfre.png"); document.open(); PdfContentByte canvas = writer.getDirectContent(); Rectangle rect = new Rectangle(36, 36, 579, 756); rect.setBorder(Rectangle.BOX); rect.setBorderWidth(2); canvas.rectangle(rect); document.addTitle("Cotizacion"); document.addSubject("Cotizacion"); document.addKeywords("Cotizacion, seguros"); document.addAuthor("BSeguro"); document.addCreator("Bseguro"); imagen.scaleAbsoluteHeight(30f); imagen.setAbsolutePosition(45f, 720f); imagen2.scaleAbsoluteHeight(30f); imagen2.setAbsolutePosition(450f, 720f); document.add(imagen); document.add(imagen2); Paragraph paragraph2 = new Paragraph("DATOS DE TU POLIZA", boldFontTitulo); paragraph2.setAlignment(Element.ALIGN_CENTER); document.add(paragraph2); //creas una tabla con un ancho de 3 celdas, el salto a la siguiente fila sera automatico PdfPTable table = new PdfPTable(3); table.getDefaultCell().setBorder(0); PdfPCell cell; Paragraph saltodelinea = new Paragraph(" "); document.add(saltodelinea); document.add(new Paragraph(" Datos de tu poliza folio: " + "BC" + x.getId_aseguradora().substring(0, 1) + x.getMetododepago().substring(0, 1) + ": 0000" + idcotizacion, boldFontTitulo)); document.add(new Paragraph(" Vigencia de la poliza del: " + fechadiamas + " al: " + fechavencimiento, boldFontTitulo)); document.add(saltodelinea); document.add(new Paragraph(" Datos del Contratante: ", boldFontTitulo)); //document.add(saltodelinea); //agrego otra tabla table = new PdfPTable(6); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell(new Paragraph("Nombre: ", boldFontTexto)); PdfPCell celdaNombre = new PdfPCell( new Paragraph(x.getNombre_contratante() + " " + x.getApellido_paterno(), FontTexto)); celdaNombre.setColspan(5); celdaNombre.setBorder(0); table.addCell(celdaNombre); table.addCell(new Paragraph("RFC : ", boldFontTexto)); PdfPCell celdaRFC = new PdfPCell(new Paragraph(x.getRfc(), FontTexto)); celdaRFC.setColspan(5); celdaRFC.setBorder(0); table.addCell(celdaRFC); table.addCell(new Paragraph("Direccion: ", boldFontTexto)); PdfPCell celdaDir = new PdfPCell( new Paragraph(x.getCall() + ", " + x.getNo_ext() + ", " + x.getNo_int() + ", " + x.getColonia() + ", " + x.getDelegacion() + ", " + x.getEstado() + ", " + x.getCp(), FontTexto)); celdaDir.setColspan(5); celdaDir.setBorder(0); table.addCell(celdaDir); table.addCell(new Paragraph("Email: ", boldFontTexto)); table.addCell(AddCell(x.getMail(), 5)); table.addCell(new Paragraph("Telefono ", boldFontTexto)); PdfPCell celdaTel = new PdfPCell(new Paragraph(x.getTelefono(), FontTexto)); celdaTel.setColspan(5); celdaTel.setBorder(0); table.addCell(celdaTel); document.add(table); document.add(saltodelinea); document.add(new Paragraph(" Datos del Vehiculo: ", boldFontTitulo)); // document.add(saltodelinea); //agrego otra tabla table = new PdfPTable(6); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell(new Paragraph("Marca: ", boldFontTexto)); table.addCell(AddCell(x.getId_marca(), 5)); table.addCell(new Paragraph("Modelo:", boldFontTexto)); table.addCell(AddCell(x.getId_anio().toString(), 5)); table.addCell(new Paragraph("Tipo: ", boldFontTexto)); table.addCell(AddCell(x.getId_submarca(), 5)); table.addCell(new Paragraph("Version: ", boldFontTexto)); table.addCell(AddCell(x.getId_modelo(), 5)); table.addCell(new Paragraph("No. De Serie: ", boldFontTexto)); table.addCell(AddCell(x.getSerie(), 5)); document.add(table); document.add(saltodelinea); document.add(new Paragraph(" Informacion de la Poliza: ", boldFontTitulo)); // document.add(saltodelinea); //agrego otra tabla table = new PdfPTable(6); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell(new Paragraph("Pago: ", boldFontTexto)); table.addCell(AddCell(x.getTipo_pago(), 5)); table.addCell(new Paragraph("Aseguradora: ", boldFontTexto)); table.addCell(AddCell(x.getId_aseguradora(), 5)); document.add(table); document.add(saltodelinea); document.add(new Paragraph(" Detalles de la Cobertura: Cobertura Amplia ", boldFontTitulo)); // document.add(saltodelinea); //agrego otra tabla table = new PdfPTable(3); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell(new Paragraph("Cobertura ", boldFontTexto)); table.addCell(new Paragraph("Responsabilidad Civil", boldFontTexto)); table.addCell(new Paragraph("Deducible ", boldFontTexto)); table.addCell(new Paragraph("Daos Materiales", FontTexto)); table.addCell(new Paragraph("Valor Comercial", FontTexto)); table.addCell(new Paragraph("5%", FontTexto)); table.addCell(new Paragraph("Robo Total", FontTexto)); table.addCell(new Paragraph("Valor Comercial", FontTexto)); table.addCell(new Paragraph("10%", FontTexto)); table.addCell(new Paragraph("Responsabilidad Civil", FontTexto)); table.addCell(new Paragraph("$4,000,000.00", FontTexto)); table.addCell(new Paragraph("", FontTexto)); table.addCell(new Paragraph("Gastos Medicos Ocupantes", FontTexto)); table.addCell(new Paragraph("$500,000.00", FontTexto)); table.addCell(new Paragraph("", FontTexto)); table.addCell(new Paragraph("Asistencia Legal", FontTexto)); table.addCell(new Paragraph("Amparada", FontTexto)); table.addCell(new Paragraph("", FontTexto)); table.addCell(new Paragraph("Asistencia Vial", FontTexto)); table.addCell(new Paragraph("Amparada", FontTexto)); table.addCell(new Paragraph("", FontTexto)); document.add(table); document.add(saltodelinea); document.add(new Paragraph(" Informacion del Pago ", boldFontTitulo)); document.add(new Paragraph(" Instrumento de Pago: " + x.getMetododepago(), boldFontTexto)); //agrego otra tabla table = new PdfPTable(6); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell(AddCell("Concepto ", 2)); table.addCell(AddCell("Monto", 4)); table.addCell(AddCell("Prima Total ", 2)); table.addCell(AddCell(x.getMonto(), 4)); table.addCell(AddCell("Prima Inicial", 2)); table.addCell(AddCell(x.getMonto(), 4)); table.addCell(AddCell("Pago Subsecuente ", 2)); table.addCell(AddCell("0", 4)); document.add(table); document.add(saltodelinea); if (x.getCobertura_auto_siempre() == true) { document.add(new Paragraph(" Informacion de Modulos HDI ", boldFontTitulo)); table = new PdfPTable(6); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell(AddCell("Modulos ", 2)); table.addCell(AddCell("Contratados", 4)); table.addCell(AddCell("HDI - Autos por Siempre ", 2)); table.addCell(AddCell("$ 1,799.00", 4)); document.add(table); } else { if (x.getCobertura_auto_amante() == true) { document.add(new Paragraph(" Informacion de Modulos HDI ", boldFontTitulo)); table = new PdfPTable(6); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell(AddCell("Modulos ", 2)); table.addCell(AddCell("Contratados", 4)); table.addCell(AddCell("HDI - Amante de los Autos ", 2)); table.addCell(AddCell("$ 1,799.00", 4)); document.add(table); } else { } document.add(saltodelinea); } document.add(new Paragraph("* Estaras asegurado a partir de las 12 horas del siguiente dia habil.", boldFontTexto)); document.close(); }
From source file:Modelo.CotizacionDAO.java
private PdfPCell AddCell(String email_, int columnas) { Font FontTexto = new Font(Font.FontFamily.HELVETICA, 10); PdfPCell celdaEmail = new PdfPCell(new Paragraph(email_, FontTexto)); celdaEmail.setColspan(columnas);/*www. j a v a2 s . c o m*/ celdaEmail.setBorder(0); return celdaEmail; }
From source file:modelo.GenerarPDF.java
public void nuevoReporteClientes(ArrayList<Cliente> Datos) throws IOException { // Se crea el documento Document documento = new Document(); // Se crea el OutputStream para el fichero donde queremos dejar el pdf. Document documento = null;/*from ww w. ja v a2 s . com*/ try { FileOutputStream ficheroPdf = new FileOutputStream("C:\\Users\\panle\\Documents\\ReporteClientes.pdf"); documento = new Document(); // Se asocia el documento al OutputStream y se indica que el espaciado entre // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); // Se abre el documento. documento.open(); documento.add(new Paragraph("REPORTE CLIENTES", FontFactory.getFont("ARIAL", // fuente 16, // tamao Font.ITALIC, // estilo BaseColor.BLACK))); // color PdfPTable tabla = new PdfPTable(9); Font font = new Font(FontFamily.COURIER, 6, Font.BOLD, BaseColor.BLACK); PdfPCell cell = new PdfPCell(new Phrase("algo", font)); documento.add(new Paragraph("\n")); Image img = Image.getInstance("C:\\Users\\panle\\Documents\\logo.png"); documento.add(img); documento.add(new Paragraph("\n")); int conta = 0; cell.setBorder(Rectangle.TITLE); tabla.addCell("NOMBRE COMLETO"); tabla.addCell("USUARIO"); tabla.addCell("NIT"); tabla.addCell("NO DOCUMENTO"); tabla.addCell("PROFESION"); tabla.addCell("TELFONO CELULAR"); tabla.addCell("TELFONO RESIDENCIA"); tabla.addCell("DIRECCIN"); tabla.addCell("CIUDAD"); while (conta < Datos.size()) { cell.setBorder(Rectangle.NO_BORDER); tabla.addCell(Datos.get(conta).getNOMBRE() + " " + Datos.get(conta).getAPELLIDO()); tabla.addCell(Datos.get(conta).getUSUARIO()); tabla.addCell(Datos.get(conta).getNIT()); tabla.addCell(Datos.get(conta).getNUMERO_DOC()); tabla.addCell(Datos.get(conta).getPROFESION()); tabla.addCell(Datos.get(conta).getTEL_CEL()); tabla.addCell(Datos.get(conta).getTEL_RESIDENCIA()); tabla.addCell(Datos.get(conta).getDIRECCION()); tabla.addCell(Datos.get(conta).getCIUDAD()); conta++; } documento.add(tabla); documento.close(); } catch (FileNotFoundException | DocumentException e) { System.out.println("Error al generar Reporte Clientes, por:"); e.printStackTrace(); } }
From source file:modelo.GenerarPDF.java
public void nuevoReporteProductos(ArrayList<Producto> Datos) throws IOException { // Se crea el documento Document // Se crea el OutputStream para el fichero donde queremos dejar el pdf. Document documento = null;/*from w w w . j a v a 2 s. com*/ try { //Direccion root FileOutputStream ficheroPdf = new FileOutputStream("C:\\Users\\panle\\Documents\\ReporteProductos.pdf"); //FileOutputStream ficheroPdf = new FileOutputStream("user.dir/tmp", "ReporteProductos.pdf"); //File tempfile = new File("user.dir/tmp", "tempfile.txt"); documento = new Document(); // Se asocia el documento al OutputStream y se indica que el espaciado entre // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); // Se abre el documento documento.open(); documento.add(new Paragraph("REPORTE PRODUCTOS", FontFactory.getFont("ARIAL", // fuente 16, // tamao Font.ITALIC, // estilo BaseColor.BLACK))); // color PdfPTable tabla = new PdfPTable(3);//#campos(columnas) para la tabla Font font = new Font(FontFamily.COURIER, 6, Font.BOLD, BaseColor.BLACK); PdfPCell cell = new PdfPCell(new Phrase("Celdas", font)); documento.add(new Paragraph("\n")); Image img = Image.getInstance("C:\\Users\\logo.png"); documento.add(img); documento.add(new Paragraph("\n")); int conta = 0; cell.setBorder(Rectangle.TITLE); tabla.addCell("DESCRIPCION"); tabla.addCell("REFERENCIA"); tabla.addCell("TIPO"); while (conta < Datos.size()) { cell.setBorder(Rectangle.NO_BORDER); tabla.addCell(Datos.get(conta).getDESCRIPCION()); tabla.addCell(Datos.get(conta).getREFERENCIA()); tabla.addCell(Datos.get(conta).getTIPO()); conta++; } documento.add(tabla); documento.close(); } catch (FileNotFoundException | DocumentException e) { System.out.println("Error al generar Reporte Productos, por:"); e.printStackTrace(); } }
From source file:modelo.GenerarPDF.java
public void nuevoReporteVentasFecha(ArrayList<Producto> Datos) throws IOException { // Se crea el documento Document // Se crea el OutputStream para el fichero donde queremos dejar el pdf. Document documento = null;/* w ww.j av a 2s .c o m*/ try { //Direccion root FileOutputStream ficheroPdf = new FileOutputStream( "C:\\Users\\panle\\Documents\\ReporteVentasFecha.pdf"); //FileOutputStream ficheroPdf = new FileOutputStream("user.dir/tmp", "ReporteProductos.pdf"); //File tempfile = new File("user.dir/tmp", "tempfile.txt"); documento = new Document(); // Se asocia el documento al OutputStream y se indica que el espaciado entre // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); // Se abre el documento documento.open(); documento.add(new Paragraph("REPORTE VENTAS POR FECHA", FontFactory.getFont("ARIAL", // fuente 16, // tamao Font.ITALIC, // estilo BaseColor.BLACK))); // color PdfPTable tabla = new PdfPTable(3);//#campos(columnas) para la tabla Font font = new Font(FontFamily.COURIER, 6, Font.BOLD, BaseColor.BLACK); PdfPCell cell = new PdfPCell(new Phrase("Celdas", font)); documento.add(new Paragraph("\n")); Image img = Image.getInstance("C:\\Users\\logo.png"); documento.add(img); documento.add(new Paragraph("\n")); int conta = 0; cell.setBorder(Rectangle.TITLE); tabla.addCell("DESCRIPCION"); tabla.addCell("REFERENCIA"); tabla.addCell("TIPO"); while (conta < Datos.size()) { cell.setBorder(Rectangle.NO_BORDER); tabla.addCell(Datos.get(conta).getDESCRIPCION()); tabla.addCell(Datos.get(conta).getREFERENCIA()); tabla.addCell(Datos.get(conta).getTIPO()); conta++; } documento.add(tabla); documento.close(); } catch (FileNotFoundException | DocumentException e) { System.out.println("Error al generar Reporte Productos, por:"); e.printStackTrace(); } }
From source file:modelo.GenerarPDF.java
public void nuevoReporteVentasCiudad(ArrayList<Producto> Datos) throws IOException { // Se crea el documento Document // Se crea el OutputStream para el fichero donde queremos dejar el pdf. Document documento = null;/*from w ww. j a va 2s .co m*/ try { //Direccion root FileOutputStream ficheroPdf = new FileOutputStream( "C:\\Users\\panle\\Documents\\ReporteVentasCiudad.pdf"); //FileOutputStream ficheroPdf = new FileOutputStream("user.dir/tmp", "ReporteProductos.pdf"); //File tempfile = new File("user.dir/tmp", "tempfile.txt"); documento = new Document(); // Se asocia el documento al OutputStream y se indica que el espaciado entre // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); // Se abre el documento documento.open(); documento.add(new Paragraph("REPORTE VENTAS POR CIUDAD", FontFactory.getFont("ARIAL", // fuente 16, // tamao Font.ITALIC, // estilo BaseColor.BLACK))); // color PdfPTable tabla = new PdfPTable(3);//#campos(columnas) para la tabla Font font = new Font(FontFamily.COURIER, 6, Font.BOLD, BaseColor.BLACK); PdfPCell cell = new PdfPCell(new Phrase("Celdas", font)); documento.add(new Paragraph("\n")); Image img = Image.getInstance("C:\\Users\\logo.png"); documento.add(img); documento.add(new Paragraph("\n")); int conta = 0; cell.setBorder(Rectangle.TITLE); tabla.addCell("DESCRIPCION"); tabla.addCell("REFERENCIA"); tabla.addCell("TIPO"); while (conta < Datos.size()) { cell.setBorder(Rectangle.NO_BORDER); tabla.addCell(Datos.get(conta).getDESCRIPCION()); tabla.addCell(Datos.get(conta).getREFERENCIA()); tabla.addCell(Datos.get(conta).getTIPO()); conta++; } documento.add(tabla); documento.close(); } catch (FileNotFoundException | DocumentException e) { System.out.println("Error al generar Reporte Productos, por:"); e.printStackTrace(); } }
From source file:modelo.GenerarPDF.java
public void nuevoReporteVentasMueble(ArrayList<Producto> Datos) throws IOException { // Se crea el documento Document // Se crea el OutputStream para el fichero donde queremos dejar el pdf. Document documento = null;/* w ww. j av a2s .co m*/ try { //Direccion root FileOutputStream ficheroPdf = new FileOutputStream( "C:\\Users\\panle\\Documents\\ReporteVentasMueble.pdf"); //FileOutputStream ficheroPdf = new FileOutputStream("user.dir/tmp", "ReporteProductos.pdf"); //File tempfile = new File("user.dir/tmp", "tempfile.txt"); documento = new Document(); // Se asocia el documento al OutputStream y se indica que el espaciado entre // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); // Se abre el documento documento.open(); documento.add(new Paragraph("REPORTE VENTAS POR MUEBLE", FontFactory.getFont("ARIAL", // fuente 16, // tamao Font.ITALIC, // estilo BaseColor.BLACK))); // color PdfPTable tabla = new PdfPTable(3);//#campos(columnas) para la tabla Font font = new Font(FontFamily.COURIER, 6, Font.BOLD, BaseColor.BLACK); PdfPCell cell = new PdfPCell(new Phrase("Celdas", font)); documento.add(new Paragraph("\n")); Image img = Image.getInstance("C:\\Users\\logo.png"); documento.add(img); documento.add(new Paragraph("\n")); int conta = 0; cell.setBorder(Rectangle.TITLE); tabla.addCell("DESCRIPCION"); tabla.addCell("REFERENCIA"); tabla.addCell("TIPO"); while (conta < Datos.size()) { cell.setBorder(Rectangle.NO_BORDER); tabla.addCell(Datos.get(conta).getDESCRIPCION()); tabla.addCell(Datos.get(conta).getREFERENCIA()); tabla.addCell(Datos.get(conta).getTIPO()); conta++; } documento.add(tabla); documento.close(); } catch (FileNotFoundException | DocumentException e) { System.out.println("Error al generar Reporte Productos, por:"); e.printStackTrace(); } }
From source file:mvjce.PDF.java
public static PdfPCell getCell(String text, int alignment) { PdfPCell cell = new PdfPCell(new Phrase(text, new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD))); cell.setPadding(1);//from w w w .j a va 2 s . c om cell.setHorizontalAlignment(alignment); cell.setBorder(PdfPCell.NO_BORDER); return cell; }
From source file:naprawa.praca.PracaController.java
public void akcjaDrukuj() { mapaUslug = getDaoFactory().getDaoDefect().pobierzUslugi(getConnection(), wybranyDefect); FileOutputStream file = null; File druk = null;//from w w w .j a v a2 s.c o m try { Document document = new Document(PageSize.A5, 0, 0, 0, 0); String userPath = System.getProperty("user.home"); druk = new File(userPath + "/Baks wydruki"); if (!druk.exists()) { druk.mkdirs(); } File wydruk = new File(druk + "/" + wybranyDefect.getInfoNaprawa() + ".pdf"); if (!wydruk.exists()) { try { wydruk.createNewFile(); } catch (IOException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } } file = new FileOutputStream(wydruk); try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(wydruk)); document.open(); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); table.setSpacingBefore(0f); table.setSpacingAfter(0f); PdfPTable tableO = new PdfPTable(2); tableO.setWidthPercentage(100); tableO.setSpacingBefore(0f); table.setSpacingAfter(0f); tableO.addCell(getNewCell( "BAK's Machine\nin. Baej Krzciuk\n26-800 Biaobrzegi\nul. Brzechwy 31\ntel. 509-281-487")); Image image = Image.getInstance(getClass().getClassLoader().getResource("baksZ.jpg")); tableO.addCell(image); table.addCell(tableO); PdfPCell cell1 = getNewCell( "Biaobrzegi, dn. " + new SimpleDateFormat("yyyy-MM-dd").format(new Date())); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(addTableCzesc()); table.addCell(addTableCzescService("Materiay", RodzajUslugi.MATERIAL)); table.addCell(addTableCzescService("Naprawa", RodzajUslugi.NAPRAWA)); PdfPTable tablePodsumowanie = new PdfPTable(3); tablePodsumowanie.setWidthPercentage(100); int[] width = { 8, 77, 15 }; tablePodsumowanie.setWidths(width); PdfPCell cell = getNewCell("Podsumowanie"); cell.setColspan(10); cell.setBorder(PdfPCell.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tablePodsumowanie.addCell(cell); tablePodsumowanie.addCell(getNewCell("1.")); tablePodsumowanie.addCell(getNewCell("Czci")); tablePodsumowanie.addCell(getNewCell(wybranyDefect.getKosztCzesciS() + " z")); tablePodsumowanie.addCell(getNewCell("2.")); tablePodsumowanie.addCell(getNewCell("Materiay")); tablePodsumowanie.addCell(getNewCell(wybranyDefect.getKosztMaterialyS() + " z")); tablePodsumowanie.addCell(getNewCell("3.")); tablePodsumowanie.addCell(getNewCell("Naprawa")); tablePodsumowanie.addCell(getNewCell(wybranyDefect.getKosztNaprawyS() + " z")); tablePodsumowanie.addCell(getNewCell("")); tablePodsumowanie.addCell(getNewCell("RAZEM")); tablePodsumowanie.addCell(getNewCell(wybranyDefect.getKosztSumaS() + " z")); table.addCell(tablePodsumowanie); document.add(table); document.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); } } catch (FileNotFoundException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); BaksSessionBean.getInstance().fireMessage(widok, "Wydruk", "Pdf do ktrego chcesz zapisa wynik jest otwarty!\n Zamknij i sprbuj jeszcze raz."); } finally { try { file.close(); } catch (IOException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } } Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); try { desktop.open(druk); } catch (IOException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } } BaksSessionBean.getInstance().fireMessage(widok, "Zapis", "Wydruk zapisany w folderze: " + System.getProperty("user.home") + "/Baks wydruki"); }