List of usage examples for com.itextpdf.text Document Document
public Document()
Document
-object. From source file:ILogbook.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: try {//from w w w . j av a 2 s . co 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:MainFrame.java
private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrintActionPerformed // TODO add your handling code here: try {/* w ww. j a v a2 s.co m*/ // TODO add your handling code here: String SQL = "Select * From tb_transaksi"; ResultSet rs = KoneksiDB.executeQuery(SQL); Document doc = new Document(); try { PdfWriter.getInstance(doc, new FileOutputStream("Report.pdf")); } catch (DocumentException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } doc.open(); try { doc.add(new Paragraph(" Warung Sido Mampir")); doc.add(new Paragraph( " Kenikmatan Nongki bersama kengkawan")); doc.add(new Paragraph(" ")); doc.add(new Paragraph("Waktu Pembelian : " + lblJam.getText())); doc.add(new Paragraph("Tanggal Pembelian : " + lblTgl.getText())); doc.add(new Paragraph("Nama Kasir : " + lblKasir.getText())); doc.add(new Paragraph("ID Transaksi: ")); try { while (rs.next()) { String id_transaksi = rs.getString(1); doc.add(new Paragraph(" " + id_transaksi)); } } catch (SQLException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } doc.add(new Paragraph(" Total Harga : " + tfTotal.getText())); doc.add(new Paragraph( " Diskon : " + lblDisc.getText())); doc.add(new Paragraph(" Jumlah Bayar : " + tfBayar.getText())); } catch (DocumentException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } doc.close(); } catch (FileNotFoundException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } }
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 {//from w w w . j av a2 s . com 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:PrintDonations.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . j a v a 2 s .com*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { response.setContentType("Invoice.pdf"); //Get the output stream for writing PDF object OutputStream out = response.getOutputStream(); SystemDao dao = new SystemDao(); String username_dbase = getServletContext().getInitParameter("username"); String dbasepsw = getServletContext().getInitParameter("password"); String dbase = getServletContext().getInitParameter("jdbcConnection"); dao.open(username_dbase, dbasepsw, dbase); Document document = new Document(); /* Basic PDF Creation inside servlet */ ArrayList<User> users = dao.gettAllUsers(); //tithes ArrayList<Donation> list = dao.getAllDonations(); ArrayList<String> projects = dao.getProjects(); //donaations Vector<String> donations = dao.get_donation(); PdfWriter.getInstance(document, out); document.open(); document.addAuthor("LightHouse Chapel International"); document.addCreationDate(); document.addCreator("lci.com"); document.add(new Paragraph(" ")); document.add(new Paragraph("============ PROJECTS ===========")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph("NAME" + " " + "NUMBER" + " " + "COST")); for (int x = 0; x < projects.size(); ++x) { String[] data = projects.get(x).split("@"); document.add(new Paragraph( " " + data[1] + " " + data[0] + " " + data[4])); } document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" Total Projects : " + projects.size())); document.add(new Paragraph(" ")); document.close(); } catch (Exception ex) { response.sendRedirect("systemError.jsp"); } }
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 w w . j a v a 2s.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 {//www . j a va2 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 {/*ww w .j av a 2s . 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 {// www .j av a2 s . c o m 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
CrearPdf(String[][] datos, String columnas[], String fecha, String autor, int d, String path) { try {/*from ww w.j a v a2s.com*/ this.d = d; this.fecha = fecha; this.autor = autor; this.columnas = columnas; this.datos = datos; FILE = path; Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); addMetaData(document); addTitlePage(document); createTable(document); document.close(); JOptionPane.showMessageDialog(null, "Guardado exitoso!", "Guardado exitoso!", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { e.printStackTrace(); } }
From source file:ResidentArchiveFrame.java
private void tabletoPDF1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tabletoPDF1ActionPerformed // TODO add your handling code here: String title = ""; if (jTabbedPane2.getSelectedIndex() == 0) { model = (DefaultTableModel) residentpersonalinfotable.getModel(); title = "PersonalInformation"; } else if (jTabbedPane2.getSelectedIndex() == 1) { model = (DefaultTableModel) residentcontactinfotable.getModel(); title = "ContactInformation"; } else if (jTabbedPane2.getSelectedIndex() == 2) { model = (DefaultTableModel) residentaddresstable.getModel(); title = "Address"; } else {//from w w w . j a va2s. co m model = (DefaultTableModel) residentstatustable.getModel(); title = "Status"; } Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream(path + "\\PDF\\" + title + "ResidentArchive.pdf")); PdfReader pdfReader = new PdfReader("ReportGeneration.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); pdfReader.close(); document.close(); JOptionPane.showMessageDialog(null, "Data saved at '" + path + "\\PDF\\" + title + "ResidentArchive.pdf' successfully", "Message", JOptionPane.INFORMATION_MESSAGE); } catch (FileNotFoundException ex) { // Logger.getLogger(ResidentArchiveFrame.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } catch (DocumentException | IOException ex) { // Logger.getLogger(ResidentArchiveFrame.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } }