List of usage examples for com.itextpdf.text Phrase Phrase
private Phrase(final boolean dummy)
From source file:ControleurClients.ControleurClients.java
private void pageCommandes(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DocumentException { request.setAttribute("attente", commandef.getAttente(clientConnect)); request.setAttribute("cours", commandef.getCours(clientConnect)); request.setAttribute("effectuee", commandef.getEffectuee(clientConnect)); List<Commande> attente = commandef.getAttente(); List<Commande> cours = commandef.getCours(); List<Commande> effectue = commandef.getEffectuee(); if (!attente.isEmpty()) { for (Commande c : attente) { Document document1 = new Document(); PdfWriter.getInstance(document1, new FileOutputStream("/home/aymeric/Commerce/Commerce/Commerce-war/web/pdf/attente" + c.getId().toString() + ".pdf")); document1.open();/*from w w w . j a v a 2 s.c o m*/ Paragraph text = new Paragraph(); text.add(new Paragraph("Grenoble Dvd", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph("Facture", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph("En attente : Commande n" + c.getId().toString(), new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); document1.add(text); Paragraph p = new Paragraph(c.getDate(), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC)); p.setAlignment(Element.ALIGN_RIGHT); p.add(new Paragraph(" ")); p.add(new Paragraph(" ")); document1.add(p); Paragraph text1 = new Paragraph(); text1.add(new Paragraph( "Mr " + c.getClient().getNom().substring(0, 1).toUpperCase() + c.getClient().getNom().substring(1) + " " + c.getClient().getPrenom().substring(0, 1).toUpperCase() + c.getClient().getPrenom().substring(1), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); text1.add(new Paragraph("Email: " + c.getClient().getEmail(), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); document1.add(text1); PdfPTable table = new PdfPTable(3); //On crer l'objet cellule. PdfPCell cell; cell = new PdfPCell(new Phrase("Facture")); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Phrase("Nom du Dvd")); cell.setRowspan(1); table.addCell(cell); //contenu du tableau. table.addCell("Quantit"); table.addCell("Prix"); for (Entry<Dvd, Integer> entry : c.getDvds().entrySet()) { Dvd dvd = (Dvd) entry.getKey(); Object value = entry.getValue(); //Image dvdimage = Image.getInstance(dvd.getImage()); //On crer un objet table dans lequel on intialise a taille. cell = new PdfPCell(new Phrase(dvd.getTitre())); cell.setRowspan(1); table.addCell(cell); table.addCell(String.valueOf(value)); table.addCell(String.valueOf(dvd.getPrix())); } cell = new PdfPCell(new Phrase("Total: " + String.valueOf(c.getMontant()) + " ")); cell.setColspan(3); table.addCell(cell); document1.add(table); Paragraph p1 = new Paragraph(); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" Grenoble Dvd: 12 avenue des ensimag 38000 Grenoble", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); p1.setAlignment(Element.ALIGN_RIGHT); document1.add(p1); document1.close(); } } if (!cours.isEmpty()) { for (Commande c : cours) { Document document1 = new Document(); PdfWriter.getInstance(document1, new FileOutputStream("/home/aymeric/Commerce/Commerce/Commerce-war/web/pdf/cours" + c.getId().toString() + ".pdf")); document1.open(); Paragraph text = new Paragraph(); text.add(new Paragraph("Grenoble Dvd", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph("Facture", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph("En cours : Commande n" + c.getId().toString(), new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); document1.add(text); Paragraph p = new Paragraph(c.getDate(), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC)); p.setAlignment(Element.ALIGN_RIGHT); p.add(new Paragraph(" ")); p.add(new Paragraph(" ")); document1.add(p); Paragraph text1 = new Paragraph(); text1.add(new Paragraph( "Mr " + c.getClient().getNom().substring(0, 1).toUpperCase() + c.getClient().getNom().substring(1) + " " + c.getClient().getPrenom().substring(0, 1).toUpperCase() + c.getClient().getPrenom().substring(1), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); text1.add(new Paragraph("Email: " + c.getClient().getEmail(), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); document1.add(text1); PdfPTable table = new PdfPTable(3); //On crer l'objet cellule. PdfPCell cell; cell = new PdfPCell(new Phrase("Facture")); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Phrase("Nom du Dvd")); cell.setRowspan(1); table.addCell(cell); //contenu du tableau. table.addCell("Quantit"); table.addCell("Prix"); for (Entry<Dvd, Integer> entry : c.getDvds().entrySet()) { Dvd dvd = (Dvd) entry.getKey(); Object value = entry.getValue(); //Image dvdimage = Image.getInstance(dvd.getImage()); //On crer un objet table dans lequel on intialise a taille. cell = new PdfPCell(new Phrase(dvd.getTitre())); cell.setRowspan(1); table.addCell(cell); table.addCell(String.valueOf(value)); table.addCell(String.valueOf(dvd.getPrix())); } cell = new PdfPCell(new Phrase("Total : " + String.valueOf(c.getMontant()) + " ")); cell.setColspan(3); table.addCell(cell); document1.add(table); Paragraph p1 = new Paragraph(); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" Grenoble Dvd: 12 avenue des ensimag 38000 Grenoble", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); p1.setAlignment(Element.ALIGN_RIGHT); document1.add(p1); document1.close(); } } if (!effectue.isEmpty()) { for (Commande c : effectue) { new File("/home/aymeric/Commerce/Commerce/Commerce-war/web/pdf/attente" + c.getId().toString() + ".pdf").delete(); new File("/home/aymeric/Commerce/Commerce/Commerce-war/web/pdf/cours" + c.getId().toString() + ".pdf").delete(); Document document1 = new Document(); PdfWriter.getInstance(document1, new FileOutputStream("/home/aymeric/Commerce/Commerce/Commerce-war/web/pdf/effectue" + c.getId().toString() + ".pdf")); document1.open(); Paragraph text = new Paragraph(); text.add(new Paragraph("Grenoble Dvd", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph("Facture", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph("Effectue : Commande n" + c.getId().toString(), new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); document1.add(text); Paragraph p = new Paragraph(c.getDate(), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC)); p.setAlignment(Element.ALIGN_RIGHT); p.add(new Paragraph(" ")); p.add(new Paragraph(" ")); document1.add(p); Paragraph text1 = new Paragraph(); text1.add(new Paragraph( "Mr " + c.getClient().getNom().substring(0, 1).toUpperCase() + c.getClient().getNom().substring(1) + " " + c.getClient().getPrenom().substring(0, 1).toUpperCase() + c.getClient().getPrenom().substring(1), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); text1.add(new Paragraph("Email: " + c.getClient().getEmail(), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); document1.add(text1); PdfPTable table = new PdfPTable(3); //On crer l'objet cellule. PdfPCell cell; cell = new PdfPCell(new Phrase("Facture")); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Phrase("Nom du Dvd")); cell.setRowspan(1); table.addCell(cell); //contenu du tableau. table.addCell("Quantit"); table.addCell("Prix"); for (Entry<Dvd, Integer> entry : c.getDvds().entrySet()) { Dvd dvd = (Dvd) entry.getKey(); Object value = entry.getValue(); //Image dvdimage = Image.getInstance(dvd.getImage()); //On crer un objet table dans lequel on intialise a taille. cell = new PdfPCell(new Phrase(dvd.getTitre())); cell.setRowspan(1); table.addCell(cell); table.addCell(String.valueOf(value)); table.addCell(String.valueOf(dvd.getPrix())); } cell = new PdfPCell(new Phrase("Total : " + String.valueOf(c.getMontant()) + " ")); cell.setColspan(3); table.addCell(cell); document1.add(table); Paragraph p1 = new Paragraph(); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" Grenoble Dvd: 12 avenue des ensimag 38000 Grenoble", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); p1.setAlignment(Element.ALIGN_RIGHT); document1.add(p1); document1.close(); } } getServletContext().getRequestDispatcher("/WEB-INF/Commande.jsp").forward(request, response); }
From source file:Controller.CrearPDF.java
/** * We create a PDF document with iText using different elements to learn * to use this library.// www . j a va 2 s . c o m * Creamos un documento PDF con iText usando diferentes elementos para aprender * a usar esta librera. * @param pdfNewFile <code>String</code> * pdf File we are going to write. * Fichero pdf en el que vamos a escribir. */ // public void createPDF(File pdfNewFile, ReparacionEntity reparacion) throws Exception { public void createPDF(File pdfNewFile) throws Exception { // We create the document and set the file name. // Creamos el documento e indicamos el nombre del fichero. try { // ClienteController cc = new ClienteController(); // Cliente cliente = cc.buscarPorId(reparacion.getCliente()); Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream(pdfNewFile)); } catch (FileNotFoundException fileNotFoundException) { System.out.println("No such file was found to generate the PDF " + "(No se encontr el fichero para generar el pdf)" + fileNotFoundException); } document.open(); // We add metadata to PDF // Aadimos los metadatos del PDF document.addTitle("Table export to PDF (Exportamos la tabla a PDF)"); document.addSubject("Using iText (usando iText)"); document.addKeywords("Java, PDF, iText"); document.addAuthor("Cdigo Xules"); document.addCreator("Cdigo Xules"); // First page // Primera pgina Chunk chunk = new Chunk("RDEN DE TRABAJO", categoryFont); Chunk c2 = new Chunk("\n\n\nCentro de Formacin SATCAR6\n" + "Calle Artes Grficas n1 Nave 12 A\n" + "Pinto (28320), Madrid", smallFont); Chunk c3 = new Chunk("Datos del Cliente", smallBold); // Chunk c4 = new Chunk("Nombre: "+cliente.getRazonSocial(),smallBold); // Chunk c5 = new Chunk("Poblacin: "+cliente.getPoblacion(),smallBold); // Chunk c6 = new Chunk("Provincia: "+cliente.getProvincia(),smallBold); // Chunk c7 = new Chunk("Cdigo Postal: "+cliente.getCp(),smallBold); // Chunk c8 = new Chunk("Num Telfono: Pepito"+cliente.getTlf1(),smallBold); Chunk c4 = new Chunk("Nombre: Jesus Eduardo Garcia Toril", smallBold); Chunk c5 = new Chunk("Poblacin: Pinto", smallBold); Chunk c6 = new Chunk("Provincia: Madrid", smallBold); Chunk c7 = new Chunk("Cdigo Postal: 28320", smallBold); Chunk c8 = new Chunk("Num Telfono: 659408182", smallBold); Paragraph parrafo = new Paragraph(chunk); Paragraph p2 = new Paragraph(c2); Paragraph p3 = new Paragraph(c3); Phrase ph1 = new Phrase(c4); Phrase ph2 = new Phrase(c5); Phrase ph3 = new Phrase(c6); Phrase ph4 = new Phrase(c7); Phrase ph5 = new Phrase(c8); // Let's create de first Chapter (Creemos el primer captulo) // We add an image (Aadimos una imagen) Image image; try { parrafo.setAlignment(Element.ALIGN_CENTER); image = Image.getInstance(iTextExampleImage); image.setAbsolutePosition(0, 750); p2.setAlignment(Element.ALIGN_LEFT); document.add(parrafo); document.add(image); document.add(p2); document.add(p3); document.add(ph1); document.add(ph2); document.add(ph3); document.add(ph4); document.add(ph5); } catch (BadElementException ex) { System.out.println("Image BadElementException" + ex); } // Second page - some elements // Segunda pgina - Algunos elementos // List by iText (listas por iText) String text = "test 1 2 3 "; for (int i = 0; i < 5; i++) { text = text + text; } List list = new List(List.UNORDERED); ListItem item = new ListItem(text); item.setAlignment(Element.ALIGN_JUSTIFIED); list.add(item); text = "a b c align "; for (int i = 0; i < 5; i++) { text = text + text; } item = new ListItem(text); item.setAlignment(Element.ALIGN_JUSTIFIED); list.add(item); text = "supercalifragilisticexpialidocious "; for (int i = 0; i < 3; i++) { text = text + text; } item = new ListItem(text); item.setAlignment(Element.ALIGN_JUSTIFIED); list.add(item); // How to use PdfPTable // Utilizacin de PdfPTable // We use various elements to add title and subtitle // Usamos varios elementos para aadir ttulo y subttulo Anchor anchor = new Anchor("Table export to PDF (Exportamos la tabla a PDF)", categoryFont); anchor.setName("Table export to PDF (Exportamos la tabla a PDF)"); Chapter chapTitle = new Chapter(new Paragraph(anchor), 1); Paragraph paragraph = new Paragraph("Do it by Xules (Realizado por Xules)", subcategoryFont); Section paragraphMore = chapTitle.addSection(paragraph); paragraphMore.add(new Paragraph("This is a simple example (Este es un ejemplo sencillo)")); Integer numColumns = 6; Integer numRows = 120; // We create the table (Creamos la tabla). PdfPTable table = new PdfPTable(numColumns); // Now we fill the PDF table // Ahora llenamos la tabla del PDF PdfPCell columnHeader; // Fill table rows (rellenamos las filas de la tabla). for (int column = 0; column < numColumns; column++) { columnHeader = new PdfPCell(new Phrase("COL " + column)); columnHeader.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(columnHeader); } table.setHeaderRows(1); // Fill table rows (rellenamos las filas de la tabla). for (int row = 0; row < numRows; row++) { for (int column = 0; column < numColumns; column++) { table.addCell("Row " + row + " - Col" + column); } } // We add the table (Aadimos la tabla) paragraphMore.add(table); // We add the paragraph with the table (Aadimos el elemento con la tabla). document.add(chapTitle); document.close(); System.out.println("Your PDF file has been generated!(Se ha generado tu hoja PDF!"); } catch (DocumentException documentException) { System.out.println( "The file not exists (Se ha producido un error al generar un documento): " + documentException); } }
From source file:controller.PlanController.java
public Document PrintPressed(String Path) throws DocumentException, IOException { // step 1//from w w w.ja v a2 s .co m Document document = new Document(); // step 2 PdfWriter.getInstance(document, new FileOutputStream(Path)); // step 3 document.open(); // step 4 PdfPTable tablaDatosPlan = new PdfPTable(2); tablaDatosPlan.setWidthPercentage(100); if (!Team.getText().isEmpty()) { PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Team") + ":" + Team.getText())); cell1.setBorderColor(BaseColor.WHITE); tablaDatosPlan.addCell(cell1); } if (!Season.getText().isEmpty()) { PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Season") + ":" + Season.getText())); cell1.setBorderColor(BaseColor.WHITE); tablaDatosPlan.addCell(cell1); } if (!Date.getText().isEmpty()) { PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Date") + ":" + Date.getText())); cell1.setBorderColor(BaseColor.WHITE); tablaDatosPlan.addCell(cell1); } if (!Players.getText().isEmpty()) { PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Players") + ":" + Players.getText())); cell1.setBorderColor(BaseColor.WHITE); tablaDatosPlan.addCell(cell1); } if (!Start.getText().isEmpty()) { PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Start") + ":" + Start.getText())); cell1.setBorderColor(BaseColor.WHITE); tablaDatosPlan.addCell(cell1); } if (!End.getText().isEmpty()) { PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("End") + ":" + End.getText())); cell1.setBorderColor(BaseColor.WHITE); tablaDatosPlan.addCell(cell1); } if (!Place.getText().isEmpty()) { PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Place") + ":" + Place.getText())); cell1.setBorderColor(BaseColor.WHITE); tablaDatosPlan.addCell(cell1); } if (!Equipment.getText().isEmpty()) { PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Equipment") + ":" + Equipment.getText())); cell1.setBorderColor(BaseColor.WHITE); tablaDatosPlan.addCell(cell1); } document.add(tablaDatosPlan); document.add(new Phrase("\n")); document.add(new Phrase("\n")); PdfPTable tablaEjercicios = new PdfPTable(4); tablaEjercicios.setHeaderRows(contadorlineas); tablaEjercicios.addCell(messages.getString("Start")); tablaEjercicios.addCell(messages.getString("End")); tablaEjercicios.addCell(messages.getString("Drill")); tablaEjercicios.addCell(messages.getString("Notes")); int cont = 0; for (int aw = 4; aw < contadorlineas + 4; aw++) { tablaEjercicios.addCell(starColumn.getCellData(cont)); tablaEjercicios.addCell(endColumn.getCellData(cont)); tablaEjercicios.addCell(drillColumn.getCellData(cont)); tablaEjercicios.addCell(notesColumn.getCellData(cont)); cont++; } document.add(tablaEjercicios); int contadorListado = 0, contadorRecorrer = 0; if (checkboxDrills.isSelected()) { while (contadorListado < planData.size()) { contadorRecorrer = 0; while (contadorRecorrer < playData.size()) { System.out.println("Busco el ejercicio " + drillColumn.getCellData(contadorListado)); if (drillColumn.getCellData(contadorListado) .contains(playData.get(contadorRecorrer).getNombreJugada())) { int contador = 1; System.out.println("Ejercicio encontrado"); document.add(new Paragraph( messages.getString("Drill") + " " + drillColumn.getCellData(contadorListado))); while (contador < playData.get(contadorRecorrer).getContadorJugada() + 1) { document.add(new Paragraph(messages.getString("Diagram") + " " + contador)); document.add(new Paragraph(" ")); Image image2 = Image.getInstance(playData.get(contadorRecorrer).getNombreJugada() + "-" + playData.get(contadorRecorrer).getTipoJugada() + "-" + playData.get(contadorRecorrer).getSubtipoJugada() + "_" + contador); image2.scalePercent(50); PdfPTable table1 = new PdfPTable(2); table1.addCell(image2); table1.addCell( textPdf.textPdf(contador, playData.get(contadorRecorrer).getDescripcionJugada(), playData.get(contadorRecorrer).getContadorJugada())); document.add(table1); contador++; } } contadorRecorrer++; } contadorListado++; } } // step 5 document.close(); return document; }
From source file:crearpdf.CrearPDF.java
private void crearReportePDForacle(String select) throws Exception { Class.forName("oracle.jdbc.OracleDriver"); //Invocamos el Driver de Oracle Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/xe", "willson"/*usuario*/, "123456"/*contrasea*/); //Creamos la conexion para acceder a la base de datos Statement stmt = con.createStatement(); ResultSet resultados = stmt.executeQuery(select); //Hacemos el select de la info que extraeremos de la base de datos Document reportePDF = new Document(PageSize.LETTER, 88, 88, 80, 15); //Creamos un nuevo Documento usando la libreria itextpdf importada. PdfWriter.getInstance(reportePDF, new FileOutputStream("REPORTE.pdf"));//Instanciamos y creamos el archivo reportePDF.open(); //Abrimos el archivo creado arriba. Paragraph parrafo = new Paragraph("Reporte del dia"); parrafo.add("Este es el repote que nos da los datos"); parrafo.setAlignment(Element.ALIGN_CENTER); PdfPTable Treportes = new PdfPTable(5);//Aqui asignamos el numero de columnas que tendra la tabla, en este casi 5. PdfPCell celdas_tabla;//Creamos las celdas que seran llenadas con los datos extraidos //Agregamos los titulos de cada Columna Treportes.addCell("ID"); Treportes.addCell("Nombre"); Treportes.addCell("Edad"); Treportes.addCell("Mes Nacimiento"); Treportes.addCell("Universidad"); //ciclo para empezar a aadir los datos de la base de datos a las celdas correspondientes en el PDF ///System.out.println("Llenando pdf"); while (resultados.next()) { String id = resultados.getString("ID"); celdas_tabla = new PdfPCell(new Phrase(id)); Treportes.addCell(celdas_tabla); String nombre = resultados.getString("NOMBRE"); celdas_tabla = new PdfPCell(new Phrase(nombre)); Treportes.addCell(celdas_tabla); String edad = resultados.getString("EDAD"); celdas_tabla = new PdfPCell(new Phrase(edad)); Treportes.addCell(celdas_tabla); String nacimiento = resultados.getString("MES_NACIMIENTO"); celdas_tabla = new PdfPCell(new Phrase(nacimiento)); Treportes.addCell(celdas_tabla); String universidad = resultados.getString("UNIVERSIDAD"); celdas_tabla = new PdfPCell(new Phrase(universidad)); Treportes.addCell(celdas_tabla); //System.out.println(id+" "+nombre+" "+edad); }/* w w w . j a v a 2s .c o m*/ // System.out.println("Listo!"); parrafo.add(Treportes); reportePDF.add(parrafo); //reportePDF.add(Treportes); //Insertamos los datos de la tabla en el PDF. reportePDF.close(); //Cerramos el archivo PDF una vez completado //Cerrar todas las conexiones resultados.close(); stmt.close(); con.close(); }
From source file:crearpdf.CrearPDF.java
public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.OracleDriver"); //Invocamos el Driver de Oracle Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/xe", "willson"/*usuario*/, "123456"/*contrasea*/); //Creamos la conexion para acceder a la base de datos Statement stmt = con.createStatement(); ResultSet resultados = stmt// w w w .j av a 2 s .c om .executeQuery("SELECT ID, NOMBRE, EDAD, MES_NACIMIENTO, UNIVERSIDAD FROM PERSONAS"); //Hacemos el select de la info que extraeremos de la base de datos Document reportePDF = new Document(PageSize.B4, 88, 88, 80, 15); //Creamos un nuevo Documento usando la libreria itextpdf importada. PdfWriter.getInstance(reportePDF, new FileOutputStream("REPORTE.pdf"));//Instanciamos y creamos el archivo reportePDF.open(); //Abrimos el archivo creado arriba. Paragraph parrafo = new Paragraph("Reporte del dia"); parrafo.setAlignment(Element.ALIGN_CENTER); PdfPTable Treportes = new PdfPTable(5);//Aqui asignamos el numero de columnas que tendra la tabla, en este casi 5. PdfPCell celdas_tabla;//Creamos las celdas que seran llenadas con los datos extraidos //Agregamos los titulos de cada Columna Treportes.addCell("ID"); Treportes.addCell("Nombre"); Treportes.addCell("Edad"); Treportes.addCell("Mes Nacimiento"); Treportes.addCell("Universidad"); //ciclo para empezar a aadir los datos de la base de datos a las celdas correspondientes en el PDF System.out.println("Llenando pdf"); while (resultados.next()) { String id = resultados.getString("ID"); celdas_tabla = new PdfPCell(new Phrase(id)); Treportes.addCell(celdas_tabla); String nombre = resultados.getString("NOMBRE"); celdas_tabla = new PdfPCell(new Phrase(nombre)); Treportes.addCell(celdas_tabla); String edad = resultados.getString("EDAD"); celdas_tabla = new PdfPCell(new Phrase(edad)); Treportes.addCell(celdas_tabla); String nacimiento = resultados.getString("MES_NACIMIENTO"); celdas_tabla = new PdfPCell(new Phrase(nacimiento)); Treportes.addCell(celdas_tabla); String universidad = resultados.getString("UNIVERSIDAD"); celdas_tabla = new PdfPCell(new Phrase(universidad)); Treportes.addCell(celdas_tabla); System.out.println(id + " " + nombre + " " + edad); } System.out.println("Listo!"); reportePDF.add(parrafo); reportePDF.add(Treportes); //Insertamos los datos de la tabla en el PDF. reportePDF.close(); //Cerramos el archivo PDF una vez completado //Cerrar todas las conexiones resultados.close(); stmt.close(); con.close(); }
From source file:CTD.planer2.util.ExportToPdf.java
/** * We create the table we want to add to our pdf * //from w ww .j ava 2 s. c o m * @param subCatPart * @throws BadElementException */ private static void createTable(Section subCatPart) throws BadElementException { // Get the number of days per Week from the Settings int daysPerWeek = App.theSettings.getDaysPerWeek(); PdfPTable table = new PdfPTable(daysPerWeek + 1); String[] WeekDay = { "Zeit", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag" }; for (int i = 0; i < daysPerWeek + 1; i++) { PdfPCell c1 = new PdfPCell(new Phrase(WeekDay[i])); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); if (i == daysPerWeek) { table.setHeaderRows(1); } } // We take the first day to get the number of units and so the number of // times we have to run this. for (int j = 0; j < planExport.getWeekday(1).size(); j++) { // For each day available, we run this loop once. for (int k = 1; k < daysPerWeek + 1; k++) { // Read one unit per day and write it in a new cell of the pdf List<Units> tmp = planExport.getWeekday(k); // If it's the first day, we also want a first cell per line // containing the time this unit starts if (k == 1) { SimpleDateFormat df = new SimpleDateFormat("HH:mm"); String time = df.format(tmp.get(j).getTime()); table.addCell(time); String room = " "; // Check whether a room is given if (tmp.get(j).getRooms().size() < 1) { room = " "; } else { room = tmp.get(j).getRooms().get(0).toString(); } String teacher = " "; if (tmp.get(j).getPerson() == null) { teacher = " "; } else { teacher = tmp.get(j).toString(); } String subject = " "; if (tmp.get(j).getSubjects().size() < 1) { subject = " "; } else { subject = tmp.get(j).getSubjects().get(0).toString(); } // If the plan is for a room, we just need the time and the // teachers name if (CPlaner.selRoom != null) { table.addCell(teacher); // If the plan is for a class, we need the time, the // room and the teachers name } else if (CPlaner.selClass != null) { table.addCell(room + ", " + teacher); // For a teachers plan, we need the room and the subject } else { table.addCell(room + ", " + subject); } } else { // If it's not the first day, we don't need to print the // start time again String room = " "; // Check again whether a room is given if (tmp.get(j).getRooms().size() < 1) { room = " "; } else { room = tmp.get(j).getRooms().get(0).toString(); } String teacher = " "; if (tmp.get(j).getPerson() == null) { teacher = " "; } else { teacher = tmp.get(j).toString(); } String subject = " "; if (tmp.get(j).getSubjects().size() < 1) { subject = " "; } else { subject = tmp.get(j).getSubjects().get(0).toString(); } // If the plan is for a room, we just need the time and the // teachers name if (CPlaner.selRoom != null) { table.addCell(teacher); // If the plan is for a class, we need the time, the // room and the teachers name } else if (CPlaner.selClass != null) { table.addCell(room + ", " + teacher); // For a teachers plan, we need the room and the subject } else { table.addCell(room + ", " + subject); } } } } // Add the whole table we've just created to the pdf file subCatPart.add(table); }
From source file:CTD.planer2.util.ExportToPdf.java
/** * We create the table we want to add to our pdf * /*w w w. java2s . c o m*/ * @param subCatPart * @throws BadElementException */ private static void createTable(Section subCatPart, Room room) throws BadElementException { // Get the number of days per Week from the Settings int daysPerWeek = App.theSettings.getDaysPerWeek(); PdfPTable table = new PdfPTable(daysPerWeek + 1); String[] WeekDay = { "Zeit", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag" }; for (int i = 0; i < daysPerWeek + 1; i++) { PdfPCell c1 = new PdfPCell(new Phrase(WeekDay[i])); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); if (i == daysPerWeek) { table.setHeaderRows(1); } } double calc = 0; // Simplify the Date since we just need the time SimpleDateFormat df = new SimpleDateFormat("HH:mm"); Date start = null; Date uSize = null; try { start = df.parse(App.theSettings.getStartingTimeH() + ":" + App.theSettings.getStartingTimeM()); uSize = new Date(MINUTES.toMillis(App.theSettings.getUnitsSize())); } catch (ParseException e) { } // We take the first day to get the number of units and so the number of // times we have to run this. for (int j = 0; j < Tools.calcRows(); j++) { calc = j == 0 ? start.getTime() : (calc + (uSize.getTime())); // For each day available, we run this loop once. for (int k = 1; k < daysPerWeek + 1; k++) { Units u = room.getUnitByRowCol(k, j); // If it's the first day, we also want a first cell per line // containing the time this unit starts if (k == 1) { table.addCell(df.format(calc)); // Check whether a room is given String teacher = " "; if (u != null) { teacher = u.toString(); } table.addCell(teacher); } else { // If it's not the first day, we don't need to print the // start time again String teacher = " "; if (u != null) { teacher = u.toString(); } table.addCell(teacher); } } } // Add the whole table we've just created to the pdf file subCatPart.add(table); }
From source file:CTD.planer2.util.ExportToPdf.java
private static void createDayTable(Section subCatPart) throws BadElementException { List<Person> personList = App.theSemester.getPersonList(); PdfPTable table = new PdfPTable(personList.size() + 1); PdfPCell c1 = new PdfPCell(new Phrase(" ")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);/*from w w w .j av a 2 s . c o m*/ for (Person p : personList) { c1 = new PdfPCell(new Phrase(p.toString())); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); int k = 1; // We take the first person to get the number of units and so the // number // of // times we have to run this. for (int j = 1; j < p.getEntity().size(); j++) { // For each person available, we run this loop once. List<Units> tmp = p.getEntity(); if (k == 1) { SimpleDateFormat df = new SimpleDateFormat("HH:mm"); String time = df.format(tmp.get(j).getTime()); table.addCell(time); String classes = " "; // Check whether a class is given if (tmp.get(j).getClasses().size() < 1) { classes = " "; } else { classes = tmp.get(j).getClasses().get(0).toString(); } table.addCell(classes); } else { // If it's not the first day, we don't need to print the // start time again String classes = " "; // Check whether a class is given if (tmp.get(j).getClasses().size() < 1) { classes = " "; } else { classes = tmp.get(j).getClasses().get(0).toString(); } table.addCell(classes); } k = k + 1; } } // Add the whole table we've just created to the pdf file subCatPart.add(table); }
From source file:cz.zcu.kiv.eegdatabase.logic.pdf.ReservationPDF.java
License:Apache License
public static PdfPTable formatReservation(Reservation reservation) { int padding = 5; GregorianCalendar created = new GregorianCalendar(); created.setTime(reservation.getCreationTime()); GregorianCalendar startTime = new GregorianCalendar(); startTime.setTime(reservation.getStartTime()); GregorianCalendar endTime = new GregorianCalendar(); endTime.setTime(reservation.getEndTime()); String personName = BookingRoomUtils.formatPersonName(reservation.getPerson()); Font title = FontFactory.getFont("Trebuchet MS", "utf-8", 15, Font.BOLD, new BaseColor(59, 70, 00)); Font header = FontFactory.getFont(FontFactory.TIMES_BOLD, 13, Font.BOLD, BaseColor.BLACK); Font value = FontFactory.getFont(FontFactory.TIMES, 13); PdfPTable table = new PdfPTable(2); PdfPCell cell;//from w w w . j a v a2 s. c o m Phrase phrase; phrase = new Phrase("Reservation by " + personName); phrase.setFont(title); cell = new PdfPCell(phrase); cell.setColspan(2); cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthTop(1); cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); cell.setPadding(padding); cell.setPaddingBottom(5); table.addCell(cell); phrase = new Phrase("Date: "); phrase.setFont(header); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthLeft(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase(BookingRoomUtils.getDate(startTime)); phrase.setFont(value); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthRight(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase("Start: "); phrase.setFont(header); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthLeft(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase(BookingRoomUtils.getHoursAndMinutes(startTime)); phrase.setFont(value); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthRight(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase("End: "); phrase.setFont(header); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthLeft(1); cell.setBorderWidthBottom(1); cell.setPadding(padding); table.addCell(cell); phrase = new Phrase(BookingRoomUtils.getHoursAndMinutes(endTime)); phrase.setFont(value); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setBorderWidthRight(1); cell.setBorderWidthBottom(1); cell.setPadding(padding); table.addCell(cell); table.setSpacingBefore(10); table.setSpacingAfter(10); return table; }
From source file:dbms.Bills1Controller.java
@FXML void OnMouseClick(ActionEvent event) throws ClassNotFoundException, SQLException, FileNotFoundException, DocumentException { int c = check(phone_no.getText()); int c1 = phone_no.getText().length(); String s1 = product_id.getText(); String s3 = cb1.getSelectionModel().getSelectedItem(); String s7 = cb2.getSelectionModel().getSelectedItem(); int s8 = cb3.getSelectionModel().getSelectedItem(); String s2 = cust_name.getText(); String s4 = address.getText(); String s6 = date.getValue().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); String s5 = phone_no.getText(); String s10 = total.getText(); String s11 = cb4.getSelectionModel().getSelectedItem(); String s12 = payment.getText(); int to = Integer.parseInt(s10); if (c == 0 || c1 != 10 || total.getText().equals("") || cust_name.getText().equals("") || address.getText().equals("") || payment.getText().equals("")) { JOptionPane.showMessageDialog(null, "Something is wrong"); } else {/*from w ww . java 2 s.c o m*/ try { Class.forName("com.mysql.jdbc.Driver"); java.sql.Connection con = DriverManager .getConnection("jdbc:mysql://localhost/dbms?user=root&password=india123"); String str1 = "insert into sold_item values(?,?,?,?,?,?,?,?,?,?)"; // System.out.println(str1); java.sql.PreparedStatement stmt1 = con.prepareStatement(str1); stmt1.setString(1, s1); stmt1.setString(2, s3); stmt1.setString(3, s7); stmt1.setInt(4, s8); stmt1.setString(5, s2); stmt1.setString(6, s4); stmt1.setString(7, s5); stmt1.setString(8, s6); stmt1.setInt(9, to); stmt1.setString(10, s11); // ResultSet rs1 = stmt1.executeQuery(); stmt1.executeUpdate(); // con.close(); JOptionPane.showMessageDialog(null, "Bill Generated"); String str6 = "select * from sold_item where billid= '" + s1 + "'"; PreparedStatement stmt2 = con.prepareStatement(str6); ResultSet rs = stmt2.executeQuery(str6); Document my_bill = new Document(); PdfWriter.getInstance(my_bill, new FileOutputStream(s1 + ".pdf")); my_bill.open(); Font f1 = new Font(FontFamily.TIMES_ROMAN, 20.0f, Font.BOLD, BaseColor.BLACK); Paragraph p2 = new Paragraph("XYZ Electronics", f1); p2.setAlignment(Paragraph.ALIGN_CENTER); my_bill.add(p2); //my_bill.add(Chunk.NEWLINE); Paragraph p3 = new Paragraph("BILL", f1); p3.setAlignment(Paragraph.ALIGN_CENTER); my_bill.add(p3); my_bill.add(Chunk.NEWLINE); PdfPTable bill_table = new PdfPTable(2); PdfPCell table_cell; while (rs.next()) { bill_table.addCell("Bill ID"); String dept_id = rs.getString(1); table_cell = new PdfPCell(new Phrase(dept_id)); bill_table.addCell(table_cell); bill_table.addCell("Product Type"); String dept_name = rs.getString(2); table_cell = new PdfPCell(new Phrase(dept_name)); bill_table.addCell(table_cell); bill_table.addCell("Product name"); String dept_pname = rs.getString(3); table_cell = new PdfPCell(new Phrase(dept_pname)); bill_table.addCell(table_cell); bill_table.addCell("Quantity"); int dept_quan = rs.getInt(4); table_cell = new PdfPCell(new Phrase("" + dept_quan)); bill_table.addCell(table_cell); bill_table.addCell("Customer Name"); String manager_id = rs.getString(5); table_cell = new PdfPCell(new Phrase(manager_id)); bill_table.addCell(table_cell); bill_table.addCell("Address"); String location_id = rs.getString(6); table_cell = new PdfPCell(new Phrase(location_id)); bill_table.addCell(table_cell); bill_table.addCell("Phone Number"); String s = rs.getString(7); table_cell = new PdfPCell(new Phrase(s)); bill_table.addCell(table_cell); bill_table.addCell("DATE"); String ss = rs.getString(8); table_cell = new PdfPCell(new Phrase(ss)); bill_table.addCell(table_cell); bill_table.addCell("Total"); int dept_total = rs.getInt(9); table_cell = new PdfPCell(new Phrase("Rs. " + dept_total)); bill_table.addCell(table_cell); } my_bill.add(bill_table); my_bill.add(Chunk.NEWLINE); Font f2 = new Font(FontFamily.TIMES_ROMAN, 20.0f, Font.UNDERLINE, BaseColor.BLACK); Paragraph p4 = new Paragraph("Manager Signature", f1); p4.setAlignment(Paragraph.ALIGN_RIGHT); my_bill.add(p4); my_bill.close(); String spl[] = s7.split("-"); String strr = "select Quantity from " + s3 + " where Company = '" + spl[0] + "' and ProductName = '" + spl[1] + "'"; PreparedStatement stmt3 = con.prepareStatement(strr); ResultSet rs3 = stmt3.executeQuery(); rs3.next(); int f = rs3.getInt(1); f = f - s8; String strr1 = "Update " + s3 + " set Quantity = " + f + " where Company = '" + spl[0] + "' and ProductName = '" + spl[1] + "' "; PreparedStatement stmt4 = con.prepareStatement(strr1); stmt4.executeUpdate(); String strr2 = "insert into payment values(?,?)"; PreparedStatement stmt5 = con.prepareStatement(strr2); stmt5.setString(1, product_id.getText()); stmt5.setString(2, payment.getText()); stmt5.executeUpdate(); rs.close(); stmt2.close(); con.close(); product_id.setText(""); // prdct_name.setText(""); cust_name.setText(""); address.setText(""); phone_no.setText(""); } catch (DocumentException | HeadlessException | FileNotFoundException | ClassNotFoundException | SQLException e) { JOptionPane.showMessageDialog(null, e.getMessage()); } } }