List of usage examples for com.itextpdf.text.pdf PdfPTable addCell
public void addCell(final Phrase phrase)
From source file:Main_Frame.java
private void jMenuItem29ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem29ActionPerformed try {/*from w w w .j a v a2s. co m*/ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con1 = DriverManager.getConnection("jdbc:odbc:College"); Statement stm1 = con1.createStatement(); //Statement stm1 = con1.createStatement(); ResultSet rs = stm1.executeQuery("SELECT * from Slot_Details"); //ResultSet rs1 = stm2.executeQuery("SELECT * from Slot_Details"); String[] start = new String[10]; String[] end = new String[10]; int line = 0; while (rs.next()) { start[line] = rs.getString("START"); end[line] = rs.getString("END"); line++; } /* try{ Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con2=DriverManager.getConnection("jdbc:odbc:College");*/ Statement stm2 = con1.createStatement(); ResultSet query_set = stm2.executeQuery("SELECT * from format"); /* Step-2: Initialize PDF documents - logical objects */ Document my_pdf_report = new Document(PageSize.A4); PdfWriter.getInstance(my_pdf_report, new FileOutputStream("C:\\Users\\Durga\\Desktop\\Time_Table.pdf")); my_pdf_report.open(); //we have four columns in our table PdfPTable table = new PdfPTable(10); //table.setWidthPercentage(100); // table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); String a[] = { "//////", "//////", "//////", "//////", "//////", "//////", "//////", "//////", "L", "U", "N", "C", "H", "//////", "//////", "//////", "//////", "//////", "//////" }; int len = 1; table.addCell("Day"); table.addCell("Branch"); String s; for (int i = 0; i < line; i++) { int j = i; if (i == 5) table.addCell(a[0]); if (i >= 5) j = line - 1; table.addCell("Period" + (i) + " \n[" + start[j] + "-" + end[j] + "]"); } table.getDefaultCell().setFixedHeight(70); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); while (query_set.next()) { String Day = query_set.getString("Day"); table.addCell(Day); String Branch = query_set.getString("Branch"); table.addCell(Branch); for (int i = 0; i < line; i++) { if (i == 5) { table.addCell(a[len++]); table.addCell(query_set.getString("slot" + (i + 1)) + "G1"); } else if (i == 6) { table.addCell(query_set.getString("slot" + (i + 1)) + "G2"); } else table.addCell(query_set.getString("slot" + (i + 1))); } } /* Attach report table to PDF */ // my_pdf_report.add(my_report_table); my_pdf_report.add(table); my_pdf_report.close(); /* Close all DB related objects */ query_set.close(); stm2.close(); //con2.close(); // } /* catch(Exception e) { System.out.println(e); }*/ stm1.close(); con1.close(); } catch (Exception e) { System.out.println(e); } if (Desktop.isDesktopSupported()) //Open pdf file { try { File myFile = new File("C:\\Users\\Durga\\Desktop\\Time_Table.pdf"); Desktop.getDesktop().open(myFile); } catch (Exception ex) { System.out.println(ex); } //System.out.println(ex); } }
From source file:pdf_demo2.java
private static void createTable(Section section) throws BadElementException { // number of table-column = 3 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); c1 = new PdfPCell(new Phrase("Table Header 2")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);/*from w w w. ja v a 2 s. co m*/ 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"); section.add(table); }
From source file:ILogbook.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: try {/* w ww . j a v a2 s . c o m*/ if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { String path = chooser.getSelectedFile().toString() + "\\" + new SimpleDateFormat("MMddyyyy") .format(dateCombo.getDateFormat().parse(dateCombo.getText())) + "logbook.pdf"; tableModel = (DefaultTableModel) logsTable.getModel(); Document document = new Document(); FileOutputStream fos = new FileOutputStream(path); PdfWriter.getInstance(document, fos); document.open(); Paragraph par = new Paragraph( "Date: " + new SimpleDateFormat("MMMM dd, yyyy") .format(dateCombo.getDateFormat().parse(dateCombo.getText())), new Font(FontFamily.TIMES_ROMAN, 12)); document.add(par); PdfPTable tab = new PdfPTable(tableModel.getColumnCount() - 1); for (int i = 1; i < tableModel.getColumnCount(); i++) { tab.addCell(tableModel.getColumnName(i)); } for (int i = 0; i < tableModel.getRowCount(); i++) { for (int j = 1; j < tableModel.getColumnCount(); j++) { tab.addCell(tableModel.getValueAt(i, j).toString()); } } document.add(tab); document.close(); fos.close(); new MessageDialog().successful(this, "File Saved."); } } catch (ParseException | DocumentException ex) { // Logger.getLogger(ILogbook.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } catch (FileNotFoundException ex) { // Logger.getLogger(ILogbook.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } catch (IOException ex) { // Logger.getLogger(ILogbook.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } }
From source file:AdminArchiveFrame.java
private void tabletoPDFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tabletoPDFActionPerformed // TODO add your handling code here: Document document = new Document(); try {/* w w w. j a v a 2s.c om*/ PdfWriter.getInstance(document, new FileOutputStream(path + "\\PDF\\AdminArchive.pdf")); document.open(); PdfPTable tab = new PdfPTable(model.getColumnCount()); for (int i = 0; i < model.getColumnCount(); i++) { tab.addCell(model.getColumnName(i)); } for (int i = 0; i < model.getRowCount(); i++) { for (int j = 0; j < model.getColumnCount(); j++) { tab.addCell(model.getValueAt(i, j).toString()); } } document.add(tab); JOptionPane.showMessageDialog(null, "Data saved at " + path + "'\\PDF\\AdminArchive.pdf' successfully", "Message", JOptionPane.INFORMATION_MESSAGE); document.close(); } catch (FileNotFoundException | DocumentException ex) { // Logger.getLogger(TransientArchiveFrame.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } }
From source file:EmployeeInfo.java
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed String value1 = txt_empID.getText(); String value2 = txt_firstName.getText(); String value3 = txt_lastName.getText(); String value4 = txt_age.getText(); try {//from w ww. ja v a 2 s.c o m Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Report1.pdf")); document.open(); //add barcode PdfContentByte CB = writer.getDirectContent(); BarcodeEAN codEAN = new BarcodeEAN(); codEAN.setCode("1234567891023"); //this value must be 13 digits Paragraph para = new Paragraph(); document.add(new Paragraph("Barcode UDCA")); codEAN.setCodeType(BarcodeEAN.UPCA); codEAN.setCode("1098765432112"); document.add(codEAN.createImageWithBarcode(CB, BaseColor.BLACK, BaseColor.BLACK)); document.add(para); Image image = Image.getInstance("images/Cherry.png"); document.add(new Paragraph("Image")); document.add(image); // write tile with style document.add(new Paragraph("Hello World", FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED))); // write date document.add(new Paragraph(new Date().toString())); document.add(new Paragraph("--------------------------------------------")); PdfPTable table = new PdfPTable(2);// 2 columns // set title , column sapn, aliignment,background color PdfPCell cell = new PdfPCell(new Paragraph("Title")); cell.setColspan(4); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.BLUE); table.addCell(cell); // PdfPTable table = new PdfPTable(x); should add multiple of x table.addCell("EmployeeID"); table.addCell(value1); table.addCell("Name"); table.addCell(value2); table.addCell("Last Name"); table.addCell(value3); table.addCell("Age"); table.addCell(value4); document.add(table); List list = new List(true, 20); list.add("First Item"); list.add("Second Item"); list.add("Third Item"); list.add("Fourth Item"); document.add(list); document.close(); JOptionPane.showMessageDialog(null, "Report saved"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:Report1.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: try {//from www.j av a 2 s .c om Document doc = new Document() { }; PdfWriter.getInstance(doc, new FileOutputStream("table.pdf")); doc.open(); PdfPTable pdfTable = new PdfPTable(jTable1.getColumnCount()); //adding table headers for (int i = 0; i < jTable1.getColumnCount(); i++) { pdfTable.addCell(jTable1.getColumnName(i)); } //extracting data from the JTable and inserting it to PdfPTable for (int rows = 0; rows < jTable1.getRowCount() - 1; rows++) { for (int cols = 0; cols < jTable1.getColumnCount(); cols++) { pdfTable.addCell(jTable1.getModel().getValueAt(rows, cols).toString()); } } doc.add(pdfTable); doc.close(); JOptionPane.showMessageDialog(am, "Report have been saved in PDF ``````````````````````````````````````````````````````"); } catch (DocumentException ex) { JOptionPane.showMessageDialog(rootPane, ex); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(rootPane, "File Not Found"); } }
From source file:FurnitureArchiveFrame.java
private void tabletoPDFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tabletoPDFActionPerformed Document document = new Document(); try {// w w w . j a v a 2 s .c om PdfWriter.getInstance(document, new FileOutputStream(path + "\\PDF\\FurnitureArchive.pdf")); document.open(); PdfPTable tab = new PdfPTable(model.getColumnCount()); for (int i = 0; i < model.getColumnCount(); i++) { tab.addCell(model.getColumnName(i)); } for (int i = 0; i < model.getRowCount(); i++) { for (int j = 0; j < model.getColumnCount(); j++) { if (model.getValueAt(i, j) != null) { tab.addCell(model.getValueAt(i, j).toString()); } else { tab.addCell("-"); } } } document.add(tab); JOptionPane.showMessageDialog(null, "Data saved at " + path + "'\\PDF\\FurnitureArchive.pdf' successfully", "Message", JOptionPane.INFORMATION_MESSAGE); document.close(); } catch (FileNotFoundException | DocumentException ex) { // Logger.getLogger(TimeInOutArchiveFrame.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } }
From source file:TimeInOutArchiveFrame.java
private void tabletoPDFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tabletoPDFActionPerformed model = (DefaultTableModel) residentlogsinfotable.getModel(); Document document = new Document(); try {//from w w w .j a va 2 s.c om PdfWriter.getInstance(document, new FileOutputStream(path + "\\PDF\\TimeInOutArchive.pdf")); document.open(); PdfPTable tab = new PdfPTable(model.getColumnCount()); for (int i = 0; i < model.getColumnCount(); i++) { tab.addCell(model.getColumnName(i)); } for (int i = 0; i < model.getRowCount(); i++) { for (int j = 0; j < model.getColumnCount(); j++) { if (model.getValueAt(i, j) != null) { tab.addCell(model.getValueAt(i, j).toString()); } else { tab.addCell("-"); } } } document.add(tab); JOptionPane.showMessageDialog(null, "Data saved at " + path + "'\\PDF\\TimeInOutArchive.pdf' successfully", "Message", JOptionPane.INFORMATION_MESSAGE); document.close(); } catch (FileNotFoundException | DocumentException ex) { // Logger.getLogger(TimeInOutArchiveFrame.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } }
From source file:CrearPdf.java
private void createTable(Document document) throws BadElementException, DocumentException { PdfPTable table = new PdfPTable(6); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1;/*from ww w.jav a2 s . c o m*/ for (int i = 0; i < columnas.length; i++) { c1 = new PdfPCell(new Phrase(columnas[i])); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); System.out.println("columnas" + columnas[i]); } table.setHeaderRows(1); for (int i = 0; i < d; i++) { for (int j = 0; j < columnas.length; j++) { System.out.print(datos[i][j] + " "); table.addCell(datos[i][j]); } System.out.println(); } document.add(table); }
From source file:FullPageTable.java
public void createPdf(String dest) throws IOException, DocumentException { Document document = new Document(PageSize.A4, 0, 0, 0, 0); PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open();// ww w .j a va2 s . co m PdfPTable table = new PdfPTable(10); table.setWidthPercentage(100); table.setSpacingBefore(0f); table.setSpacingAfter(0f); // first row PdfPCell cell = new PdfPCell(new Phrase("DateRange")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(10.0f); cell.setBackgroundColor(new BaseColor(140, 221, 8)); table.addCell(cell); table.addCell("Calldate"); table.addCell("Calltime"); table.addCell("Source"); table.addCell("DialedNo"); table.addCell("Extension"); table.addCell("Trunk"); table.addCell("Duration"); table.addCell("Calltype"); table.addCell("Callcost"); table.addCell("Site"); for (int i = 0; i < 100; i++) { table.addCell("date" + i); table.addCell("time" + i); table.addCell("source" + i); table.addCell("destination" + i); table.addCell("extension" + i); table.addCell("trunk" + i); table.addCell("dur" + i); table.addCell("toc" + i); table.addCell("callcost" + i); table.addCell("Site" + i); } document.add(table); document.close(); }