List of usage examples for com.itextpdf.text Paragraph add
@Override public boolean add(Element o)
Element
to the Paragraph
. From source file:com.workhub.utils.PDFUtils.java
private static void createList(Paragraph sommaire, List<ElementModel> models) { com.itextpdf.text.List list = new com.itextpdf.text.List(true, false, 10); for (ElementModel elementModel : models) { list.add(elementModel.getTitle()); }/* w w w .j av a2s.com*/ sommaire.add(list); }
From source file:com.zaptech.pdfdemo.MainActivity.java
private void addTitlePage(Document document) { try {//w w w .j ava 2 s. c om Paragraph paragraph = new Paragraph(); addEmptyLine(paragraph, 1); paragraph.add(new Paragraph("Sample Title", catFont)); addEmptyLine(paragraph, 1); paragraph.add( new Paragraph("Report generated by:: " + System.getProperty("user.name") + ", ", smallFont)); addEmptyLine(paragraph, 3); paragraph.add(new Paragraph("This document describes something which is very important ", smallFont)); addEmptyLine(paragraph, 8); paragraph.add(new Paragraph( "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).", redFont)); document.add(paragraph); document.newPage(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.zaptech.pdfdemo.MainActivity.java
private void addEmptyLine(Paragraph paragraph, int i) { for (int j = 0; j < i; j++) { paragraph.add(""); }//from www .j a v a 2 s. c om }
From source file:comisionesafis.informes.CintaComisiones.java
public boolean generar() { // Abrimos el fichero de comisiones String sSQL = ""; Statement stmt;// www . ja va2 s . com ResultSet rsComisiones; ResultSet rsBanco; String cuenta; // Generamos la sentencia de Seleccin de Datos try { // Generamos el PDF Document documento = new Document(PageSize.A4, 80, 80, 50, 50); FileOutputStream salida = new FileOutputStream(FICHERO_PDF); PdfWriter writer = PdfWriter.getInstance(documento, salida); writer.setInitialLeading(0); // Obtenemos una instancia de nuestro manejador de eventos CintaComisionesPie pie = new CintaComisionesPie(); //Asignamos el manejador de eventos al escritor. writer.setPageEvent(pie); // Abrimos el Documento documento.open(); sSQL = "SELECT * "; sSQL += " FROM ResumenComisiones"; sSQL += " ORDER BY CodAgente"; stmt = conexion.createStatement(); rsComisiones = stmt.executeQuery(sSQL); Paragraph Titulo = new Paragraph(); Titulo.setAlignment(Element.ALIGN_CENTER); Titulo.add("CINTA COMISIONES"); float[] anchuras = { 1f, 1.5f, 3f, 4f, 1f, 1.5f }; PdfPTable table = new PdfPTable(anchuras); table.setWidthPercentage(100); table.setSpacingBefore(15f); table.setSpacingAfter(10f); PdfPCell celda; // Tipo de letra para la tabla Font font = new Font(Font.FontFamily.COURIER, 8, Font.NORMAL); celda = new PdfPCell(new Phrase("Agente", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(celda); celda = new PdfPCell(new Phrase("Importe", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(celda); celda = new PdfPCell(new Phrase("Cuenta Bancaria", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(celda); celda = new PdfPCell(new Phrase("Nombre", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(celda); celda = new PdfPCell(new Phrase("Irpf", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(celda); celda = new PdfPCell(new Phrase("Total", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(celda); while (rsComisiones.next()) { // Buscamos la Cuenta Bancaria sSQL = "SELECT * "; sSQL += " FROM Agentes"; sSQL += " WHERE CodAgente='" + rsComisiones.getString("CodAgente") + "'"; stmt = conexion.createStatement(); rsBanco = stmt.executeQuery(sSQL); if (!rsBanco.next()) { cuenta = " "; } else { cuenta = rsBanco.getString("Banco"); cuenta += rsBanco.getString("Sucursal"); cuenta += rsBanco.getString("DC"); cuenta += rsBanco.getString("Cuenta"); } // Datos del agente celda = new PdfPCell(new Phrase(rsComisiones.getString("CodAgente"), font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(celda); celda = new PdfPCell(new Phrase( Numeros.formateaDosDecimales(Double.parseDouble(rsComisiones.getString("TotalComisiones"))), font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); celda = new PdfPCell(new Phrase(cuenta, font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(celda); celda = new PdfPCell(new Phrase(rsComisiones.getString("Nombre"), font)); celda.setBorder(Rectangle.NO_BORDER); table.addCell(celda); celda = new PdfPCell(new Phrase( Numeros.formateaDosDecimales(Double.parseDouble(rsComisiones.getString("TotalRetencion"))), font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); celda = new PdfPCell(new Phrase( Numeros.formateaDosDecimales(Double.parseDouble(rsComisiones.getString("TotalPagar"))), font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); } documento.add(Titulo); documento.add(new Paragraph(" ")); // Agregamos la tabla al documento documento.add(table); documento.close(); return true; } catch (Exception e) { return false; } }
From source file:comisionesafis.informes.FacturasComisionesAgentes.java
public boolean generar() { // Abrimos el fichero de comisiones Periodos periodos = new Periodos(pb.getFicheroComisiones()); String sSQL = ""; Statement stmt;/*ww w . j ava 2 s . co m*/ ResultSet rsComisiones; String sFactura1; String sFactura2; // Generamos la sentencia de Seleccin de Datos try { // Generamos el PDF Document documento = new Document(PageSize.A4, 80, 80, 50, 50); FileOutputStream salida = new FileOutputStream("FacturasComisionesAgentes.pdf"); PdfWriter writer = PdfWriter.getInstance(documento, salida); writer.setInitialLeading(0); // Obtenemos una instancia de nuestro manejador de eventos FacturasComisionesAgentesPie pie = new FacturasComisionesAgentesPie(); //Asignamos el manejador de eventos al escritor. writer.setPageEvent(pie); // Abrimos el Documento documento.open(); sSQL = "SELECT * "; sSQL += " FROM ResumenComisiones"; sSQL += " ORDER BY CodAgente"; stmt = conexion.createStatement(); rsComisiones = stmt.executeQuery(sSQL); while (rsComisiones.next()) { // Generamos los prrafos // Datos del agente Paragraph pAgente[] = new Paragraph[5]; pAgente[0] = new Paragraph(); pAgente[0].add(rsComisiones.getString("Nombre")); pAgente[0].setAlignment(Paragraph.ALIGN_LEFT); pAgente[1] = new Paragraph(); pAgente[1].add(rsComisiones.getString("Direccion")); pAgente[1].setAlignment(Paragraph.ALIGN_LEFT); pAgente[2] = new Paragraph(); pAgente[2].add(rsComisiones.getString("CodPostal") + " " + rsComisiones.getString("Poblacion")); pAgente[2].setAlignment(Paragraph.ALIGN_LEFT); pAgente[3] = new Paragraph(); pAgente[3].add(rsComisiones.getString("Provincia")); pAgente[3].setAlignment(Paragraph.ALIGN_LEFT); pAgente[4] = new Paragraph(); pAgente[4].add(rsComisiones.getString("NIF")); pAgente[4].setAlignment(Paragraph.ALIGN_LEFT); // creating separators LineSeparator separador = new LineSeparator(1, 100, null, Element.ALIGN_CENTER, -2); // Datos fijos Paragraph pPelayo[] = new Paragraph[5]; pPelayo[0] = new Paragraph(); pPelayo[0].add("PELAYO VIDA"); pPelayo[0].setAlignment(Paragraph.ALIGN_RIGHT); pPelayo[1] = new Paragraph(); pPelayo[1].add("CL SANTA ENGRACIA 69"); pPelayo[1].setAlignment(Paragraph.ALIGN_RIGHT); pPelayo[2] = new Paragraph(); pPelayo[2].add("28010 MADRID"); pPelayo[2].setAlignment(Paragraph.ALIGN_RIGHT); pPelayo[3] = new Paragraph(); pPelayo[3].add("MADRID"); pPelayo[3].setAlignment(Paragraph.ALIGN_RIGHT); pPelayo[4] = new Paragraph(); pPelayo[4].add("06422"); pPelayo[4].setAlignment(Paragraph.ALIGN_RIGHT); // Fecha Paragraph pFecha = new Paragraph(); pFecha = new Paragraph("Madrid, a " + periodos.extraeFechaLarga()); pFecha.setAlignment(Paragraph.ALIGN_RIGHT); // Lnea 1 de FACTURA Paragraph pFactura1 = new Paragraph(); sFactura1 = "FACTURA: n factura "; sFactura1 += rsComisiones.getString("CodAgente") + " - "; sFactura1 += periodos.extraePeriodoMY("MM-YYYY"); pFactura1 = new Paragraph(sFactura1); // Lnea 2 de FACTURA Paragraph pFactura2 = new Paragraph(); sFactura2 = "Factura por la prestacin de servicios relativos a las operaciones "; sFactura2 += "de intermediacin de seguros realizadas para su entidad del mes de "; sFactura2 += periodos.extraePeriodoMY("MM YYYY"); ; pFactura2 = new Paragraph(sFactura2); // Datos Econmicos float[] anchuras = { 5f, 2f }; PdfPTable table = new PdfPTable(anchuras); table.getDefaultCell().setBorder(0); // Tipo de letra para la tabla Font font = new Font(Font.FontFamily.COURIER, 11, Font.NORMAL); PdfPCell celda = new PdfPCell(); celda = new PdfPCell(new Phrase("Comisiones pagadas", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(celda); celda = new PdfPCell( new Phrase(Double.toString(rsComisiones.getDouble("TotalComisiones")) + " ", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); celda = new PdfPCell(new Phrase("Otros conceptos", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(celda); celda = new PdfPCell(new Phrase(" ", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); celda = new PdfPCell(new Phrase( "Retencin (" + Double.toString(rsComisiones.getDouble("RetencionPorcentaje")) + "%)", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(celda); Double dblRetencion = rsComisiones.getDouble("TotalComisiones") * (rsComisiones.getDouble("RetencionPorcentaje") / 100); celda = new PdfPCell(new Phrase(Numeros.formateaDosDecimales(dblRetencion) + " ", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); celda = new PdfPCell(new Phrase("Conceptos no sujetos", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(celda); celda = new PdfPCell(new Phrase(" ", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); celda = new PdfPCell(new Phrase("Total a pagar", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(celda); Double dblTotalPagar = rsComisiones.getDouble("TotalComisiones") - dblRetencion; celda = new PdfPCell(new Phrase(Numeros.formateaDosDecimales(dblTotalPagar) + " ", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); // Literal: Operacin exenta de IVA Paragraph pColetilla = new Paragraph(); pColetilla.add("Operacin exenta de IVA"); // Aadimos los prrafos al Documento for (int i = 0; i < 5; i++) documento.add(pAgente[i]); documento.add(new Paragraph(" ")); documento.add(separador); for (int i = 0; i < 5; i++) documento.add(pPelayo[i]); documento.add(new Paragraph(" ")); documento.add(pFecha); documento.add(new Paragraph(" ")); documento.add(pFactura1); documento.add(separador); documento.add(pFactura2); // Agregamos la tabla al documento documento.add(new Paragraph(" ")); documento.add(table); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(pColetilla); documento.newPage(); } documento.close(); return true; } catch (Exception e) { return false; } }
From source file:containers.Receipt.java
public void printReceiptTogether() { try {//from w ww . j av a2 s . co m String path = System.getProperty("user.home") + File.separator + "Documents"; OutputStream file = new FileOutputStream(new File(path + "\\receiptTogether.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER)); Image img = Image.getInstance(new URL(link)); img.scalePercent(56f); p.add(img); p.add(header); p.add(new Date().toString()); footerTogether(); p.add(body); p.add(footer); document.add(p); document.close(); file.close(); header = ""; body = ""; footer = ""; } catch (Exception e) { e.printStackTrace(); } }
From source file:containers.Receipt.java
public void printReceiptSeparate() { try {//www .j a v a 2s . c o m String path = System.getProperty("user.home") + File.separator + "Documents"; OutputStream file = new FileOutputStream(new File(path + "\\receipt" + orderNumber + ".pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER)); Image img = Image.getInstance(new URL(link)); img.scalePercent(56f); p.add(img); p.add(header); p.add(new Date().toString()); footerSeparate(); p.add(body); p.add(footer); document.add(p); document.close(); file.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:containers.Receipt.java
public void printSentOrder(Order order) { ArrayList<Item> items = order.getItems(); orderNumber = Integer.toString(order.getOrderNo()); drink = "Bar Order\n"; drink += "\nOrder #: " + orderNumber + "\n"; drink += "Server : " + empName + "\n\n"; drink += String.format("%-15s\n", "Item"); drink += String.format("%-15s\n", "----"); food = "Kitchen Order\n"; food += "\nOrder #: " + orderNumber + "\n"; food += "Server : " + empName + "\n\n"; food += String.format("%-15s\n", "Item"); food += String.format("%-15s\n", "----"); for (Item item : items) { if (item.getItemType().equalsIgnoreCase("drink")) { drink += String.format("%-15s", item.getItemName()); drink += "\n"; drinkCount++;/*ww w . ja v a 2s. co m*/ } else { food += String.format("%-15s", item.getItemName()); food += "\n"; foodCount++; } } if (drinkCount > 0) { try { String path = System.getProperty("user.home") + File.separator + "Documents"; OutputStream file = new FileOutputStream(new File(path + "\\barOrder" + orderNumber + ".pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER)); p.add(new Date().toString() + "\n"); p.add(drink); document.add(p); document.close(); file.close(); } catch (Exception e) { e.printStackTrace(); } } if (foodCount > 0) { try { String path = System.getProperty("user.home") + File.separator + "Documents"; OutputStream file = new FileOutputStream(new File(path + "\\kitchenOrder" + orderNumber + ".pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER)); p.add(new Date().toString() + "\n"); p.add(food); document.add(p); document.close(); file.close(); } catch (Exception e) { e.printStackTrace(); } } drink = ""; food = ""; }
From source file:containers.Report.java
public void generateHours(String hours, String from, String to) { try {/*ww w .j av a 2 s . co m*/ String path = System.getProperty("user.home") + File.separator + "Documents"; OutputStream file = new FileOutputStream(new File(path + "\\EmployeeReport.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER)); Image img = Image.getInstance(new URL(link)); img.scalePercent(56f); p.add(img); ehours = hours; body = String.format("%-15s - %2s\n", "Employee Number", empno); body += String.format("%-15s - %5s\n", "First Name", fname); body += String.format("%-15s - %1s\n", "Last Name", lname); body += String.format("%-15s - %9s\n", "Address", address); body += String.format("%-15s - %9s\n", "Phone Number", phone); body += String.format("%-15s - %3s\n", "Position", position); body += String.format("%-15s - %8s\n", "Total Hours", ehours); body += "\n"; from = from.substring(0, 10); to = to.substring(0, 10); p.add(new Date().toString()); p.add("\n\nEmployee Report\n\n"); p.add("Reporting Date: \n" + from + " - " + to + "\n\n"); p.add(body); document.add(p); document.close(); file.close(); body = ""; } catch (Exception e) { e.printStackTrace(); } }
From source file:containers.Report.java
public void generateOrderByDate(ArrayList<String> entry, String from, String to) { try {//from w w w .j ava2 s. c om String path = System.getProperty("user.home") + File.separator + "Documents"; OutputStream file = new FileOutputStream(new File(path + "\\DateOrderReport.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER)); Image img = Image.getInstance(new URL(link)); img.scalePercent(56f); p.add(img); body2 = String.format("%5s - %5s - %5s - %5s\n", "Order No.", "Order Total", "Payment Type", "Order Date"); double counter = 0; for (int i = 0; i < entry.size(); i += 4) { body2 += String.format("%-10s %8s %15s %24s\n", entry.get(i), entry.get(i + 1), entry.get(i + 2), entry.get(i + 3).substring(0, 19)); counter += Double.parseDouble(entry.get(i + 1)); } body2 += "\n\nTotal for all orders: $" + counter; from = from.substring(0, 10); to = to.substring(0, 10); p.add(new Date().toString()); p.add("\n\nOrder by Date Report\n"); p.add("Reporting Date: \n" + from + " - " + to + "\n\n"); p.add(body2); document.add(p); document.close(); file.close(); body2 = ""; } catch (Exception e) { e.printStackTrace(); } }