List of usage examples for com.itextpdf.text Document close
boolean close
To view the source code for com.itextpdf.text Document close.
Click Source Link
From source file:com.farouk.projectapp.ManagerGUI.java
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed String pdfName = JOptionPane.showInputDialog(rootPane, "Enter Title", "Please enter a title", WIDTH); if (pdfName.isEmpty()) { pdfName = "Global Report"; }/*from w w w . j a v a 2 s .c om*/ Document document = new Document(); int numEMployees = 1; try { PdfWriter.getInstance(document, new FileOutputStream(pdfName + ".pdf")); document.open(); document.addAuthor("TeamPirates"); document.addTitle("Global Report"); Font font1 = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD); Font font2 = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.UNDERLINE); for (User u : SQLConnectMana.getEmployeesFromDb()) { JTable jTableTran = new JTable(); JTable jTableReport = new JTable(); Chapter chapter = new Chapter( new Paragraph(new Phrase("Employee : " + u.getLogin() + "\n\n", font1)), numEMployees); Section section1 = chapter.addSection(new Paragraph(new Phrase("Recent Transactions :\n", font2)), 9); Section section2 = chapter.addSection(new Paragraph(new Phrase("Reported Companies :\n", font2)), 9); // Transactions : DefaultTableModel modelPDFtrans = new DefaultTableModel(); modelPDFtrans.setColumnIdentifiers( new String[] { "Name", "Operation", "Quantity", "Price Paid", "Date" }); for (Transaction t : SQLConnectMana.getTransactions(u.getId())) { modelPDFtrans.addRow(new String[] { t.getSymbol(), t.getOperation(), Integer.toString(t.getQuantity()), Double.toString(t.getPricePaid()), t.getDate() }); } jTableTran.setModel(modelPDFtrans); PdfPTable pdfTableTrans = new PdfPTable(jTableTran.getColumnCount()); for (int i = 0; i < jTableTran.getColumnCount(); i++) { pdfTableTrans.addCell(jTableTran.getColumnName(i)); } //extracting data from the JTable and inserting it to PdfPTable for (int rows = 0; rows < jTableTran.getRowCount(); rows++) { for (int cols = 0; cols < jTableTran.getColumnCount(); cols++) { pdfTableTrans.addCell(jTableTran.getModel().getValueAt(rows, cols).toString()); } } Paragraph blank = new Paragraph("\n\n"); section1.add(blank); section1.add(pdfTableTrans); section1.add(blank); //Reported Companies : DefaultTableModel modelPDFReported = new DefaultTableModel(); modelPDFReported.setColumnIdentifiers( new String[] { "Name", "Symbol", "Stock Price ()", "Quantity Bought" }); for (Company c : SQLConnectMana.getNameOfReported(u.getId())) { modelPDFReported.addRow(new String[] { c.getName(), c.getSymbol(), String.valueOf(c.getStockPrice().doubleValue()), Integer.toString(c.getNumberOwned()) }); } jTableReport.setModel(modelPDFReported); PdfPTable pdfTableReport = new PdfPTable(jTableReport.getColumnCount()); for (int i = 0; i < jTableReport.getColumnCount(); i++) { pdfTableReport.addCell(jTableReport.getColumnName(i)); } //extracting data from the JTable and inserting it to PdfPTable for (int rows = 0; rows < jTableReport.getRowCount(); rows++) { for (int cols = 0; cols < jTableReport.getColumnCount(); cols++) { pdfTableReport.addCell(jTableReport.getModel().getValueAt(rows, cols).toString()); } } section2.add(blank); section2.add(pdfTableReport); section2.add(blank); //End of doc for a single employee document.add(chapter); numEMployees++; } Chapter ban = new Chapter(new Paragraph(new Phrase("Prohibited Companies :\n\n", font1)), ++numEMployees); com.itextpdf.text.List bannedCompanies = new List(List.ORDERED); for (String lii : SQLConnectMana.getBannedCompForAll()) { bannedCompanies.add(new com.itextpdf.text.ListItem(lii)); } ban.add(bannedCompanies); document.add(ban); document.close(); } catch (DocumentException | FileNotFoundException e) { System.err.println("Sorry Problem in pdf.\n" + e); } }
From source file:com.fixent.publish.server.pdf.AddressPdf.java
public static void main(String[] args) { try {//from ww w . ja va 2 s . c om Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); addMetaData(document); addTitlePage(document); addContent(document); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.framework.example.html2pdf.ConvertDemo.java
public static void createPdf(String file) throws IOException, DocumentException { // step 1/*from ww w.j a va 2s .com*/ Document document = new Document(); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); // step 3 document.open(); // step 4 XMLWorkerHelper.getInstance().parseXHtml(writer, document, new FileInputStream(HTML), Charset.forName("UTF-8")); // step 5 document.close(); }
From source file:com.framework.example.html2pdf.ConvertDemo.java
public static void htmlCodeComeFromFile(String filePath, String pdfPath) { Document document = new Document(); try {/*from ww w . j av a 2 s . c o m*/ StyleSheet st = new StyleSheet(); st.loadTagStyle("body", "leading", "16,0"); PdfWriter.getInstance(document, new FileOutputStream(pdfPath)); document.open(); ArrayList p = (ArrayList) HTMLWorker.parseToList(new FileReader(filePath), st); for (int k = 0; k < p.size(); ++k) { document.add((Element) p.get(k)); } document.close(); System.out.println("?"); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.framework.example.html2pdf.ConvertDemo.java
public void htmlCodeComeString(String htmlCode, String pdfPath) { Document doc = new Document(PageSize.A4); try {// w w w. j ava2 s .c om PdfWriter.getInstance(doc, new FileOutputStream(pdfPath)); doc.open(); // // BaseFont bfChinese = // BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); // Font FontChinese = new Font(bfChinese, 12, Font.BOLD); Paragraph t = new Paragraph(htmlCode); doc.add(t); doc.close(); System.out.println("?"); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ftt.gui.FrameFormation.java
private void pdf1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pdf1ActionPerformed if (nomf.getText() == null || descriptionf.getText() == null || "".equals(lieux.getText()) || dateclot.getDate() == null || dateov.getDate() == null) { JOptionPane.showMessageDialog(this, "Vrifier les champs !"); } else {//from w ww .j a v a 2s .co m SimpleDateFormat formateur = new SimpleDateFormat("dd-MM-yyyy"); String val1 = lieux.getText(); String val2 = formateur.format(dateov.getDate()); String val3 = formateur.format(dateclot.getDate()); String val4 = combocible.getSelectedItem().toString(); String val5 = nomf.getText(); String val6 = descriptionf.getText(); Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream("rapport.pdf")); document.open(); com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance("ftt.png"); document.add(image); document.add(new Paragraph("Liste des formations", FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD))); document.add(new Paragraph(formateur.format(new Date()))); String val322 = formateur.format(new Date()); document.add(new Paragraph(" ")); PdfPTable table = new PdfPTable(2); PdfPCell cell = new PdfPCell(new Paragraph("formations")); cell.setColspan(4); cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.BLUE); table.addCell(cell); table.addCell("Nom formation"); table.addCell(val5); table.addCell(cell); table.addCell("Description"); table.addCell(val6); table.addCell(cell); table.addCell("Lieux"); table.addCell(val1); table.addCell("Date d'ouverture"); table.addCell(val2); table.addCell("Date de cloture"); table.addCell(val3); table.addCell("Cible"); table.addCell(val4); document.add(table); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph("Responsable des formations")); document.add(new Paragraph("Federation Tunisenne de Tennis")); document.close(); JOptionPane.showMessageDialog(null, "Rapport Enregistrer"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } }
From source file:com.ftt.gui.FrameFormation.java
private void pdf2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pdf2ActionPerformed FormationDAO fd = new FormationDAO(); ArrayList<Formation> formations = (ArrayList<Formation>) fd.select(); SimpleDateFormat formateur = new SimpleDateFormat("dd-MM-yyyy"); Document document = new Document(); try {/* w ww .j av a 2s . c o m*/ PdfWriter.getInstance(document, new FileOutputStream("rapport_formations.pdf")); document.open(); com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance("ftt.png"); document.add(image); document.add(new Paragraph("Liste des formations", FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD))); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); for (int i = 0; i < formations.size(); i++) { document.add(new Paragraph(" ")); int val = formations.get(i).getId(); String val1 = formations.get(i).getLieux(); String val2 = formations.get(i).getDateOuverture(); String val3 = formations.get(i).getDateCloture(); String val4 = formations.get(i).getCible(); String val5 = formations.get(i).getNom(); String val6 = formations.get(i).getDescription(); PdfPTable table = new PdfPTable(2); PdfPCell cell = new PdfPCell(new Paragraph("formation " + val)); cell.setColspan(4); cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.GRAY); table.addCell(cell); table.addCell("Nom formation"); table.addCell(val5); table.addCell("Description"); table.addCell(val6); table.addCell("Lieux"); table.addCell(val1); table.addCell("Date d'ouverture"); table.addCell(val2); table.addCell("Date de cloture"); table.addCell(val3); table.addCell("Cible"); table.addCell(val4); document.add(table); } document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph("Responsable des formations")); document.add(new Paragraph("Federation Tunisenne de Tennis")); document.close(); JOptionPane.showMessageDialog(null, "Rapport Enregistrer"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:com.ftt.gui.FrameJoueur.java
private void pdf2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pdf2ActionPerformed JoueurDAO fd = new JoueurDAO(); ArrayList<Joueur> joueurs = (ArrayList<Joueur>) fd.select_trie_par_club(); SimpleDateFormat formateur = new SimpleDateFormat("dd-MM-yyyy"); Document document = new Document(); try {/* ww w .j a va2 s .c o m*/ PdfWriter.getInstance(document, new FileOutputStream("rapport_joueurs.pdf")); document.open(); com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance("ftt.png"); document.add(image); document.add(new Paragraph("Liste des joueurs", FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD))); document.add(new Paragraph(" ")); for (int i = 0; i < joueurs.size(); i++) { document.add(new Paragraph(" ")); document.add(new Paragraph(joueurs.get(i).getNom_club())); document.add(new Paragraph(" ")); Integer val = joueurs.get(i).getId(); String val1 = joueurs.get(i).getNomJoueur(); String val2 = joueurs.get(i).getPrenomJoueur(); String val3 = joueurs.get(i).getDateNaissance(); String val4 = joueurs.get(i).getCarriere(); String val5 = joueurs.get(i).getSexe(); Integer val6 = joueurs.get(i).getPoints(); PdfPTable table = new PdfPTable(2); PdfPCell cell = new PdfPCell(new Paragraph("Joueur id: " + val)); cell.setColspan(4); cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_LEFT); cell.setBackgroundColor(BaseColor.GRAY); table.addCell(cell); table.addCell("Nom"); table.addCell(val1); table.addCell("Prenom"); table.addCell(val2); table.addCell("Date de naissance"); table.addCell(val3); table.addCell("Carriere"); table.addCell(val4); table.addCell("sexe"); table.addCell(val5); table.addCell("points"); table.addCell(val6.toString()); document.add(table); } document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph("Federation Tunisenne de Tennis")); document.close(); JOptionPane.showMessageDialog(null, "Rapport Enregistrer"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:com.gadroves.gsisinve.controller.FacturarController.java
void PrintToPDF(TbFacturaVenta facturaVenta, TbCLienteFactura cLienteFactura) throws DocumentException, IOException { Font header = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD); Font normalBold = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font normal = new Font(Font.FontFamily.HELVETICA, 12); String fileName = "Factura_" + facturaVenta.getId() + ".pdf"; // step 1// w w w .j a va 2 s. co m Document document = new Document(); // step 2 PdfWriter.getInstance(document, new FileOutputStream(fileName)); // step 3 document.open(); // step 4 document.add(new Paragraph("Gadroves S.A Factura De Venta", header)); document.add(new Paragraph(" ")); document.add(new Paragraph("Factura N" + facturaVenta.getId(), normalBold)); document.add(new Chunk("Cliente: ", normalBold)); document.add(new Chunk(" ")); document.add(new Chunk(cLienteFactura.getName(), normal)); document.add(new Paragraph()); document.add(new Chunk("Direccin: ", normalBold)); document.add(new Chunk(" ")); document.add(new Chunk(cLienteFactura.getAddress(), normal)); document.add(new Paragraph()); document.add(new Chunk("Identificacion: ", normalBold)); document.add(new Chunk(" ")); document.add(new Chunk(cLienteFactura.getId(), normal)); document.add(new Paragraph()); document.add(new Chunk("Credito: ", normalBold)); document.add(new Chunk(" ")); document.add(new Chunk(Boolean.FALSE.toString(), normal)); document.add(new Paragraph()); for (int i = 0; i < 3; i++) document.add(new Paragraph(" ")); createItemsTable(document, facturaVenta); document.add(new Paragraph(" ")); Paragraph subs = new Paragraph(); subs.setAlignment(Element.ALIGN_RIGHT); subs.setIndentationRight(40); subs.add(new Chunk("Subtotal: " + String.format("%1$" + 10 + "s", String.valueOf(facturaVenta.getSub())))); subs.add(Chunk.NEWLINE); subs.add(new Chunk( "Impuestos: " + String.format("%1$" + 10 + "s", String.valueOf(facturaVenta.getImpuestos())))); subs.add(Chunk.NEWLINE); subs.add(new Chunk( "Total: " + String.format("%1$" + 10 + "s", String.valueOf(facturaVenta.getTotal())))); subs.add(Chunk.NEWLINE); document.add(subs); // step 5 document.close(); Desktop.getDesktop().open(new File(fileName)); }
From source file:com.github.albfernandez.joinpdf.ItextUtils.java
License:Open Source License
public static void close(final Document document) { try {//w ww .ja va 2s .c om if (document != null) { document.close(); } } catch (Exception e) { // NOPMD // } }