List of usage examples for com.itextpdf.text.pdf PdfPCell PdfPCell
public PdfPCell(PdfPCell cell)
PdfPCell
. From source file:bemyguest.controller.ValidationResevation.java
@FXML private void handleButtonValiderAction(ActionEvent event) throws FileNotFoundException, DocumentException { Resrevation e = tab_reservation.getSelectionModel().getSelectedItem(); if (e == null) { Alert alert = new Alert(Alert.AlertType.WARNING); alert.setTitle("Warning Dialog"); alert.setHeaderText(null);/*w w w .j a v a 2 s.c o m*/ alert.setContentText("selectionner un demande de reservation a traiter svp!"); alert.showAndWait(); LoadData(); setCellTable(); } else { Alert alert = new Alert(Alert.AlertType.CONFIRMATION); alert.setTitle("Confiramtion"); alert.setHeaderText(null); alert.setContentText("vous etes sur d'accepter cette demande de reservation"); Optional<ButtonType> answer = alert.showAndWait(); if (answer.get() == ButtonType.OK) { ResevationDAO dao = new ResevationDAO(); if (dao.ajouter_Reservation(e)) { LoadData(); setCellTable(); alert.setTitle("Success Dialog"); alert.setHeaderText(null); alert.setContentText("Demandes accepter avec success"); alert.showAndWait(); try { Document d = new Document(PageSize.A4.rotate()); PdfWriter.getInstance(d, new FileOutputStream(e.getUser().getNom() + "Facture.pdf")); d.open(); d.add(new Paragraph("BeMyGuest Facture :", FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED))); d.add(new Paragraph(new Date().toString())); d.add(new Paragraph( "-------------------------------------------------------------------------------------------------------------")); d.add(new Paragraph(" ")); d.add(new Paragraph(" ")); PdfPTable pdt = new PdfPTable(7); PdfPCell cell = new PdfPCell(new Paragraph("Composant de facture")); cell.setColspan(7); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.RED); pdt.addCell(cell); pdt.addCell(new Paragraph("Nom:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("Prenom:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("Date Debut:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("Date Fin:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("nbre chambre:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("nbre personne:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("Prix:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(e.getUserDemandant().getNom(), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(e.getUserDemandant().getPrenom(), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(e.getDateDebut().toString(), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(e.getDateFin().toString(), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(e.getDateDebut().toString()); int nb = e.getPropriete().getNbrChambre(); float pr = e.getPropriete().getPrix(); int nbp = e.getPropriete().getNbrVoyageur(); pdt.addCell(new Paragraph(Integer.toString(nb), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(Integer.toString(nbp), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(Float.toString(pr), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(Float.toString(pr)); d.add(pdt); d.close(); } catch (Exception b) { JOptionPane.showMessageDialog(null, b); } } else { alert.setTitle("Error Dialog"); alert.setHeaderText(null); alert.setContentText("Cette Propriete Reserver pendant cette date "); alert.showAndWait(); LoadData(); setCellTable(); } } else { LoadData(); setCellTable(); } } }
From source file:biblioteca.BibliotecaFXMLController.java
@FXML /// Arquivo - PDF - Tabela Alunos public void pdf() throws FileNotFoundException, DocumentException, IOException, SQLException { Document doc = null;/* w w w . j av a 2 s .co m*/ OutputStream os = null; try { contest conn = new contest(); //cria o documento tamanho A4, margens de 2,54cm doc = new Document(PageSize.A4); //cria a stream de sada os = new FileOutputStream("TabelaA.pdf"); //associa a stream de sada ao PdfWriter.getInstance(doc, os); //abre o documento doc.open(); //adiciona o texto ao PDF PdfPTable tabelaA = new PdfPTable(new float[] { 0.2f, 0.7f, 0.7f, 0.9f, 0.7f }); PdfPCell header = new PdfPCell(new Paragraph("Tabela de Alunos")); header.setColspan(5); tabelaA.addCell(header); tabelaA.addCell("ID"); tabelaA.addCell("Matrcula"); tabelaA.addCell("Nome"); tabelaA.addCell("C.P.F"); tabelaA.addCell("Telefone"); Statement stA = conn.conectar1().createStatement(); ResultSet rsa = stA.executeQuery("SELECT idAluno,matriculaAluno,nomeAluno,nCPF,Telefone FROM `Aluno`;"); while (rsa.next()) { Aluno a = new Aluno(0, 0, "", "", ""); a.setIdaluno(rsa.getInt("idAluno")); a.setMatricula(rsa.getInt("matriculaAluno")); a.setNoAluno(rsa.getString("nomeAluno")); a.setCpf(rsa.getString("nCPF")); a.setTelefone(rsa.getString("Telefone")); tabelaA.addCell(String.valueOf(a.getIdaluno())); tabelaA.addCell(String.valueOf(a.getMatricula())); tabelaA.addCell(a.getNoAluno()); tabelaA.addCell(a.getCpf()); tabelaA.addCell(a.getTelefone()); } doc.add(tabelaA); } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } }
From source file:biblioteca.BibliotecaFXMLController.java
@FXML /// Arquivo - PDF - Tabela Livros public void pdfL() throws FileNotFoundException, DocumentException, IOException, SQLException { Document doc = null;/* w w w . ja v a 2 s.c o m*/ OutputStream os = null; try { contest conn = new contest(); //cria o documento tamanho A4, margens de 2,54cm doc = new Document(PageSize.A4); //cria a stream de sada os = new FileOutputStream("TabelaL.pdf"); //associa a stream de sada ao PdfWriter.getInstance(doc, os); //abre o documento doc.open(); //adiciona o texto ao PDF PdfPTable tabelaL = new PdfPTable(new float[] { 0.1f, 0.7f, 0.7f, 0.1f }); PdfPCell header = new PdfPCell(new Paragraph("Tabela de Livros")); header.setColspan(4); tabelaL.addCell(header); tabelaL.addCell("ID"); tabelaL.addCell("Ttulo"); tabelaL.addCell("Autor"); tabelaL.addCell("Qtde."); Statement st = conn.conectar1().createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM `Livro`;"); while (rs.next()) { Livro l = new Livro(0, "", "", 0, 0); l.setIdlivro(rs.getInt("idlivro")); l.setTiLivro(rs.getString("nomeLivro")); l.setNoAutor(rs.getString("nomeAutor")); l.setQtdeLivro(rs.getInt("qtdelivro")); tabelaL.addCell(String.valueOf(l.getIdlivro())); tabelaL.addCell(l.getTiLivro()); tabelaL.addCell(l.getNoAutor()); tabelaL.addCell(String.valueOf(l.getQtdeLivro())); } doc.add(tabelaL); } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } }
From source file:biblioteca.BibliotecaFXMLController.java
@FXML /// Arquivo - PDF - Tabela Reservas public void pdfR() throws FileNotFoundException, DocumentException, IOException, SQLException { Document doc = null;// w ww . java 2 s . c o m OutputStream os = null; try { contest conn = new contest(); //cria o documento tamanho A4, margens de 2,54cm doc = new Document(PageSize.A4); //cria a stream de sada os = new FileOutputStream("Tabela de Reservas.pdf"); //associa a stream de sada ao PdfWriter.getInstance(doc, os); //abre o documento doc.open(); //adiciona o texto ao PDF PdfPTable tabelaR = new PdfPTable(new float[] { 0.2f, 0.7f, 0.7f, 0.7f, 0.7f }); PdfPCell header = new PdfPCell(new Paragraph("Tabela de Reservas")); header.setColspan(5); tabelaR.addCell(header); tabelaR.addCell("ID"); tabelaR.addCell("Ttulo do Livro"); tabelaR.addCell("Aluno"); tabelaR.addCell("Data de Saida"); tabelaR.addCell("Data de Entrega"); Statement stR = conn.conectar1().createStatement(); ResultSet rsr = stR.executeQuery( "SELECT Itens.id_Itens as \"Item\", Itens.id_reserva AS \"Reserva\", Aluno.nomeAluno " + "as \"Aluno\", Itens.id_Livro as \"idLivro\", Livro.nomeLivro AS \"NomeLivro\", Reserva.dataRetirada AS \"DataSaida\", Reserva.dataEntrega as \"DataEntrega\"" + "FROM Itens JOIN Reserva ON id_reserva = Reserva.idReserva\n" + "JOIN Aluno ON Reserva.idAluno = Aluno.idAluno\n" + "JOIN Livro ON Livro.idLivro = Itens.id_Livro;"); while (rsr.next()) { Reserva r = new Reserva(0, 0, "", 0, "", "", ""); r.setIdItem(rsr.getInt("Item")); r.setIdReserva(rsr.getInt("Reserva")); r.setNoAluno(rsr.getString("Aluno")); r.setIdLivro(rsr.getInt("idLivro")); r.setNoLivro(rsr.getString("NomeLivro")); r.setDaSaida(rsr.getString("DataSaida")); r.setDaEntrada(rsr.getString("DataEntrega")); tabelaR.addCell(String.valueOf(r.getIdReserva())); tabelaR.addCell(r.getNoLivro()); tabelaR.addCell(r.getNoAluno()); tabelaR.addCell(r.getDaSaida()); tabelaR.addCell(r.getDaEntrada()); } doc.add(tabelaR); } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } }
From source file:billerfx.FXMLBillController.java
File generatePDF() { File fi = null;/* w ww . j a va 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 a va2s. com 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;/* w ww .ja va 2s. com*/ 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);/* www . j a v a 2 s . 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:bookshopautomationsoftware.GenerateReceipt.java
private static void createTable(Section subCatPart) throws BadElementException { PdfPTable table = new PdfPTable(4); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); addEmptyLine(preface, 2);/*from w ww. ja v a2s . co m*/ PdfPCell c1 = new PdfPCell(new Phrase("slno")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("isbn")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("quantity")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("price")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); try { Connection con = DriverManager.getConnection(DB_URL1, USER1, PASS1); Statement stmnt = con.createStatement(); String sql = "SELECT slno,book,quantity FROM cart"; Connection con1 = DriverManager.getConnection(DB_URL1, USER1, PASS1); Statement stmnt1 = con.createStatement(); int count = 0; ResultSet rs = stmnt.executeQuery(sql); ResultSet rs1; float total = 0; while (rs.next()) { String sql1 = "SELECT isbn,price FROM booktable WHERE isbn = " + rs.getLong("book"); rs1 = stmnt1.executeQuery(sql1); rs1.next(); count++; table.addCell("" + rs.getInt("slno")); table.addCell("" + rs.getLong("book")); table.addCell("" + rs.getInt("quantity")); table.addCell("" + rs1.getFloat("price")); total += (rs1.getFloat("price")) * (rs.getInt("quantity")); // model.addRow(new Object[]{(""+rs.getInt("slno")),""+rs.getLong("book"),""+rs.getInt("quantity")}); } table.addCell(""); table.addCell(""); table.addCell(""); table.addCell("" + total); if (count == 0) { // dispose(); return; } } catch (Exception e) { System.out.println(" " + e + " is caught"); } /*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:br.com.docedesafio.pdfs.FirstPdf.java
private static 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 w w w . j a va 2 s . co 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); }