List of usage examples for com.itextpdf.text Document Document
public Document()
Document
-object. From source file:com.example.createpdffromimage.FirstPdf.java
private void initialize() { try {/*w w w . j av a 2s . 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.example.pdfcreate.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn1 = (Button) findViewById(R.id.button1); btn1.setOnClickListener(new OnClickListener() { @Override/*from w ww . j a va 2s. c o m*/ public void onClick(View arg0) { File f = new File(FILE); if (!(f.exists())) { try { f.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); Log.e("FileCreated", "filsesss"); } } txt1 = (EditText) findViewById(R.id.editText2); txt2 = (EditText) findViewById(R.id.editText1); str1 = txt1.getText().toString(); str2 = txt2.getText().toString(); Log.e("Pdfmssgggg......1..", str1); Log.e("Pdfmssgggg....2....", str2); try { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); addMetaData(document); addTitlePage(document); addContent(document); //createImage(); document.close(); Log.e("Pdfmssgggg", "PDG created"); Toast.makeText(getApplicationContext(), "Pdf Created", Toast.LENGTH_LONG).show(); } catch (Exception e) { Log.e("Errorrr", e.getMessage()); Toast.makeText(getApplicationContext(), "Error---in Pdf Created", Toast.LENGTH_LONG).show(); } } }); }
From source file:com.example.PDFViewer.FirstPdf.java
public static void main(String[] args) { try {/*from w w w . j a v a2 s . c o m*/ Document document = new Document(); String extStorageDirectory = Environment.getExternalStorageDirectory().toString(); File folder = new File(extStorageDirectory, "testthreepdf"); folder.mkdir(); File pdfFile = new File(folder, "second.pdf"); if (!pdfFile.exists()) pdfFile.createNewFile(); PdfWriter.getInstance(document, new FileOutputStream(pdfFile)); // PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); addMetaData(document); addTitlePage(document); addContent(document); document.close(); } catch (Exception e) { Log.d("test", "error" + e.getMessage()); e.printStackTrace(); } }
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 av 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 w w w . j av a2s. co m*/ 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/*ww w . j ava 2s . c o m*/ 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 w w w . j a v a 2s . 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.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 {// w ww .j a v a 2 s. c o 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 {/* ww w .j a v a2s . com*/ 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 {//from w w w .j av a2 s .com 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); } }