List of usage examples for com.itextpdf.text.pdf PdfPTable PdfPTable
public PdfPTable(final PdfPTable table)
PdfPTable
. From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
/** * Dado un resultSet obtenido de una consulta, esta funcin convierte los datos * internos de este en una tabla que puede ser insertada en un Document de iText * esta PdfPTable tiene en su primera linea los nombres de las columnas del ResultSet * @param entrada ResultSet El resultado de una consulta a la base de datos * @return una PdfPTable para insertar en un documento de iText * @see com.itextpdf.text.pdf.PdfPTable; * @see java.sql.ResultSet;//from w w w. j a v a2 s . c om */ static public PdfPTable resultSetToTable(ResultSet entrada) { PdfPTable salida = null; try { ResultSetMetaData rsmd = entrada.getMetaData(); salida = new PdfPTable(rsmd.getColumnCount()); for (int i = 1; i <= rsmd.getColumnCount(); i++) { salida.addCell(rsmd.getColumnName(i)); } salida.setHeaderRows(1); while (entrada.next()) { for (int i = 1; i <= rsmd.getColumnCount(); i++) { salida.addCell(entrada.getString(i)); } } } catch (java.sql.SQLException sqlex) { System.err.println(sqlex); } return salida; }
From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
static public PdfPTable plainArrayListToPdfPTable(ArrayList<String> entrada, int columns) { PdfPTable salida = new PdfPTable(columns); for (int i = 0; i < columns; i++) { salida.addCell(entrada.get(i));//from w w w . j a va 2s . c o m } salida.setHeaderRows(1); for (int i = columns; i < entrada.size(); i++) { salida.addCell(entrada.get(i)); } return salida; }
From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
static public ArrayList<PdfPTable> resultSetsToTables(ArrayList<ResultSet> entrada) { ArrayList<PdfPTable> Salida = new ArrayList<PdfPTable>(10); PdfPTable salida = null;/*w w w . j a v a 2s . com*/ for (int j = 0; j < entrada.size(); j++) { try { ResultSetMetaData rsmd = entrada.get(j).getMetaData(); salida = new PdfPTable(rsmd.getColumnCount()); for (int i = 1; i <= rsmd.getColumnCount(); i++) { salida.addCell(rsmd.getColumnName(i)); } salida.setHeaderRows(1); while (entrada.get(j).next()) { for (int i = 1; i <= rsmd.getColumnCount(); i++) { salida.addCell(entrada.get(j).getString(i)); } } } catch (java.sql.SQLException sqlex) { System.err.println(sqlex); } Salida.add(salida); } return Salida; }
From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
/** * Esta funcin convierte un arrayList en una PdfPTable y, agrega una columna * de estadisticas a esta. Funcionar si el arrayList tiene en su ultima columna * numeros/*www . jav a 2 s . co m*/ * @param entrada Matriz con los datos estadisticos de la base de datos * @param total La suma de todos los datos de la ultima columna * @param rows El numero de columnas que se mostrarn en la PdfPTable * @return PdfPTable Contiene los datos del ArrayList ms los porcentajes. */ static public PdfPTable arrayListToStatisticTable(ArrayList<ArrayList<String>> entrada, int total, int rows) { PdfPTable salida = null; salida = new PdfPTable(entrada.get(0).size() + 1); for (int i = 0; i < entrada.get(0).size(); i++) { salida.addCell(entrada.get(0).get(i)); } salida.addCell("Porcentaje"); salida.setHeaderRows(1); int counter = 0; for (int j = 1; j < entrada.size() && counter < rows; j++) { for (int i = 0; i < entrada.get(j).size(); i++) { salida.addCell(entrada.get(j).get(i)); if (i == entrada.get(j).size() - 1) { int porcentaje = (int) (Integer.parseInt(entrada.get(j).get(i)) * 100) / total; salida.addCell(porcentaje + "%"); } } counter++; } if (entrada.size() - 1 > rows) { int otros = 0, otrospor; for (int i = counter; i < entrada.size(); i++) { otros += Integer.parseInt(entrada.get(i).get(entrada.get(i).size() - 1)); } otrospor = otros * 100; otrospor /= total; salida.addCell("-"); salida.addCell("Otros"); salida.addCell(otros + ""); salida.addCell(otrospor + "%"); } return salida; }
From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
static public void createDinamicPdf(String path, String titulo, String encabezado, ArrayList<Element> contenido) { Document document = new Document(); //step 2// w ww . j a v a 2s .c o m try { PdfWriter.getInstance(document, new FileOutputStream(path)); Font myFontTitle = new Font(); myFontTitle.setFamily("Arial"); myFontTitle.setStyle(Font.BOLD); myFontTitle.setSize(12); Font Univallef = new Font(); Univallef.setColor(BaseColor.RED); Univallef.setFamily("Arial"); Univallef.setSize(18); Image header = Image .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png")); header.setAlignment(Image.ALIGN_CENTER); header.scaleToFit(50, 75); Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef); Univalle.setAlignment(Paragraph.ALIGN_CENTER); Paragraph pTitulo = new Paragraph(titulo, myFontTitle); pTitulo.setAlignment(Paragraph.ALIGN_CENTER); Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle); biblioteca.setAlignment(Paragraph.ALIGN_CENTER); Paragraph developers = new Paragraph( "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle); developers.setAlignment(Paragraph.ALIGN_CENTER); Paragraph Fecha = new Paragraph("Fecha y Hora de Reporte: " + fecha, myFontTitle); //Paragraph Introduccion = new Paragraph("Reporte de usuarios registrados"); document.open(); // step 4 document.add(header); document.add(new Paragraph("\r\n")); document.add(Univalle); document.add(new Paragraph("\r\n")); document.add(pTitulo); document.add(new Paragraph("\r\n")); document.add(biblioteca); document.add(new Paragraph("\r\n")); document.add(developers); document.add(new Paragraph("\r\n")); document.add(Fecha); document.add(new Paragraph("\r\n")); // document.add(Introduccion); document.add(new Paragraph("\r\n")); for (int i = 0; i < contenido.size(); i++) { document.add(contenido.get(i).getClass().equals(new PdfPTable(2).getClass()) ? (PdfPTable) contenido.get(i) : contenido.get(i)); } // step 5 document.close(); } catch (DocumentException de) { System.err.println(de); } catch (IOException ioex) { System.err.println(ioex); } }
From source file:billerfx.FXMLBillController.java
File generatePDF() { File fi = null;/*ww w . ja v a 2 s . c o m*/ try { Stage gg = ((Stage) imv.getParent().getScene().getWindow()); fi = File.createTempFile("billerfx_" + gg.getTitle(), ".pdf"); fi.deleteOnExit(); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(fi)); Rectangle r = new RectangleReadOnly(207, 575); document.setPageSize(r); document.setMargins(15, 15, 0, 0); document.open(); Font fontbold = FontFactory.getFont("Times-Roman", 10, Font.NORMAL); Font fontbold2 = FontFactory.getFont("Times-Roman", 9, Font.NORMAL); String[] ll = Database.getCurrentSettings(); String ss = "-----------------------------------------------------\n"; ss += ll[0] + "\nAddress: " + ll[1] + "\nPhone: " + ll[2] + "\n"; String kk = Calendar.getInstance().get(Calendar.AM_PM) == Calendar.AM ? "AM" : (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.PM ? "PM" : ""); ss += Calendar.getInstance().get(Calendar.DATE) + "/" + (1 + Calendar.getInstance().get(Calendar.MONTH)) + "/" + Calendar.getInstance().get(Calendar.YEAR) + " at " + Calendar.getInstance().get(Calendar.HOUR) + ":" + Calendar.getInstance().get(Calendar.MINUTE) + " " + kk + "\n"; ss += "Table No. " + c.getText() + " Bill No. " + a.getText() + "\n"; ss += "-----------------------------------------------------\n"; Paragraph para = new Paragraph(ss, fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); float[] columnWidths = { 3f, 1f }; table.setWidths(columnWidths); PdfPCell defaultCell = table.getDefaultCell(); defaultCell.setBorder(PdfPCell.NO_BORDER); ObservableList ob = map.get(Integer.parseInt(gg.getTitle())); for (int i = 0; i < ob.size(); i++) { Item2 ii = (Item2) ob.get(i); String s1 = ii.getQuantity() + " x " + ii.getName(); String s2 = "Rs. " + ii.getTotal(); Paragraph para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); Paragraph para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); PdfPCell cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } document.add(table); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(columnWidths); defaultCell = table.getDefaultCell(); defaultCell.setBorder(PdfPCell.NO_BORDER); String s1 = "Total:"; String s2 = "Rs. " + h.getText(); Paragraph para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); Paragraph para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); PdfPCell cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); if (Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()) > 0.0) { s1 = "Discount:"; s2 = "Rs. " + BillerFX.df.format(Double.parseDouble(h.getText()) - Double.parseDouble(i.getText())); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } if (ll[7].equals("1")) { s1 = ll[3]; s2 = "Rs. " + k.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } if (ll[8].equals("1")) { s1 = ll[4]; s2 = "Rs. " + l.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } s1 = "Grand Total:"; s2 = "Rs. " + m.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); document.add(table); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); fontbold2 = FontFactory.getFont("Times-Roman", 8, Font.NORMAL); para = new Paragraph( "Thank You.\nThis invoice was created using BillerFX.\n (BillerFX Contact: ayushmaanbhav1008@gmail.com)\n", fontbold2); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); document.close(); } catch (Exception mm) { } return fi; }
From source file:bl.pdf.PDFFile.java
private PdfPTable getTable(EntityTableModel tModel) { String[] headers = tModel.getColumnNames(); PdfPTable table = new PdfPTable(headers.length); table.setHeaderRows(1);/*from ww w. j av a 2s . c om*/ table.setWidthPercentage(100); for (String header : headers) { PdfPCell c1 = new PdfPCell(new Phrase(header)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } ArrayList<DBEntity> entries = tModel.getEntries(); if (entries.isEmpty()) { PdfPCell c = new PdfPCell(new Phrase("Keine Eintrge vorhanden")); c.setHorizontalAlignment(Element.ALIGN_CENTER); c.setColspan(headers.length); table.addCell(c); return table; } for (DBEntity entry : entries) { for (String header : headers) { Method method; Object a; try { method = entry.getClass().getMethod("get" + header, new Class<?>[0]); a = method.invoke(entry, new Object[0]); table.addCell(String.valueOf(a)); } catch (NoSuchMethodException e) { e.printStackTrace(); table.addCell(new String("")); } catch (SecurityException e) { e.printStackTrace(); table.addCell(new String("")); } catch (IllegalAccessException e) { e.printStackTrace(); table.addCell(new String("")); } catch (IllegalArgumentException e) { e.printStackTrace(); table.addCell(new String("")); } catch (InvocationTargetException e) { e.printStackTrace(); table.addCell(new String("")); } } } return table; }
From source file:bl.pdf.PDFFile.java
private PdfPTable getRechnungszeileTable(Rechnung r) throws DALException { String[] headers;//from ww w .j a v a2 s. co m if (r instanceof Eingangsrechnung) { String[] h = { "Rechnungszeile", "Kommentar", "Steuersatz", "Betrag", "ohne Steuer" }; headers = h; } else { String[] h = { "Rechnungszeile", "Kommentar", "AngebotID", "Steuersatz", "Betrag", "ohne Steuer" }; headers = h; } PdfPTable table = new PdfPTable(headers.length); table.setHeaderRows(1); table.setWidthPercentage(100); for (String header : headers) { PdfPCell c1 = new PdfPCell(new Phrase(header)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } ArrayList<Rechnungszeile> rechnungszeilen = BL.getRechnungszeileListe(r.getRechnungID()); if (rechnungszeilen.isEmpty()) { PdfPCell c = new PdfPCell(new Phrase("Keine Rechnungszeilen vorhanden")); c.setHorizontalAlignment(Element.ALIGN_CENTER); if (r instanceof Ausgangsrechnung) { c.setColspan(6); } else { c.setColspan(5); } table.addCell(c); return table; } double summe = 0; double summeOhne = 0; for (Rechnungszeile rz : rechnungszeilen) { table.addCell(String.valueOf(rz.getRechnungszeileID())); table.addCell(String.valueOf(rz.getKommentar())); if (r instanceof Ausgangsrechnung) { table.addCell(String.valueOf(rz.getAngebotID())); } table.addCell(String.valueOf(rz.getSteuersatz())); table.addCell(String.valueOf(rz.getBetrag())); double betrag = rz.getBetrag(); double steuersatz = rz.getSteuersatz(); double betragOhne = betrag - (betrag / 100 * steuersatz); table.addCell(String.valueOf(betragOhne)); summe += rz.getBetrag(); summeOhne += betragOhne; } PdfPCell c = new PdfPCell(new Phrase("Summe")); c.setHorizontalAlignment(Element.ALIGN_RIGHT); if (r instanceof Ausgangsrechnung) { c.setColspan(4); } else { c.setColspan(3); } table.addCell(c); table.addCell(String.valueOf(summe)); table.addCell(String.valueOf(summeOhne)); return table; }
From source file:bl.pdf.PDFFile.java
private void createTable(Section subCatPart) throws BadElementException { PdfPTable table = new PdfPTable(3); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);/*from www .ja v a 2s . c o m*/ c1 = new PdfPCell(new Phrase("Table Header 2")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Table Header 3")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); table.addCell("1.0"); table.addCell("1.1"); table.addCell("1.2"); table.addCell("2.1"); table.addCell("2.2"); table.addCell("2.3"); subCatPart.add(table); }
From source file:bladwin.web.reg.regPDF.java
private PdfPTable genSport(customerRegBean a) { float[] widths2 = { 0.33f, 0.33f, 0.33f }; PdfPTable table = new PdfPTable(widths2); PdfPCell cell1 = new PdfPCell(), cell2 = new PdfPCell(), cell3 = new PdfPCell(); cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell2.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell3.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell1.setPhrase(pdfRptMgr.getRptFont("Shirt Size", true)); cell2.setPhrase(pdfRptMgr.getRptFont("Short Size", true)); cell3.setPhrase(pdfRptMgr.getRptFont("Warmup Suit Size", true)); table.addCell(cell1);/*from w ww. j a v a 2 s .co m*/ table.addCell(cell2); table.addCell(cell3); cell1.setPhrase(pdfRptMgr.getRptFont(a.getShirtSizeStr())); cell2.setPhrase(pdfRptMgr.getRptFont(a.getShortSideStr())); cell3.setPhrase(pdfRptMgr.getRptFont(a.getWarmupSuiteSizeStr())); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); return table; }