List of usage examples for com.itextpdf.kernel.pdf PdfWriter close
@Override public void close() throws IOException
From source file:com.js.quickestquail.ui.actions.io.ExportToPDFAction.java
private void writeAll(File outputFile) throws FileNotFoundException, IOException { // progress dialog JProgressDialog dialog = new JProgressDialog(UI.get(), false); dialog.setMaximum(DriveManager.get().getSelected().size()); dialog.setTitle(java.util.ResourceBundle.getBundle("i18n/i18n").getString("export.pdf")); dialog.setVisible(true);//from w w w . j a va 2 s. c om // run this in a new Thread new Thread() { @Override public void run() { try { int nrOfMovies = 0; List<Entry<File, String>> entries = new ArrayList<>( DriveManager.get().getSelected().entrySet()); java.util.Collections.sort(entries, new Comparator<Entry<File, String>>() { @Override public int compare(Entry<File, String> o1, Entry<File, String> o2) { Movie mov1 = CachedMovieProvider.get().getMovieByID(o1.getValue()); Movie mov2 = CachedMovieProvider.get().getMovieByID(o2.getValue()); return mov1.getTitle().compareTo(mov2.getTitle()); } }); PdfWriter writer = new PdfWriter(new FileOutputStream(outputFile)); PdfDocument pdf = new PdfDocument(writer); Document doc = new Document(pdf); for (Entry<File, String> en : entries) { Movie mov = CachedMovieProvider.get().getMovieByID(en.getValue()); // update progress dialog dialog.setText(mov.getTitle()); dialog.setProgress(nrOfMovies); // add table Table table = new Table(new float[] { 0.5f, 0.25f, 0.25f }); table.setWidthPercent(100); table.setBorder(Border.NO_BORDER); Cell cell; cell = new Cell(5, 1); cell.setBorder(Border.NO_BORDER); try { Image img = new Image(ImageDataFactory.create(new URL(mov.getPoster()))); cell.setNextRenderer(new ImageBackgroundCellRenderer(cell, img)); } catch (Exception ex) { } cell.setHeight(160); cell.setWidth(100); table.addCell(cell); cell = new Cell(1, 1).add("Title").setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add(mov.getTitle()).setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add("Year").setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add(mov.getYear() + "").setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add("IMDB ID").setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add(mov.getImdbID()).setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add("IMDB Rating").setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add(mov.getImdbRating() + "").setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add("IMDB Votes").setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add(mov.getImdbVotes() + "").setBorder(Border.NO_BORDER); table.addCell(cell); doc.add(table); nrOfMovies++; if (nrOfMovies % 4 == 0) { doc.add(new AreaBreak()); } doc.add(new Paragraph("")); } // close IO doc.close(); pdf.close(); writer.close(); // close dialog dialog.setVisible(false); } catch (Exception ex) { } } }.start(); }
From source file:model.PrintPDF.java
public void inThongKeCanBo(ArrayList<CanBo> listCanBo, String pathName, String nam, int gt, String tongNhanVien, String soNVVH) {// ww w . j ava 2 s . co m PdfWriter pdfWriter = null; String gioiTinh = ""; if (gt == 1) { gioiTinh = "n"; } else { gioiTinh = "nam"; } try { pdfWriter = new PdfWriter(pathName); PdfDocument pdfDocument = new PdfDocument(pdfWriter); Document document = new Document(pdfDocument, PageSize.A4.rotate()); PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H, true); document.setMargins(50, 50, 50, 50); document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold() .setTextAlignment(TextAlignment.CENTER).setFontSize(16)); document.add(new Paragraph("Thng k cn b " + gioiTinh + " nm " + nam + "\n\n").setFont(hfont) .setBold().setTextAlignment(TextAlignment.CENTER).setFontSize(14)); float[] columnWidths = { 1, 2, 4, 3, 4 }; Table table = new Table(columnWidths); table.setWidthPercent(100); table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold() .setFontSize(14)); table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont) .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("Ngy sinh").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("S in thoi").setFont(hfont) .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14)); // ni dung ca bng thng k for (int i = 0; i < listCanBo.size(); i++) { table.addCell(new Paragraph((i + 1) + "").setFont(hfont).setTextAlignment(TextAlignment.CENTER)); table.addCell(new Paragraph(listCanBo.get(i).getMaCB()).setFont(hfont) .setTextAlignment(TextAlignment.CENTER)); table.addCell(new Paragraph(listCanBo.get(i).getHoTen()).setFont(hfont) .setTextAlignment(TextAlignment.CENTER)); table.addCell(new Paragraph(dateFormat.format(listCanBo.get(i).getNgaySinh())).setFont(hfont) .setTextAlignment(TextAlignment.CENTER)); table.addCell(new Paragraph(listCanBo.get(i).getSDT()).setFont(hfont) .setTextAlignment(TextAlignment.CENTER)); } document.add(table); document.add(new Paragraph("\n\n Tng s nhn vin : " + tongNhanVien).setFont(hfont) .setTextAlignment(TextAlignment.LEFT)); document.add(new Paragraph(" Tng s nhn vin sp v? hu : " + tongNhanVien).setFont(hfont) .setTextAlignment(TextAlignment.LEFT)); document.add(new Paragraph( "\n\n\n H Ni, ngy thng nm \n Ng?i lp phiu \n ( Ghi r h? tn) ") .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40)); document.close(); } catch (FileNotFoundException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } finally { try { pdfWriter.close(); } catch (IOException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:model.PrintPDF.java
public void thongKeDoanPhi(ArrayList<String> listDataTable, String pathName, String nam, String tongDoanVien, String tienDoanPhi) {//from w ww.java2s. c om PdfWriter pdfWriter = null; String gioiTinh = ""; try { pdfWriter = new PdfWriter(pathName); PdfDocument pdfDocument = new PdfDocument(pdfWriter); Document document = new Document(pdfDocument, PageSize.A4.rotate()); PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H, true); document.setMargins(50, 50, 50, 50); document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold() .setTextAlignment(TextAlignment.CENTER).setFontSize(16)); document.add(new Paragraph("Thng k on vin " + gioiTinh + " nm " + nam + "\n\n") .setFont(hfont).setBold().setTextAlignment(TextAlignment.CENTER).setFontSize(14)); float[] columnWidths = { 1, 2, 4, 3, 4 }; Table table = new Table(columnWidths); table.setWidthPercent(100); table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold() .setFontSize(14)); table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont) .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("Ngy sinh").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("S ti khon ").setFont(hfont) .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14)); // ni dung ca bng thng k for (int i = 0; i < listDataTable.size(); i++) { table.addCell(new Paragraph(listDataTable.get(i)).setFont(hfont) .setTextAlignment(TextAlignment.CENTER).setFontSize(14)); } document.add(table); document.add(new Paragraph("\n\n Tng s on vin : " + tongDoanVien).setFont(hfont) .setTextAlignment(TextAlignment.LEFT)); document.add(new Paragraph(" ?on ph (VN? / ?on Vin) : " + tienDoanPhi + "VN?") .setFont(hfont).setTextAlignment(TextAlignment.LEFT)); double tongTienDoanPhi = Integer.parseInt(tongDoanVien) * Integer.parseInt(tienDoanPhi); document.add(new Paragraph(" Tng s ti?n on ph : " + tongTienDoanPhi + " VND") .setFont(hfont).setTextAlignment(TextAlignment.LEFT)); document.add(new Paragraph( "\n\n\n H Ni, ngy thng nm \n Ng?i lp phiu \n ( Ghi r h? tn) ") .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40)); document.close(); } catch (FileNotFoundException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } finally { try { pdfWriter.close(); } catch (IOException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:model.PrintPDF.java
public void thongKeCongDoanPhi(ArrayList<String> listDataTable, String pathName, String nam, String tongCongDoanVien, String tienCongDoanPhi) { PdfWriter pdfWriter = null; try {/*www . j a v a2s . com*/ pdfWriter = new PdfWriter(pathName); PdfDocument pdfDocument = new PdfDocument(pdfWriter); Document document = new Document(pdfDocument, PageSize.A4.rotate()); PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H, true); document.setMargins(50, 50, 50, 50); document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold() .setTextAlignment(TextAlignment.CENTER).setFontSize(16)); document.add(new Paragraph("Thng k cng on vin nm " + nam + "\n\n").setFont(hfont) .setBold().setTextAlignment(TextAlignment.CENTER).setFontSize(14)); float[] columnWidths = { 1, 2, 4, 3, 3, 3 }; Table table = new Table(columnWidths); table.setWidthPercent(100); table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold() .setFontSize(14)); table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont) .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("Ngy sinh").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("Chc v ").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("Cng on ph ").setFont(hfont) .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14)); // ni dung ca bng thng k for (int i = 0; i < listDataTable.size(); i++) { table.addCell(new Paragraph(listDataTable.get(i)).setFont(hfont) .setTextAlignment(TextAlignment.CENTER).setFontSize(14)); } document.add(table); document.add(new Paragraph("\n\n Tng s nhn vin : " + tongCongDoanVien) .setFont(hfont).setTextAlignment(TextAlignment.LEFT)); document.add(new Paragraph(" Tng cng on ph : " + tienCongDoanPhi).setFont(hfont) .setTextAlignment(TextAlignment.LEFT)); document.add(new Paragraph( "\n\n\n H Ni, ngy thng nm \n Ng?i lp phiu \n ( Ghi r h? tn) ") .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40)); document.close(); } catch (FileNotFoundException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } finally { try { pdfWriter.close(); } catch (IOException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:model.PrintPDF.java
public void thongKeDangPhi(ArrayList<String> listDataTable, String pathName, String nam, String tongDangVien) { PdfWriter pdfWriter = null; try {/* www .j a va 2 s . c o m*/ pdfWriter = new PdfWriter(pathName); PdfDocument pdfDocument = new PdfDocument(pdfWriter); Document document = new Document(pdfDocument, PageSize.A4.rotate()); PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H, true); document.setMargins(50, 50, 50, 50); document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold() .setTextAlignment(TextAlignment.CENTER).setFontSize(16)); document.add(new Paragraph("Thng k ng vin " + " nm " + nam + "\n\n").setFont(hfont) .setBold().setTextAlignment(TextAlignment.CENTER).setFontSize(14)); float[] columnWidths = { 1, 2, 4, 3, 4, 4 }; Table table = new Table(columnWidths); table.setWidthPercent(100); table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold() .setFontSize(14)); table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont) .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("Ngy sinh").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("Chc v ").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("?ng ph ").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); // ni dung ca bng thng k for (int i = 0; i < listDataTable.size(); i++) { table.addCell(new Paragraph(listDataTable.get(i)).setFont(hfont) .setTextAlignment(TextAlignment.CENTER).setFontSize(14)); } document.add(table); document.add(new Paragraph("\n\n Tng s ng vin : " + tongDangVien).setFont(hfont) .setTextAlignment(TextAlignment.LEFT)); document.add(new Paragraph( "\n\n\n H Ni, ngy thng nm \n Ng?i lp phiu \n ( Ghi r h? tn) ") .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40)); document.close(); } catch (FileNotFoundException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } finally { try { pdfWriter.close(); } catch (IOException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:model.PrintPDF.java
public void thongKeTienThi(ArrayList<String> listDataTable, String pathName) { PdfWriter pdfWriter = null; try {// w w w .java2 s .c o m pdfWriter = new PdfWriter(pathName); PdfDocument pdfDocument = new PdfDocument(pdfWriter); Document document = new Document(pdfDocument, PageSize.A4.rotate()); PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H, true); document.setMargins(50, 50, 50, 50); document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold() .setTextAlignment(TextAlignment.CENTER).setFontSize(16)); document.add(new Paragraph("Thng k ti?n thi ging vin " + "\n\n").setFont(hfont).setBold() .setTextAlignment(TextAlignment.CENTER).setFontSize(14)); float[] columnWidths = { 1, 2, 4, 3, 4, 4 }; Table table = new Table(columnWidths); table.setWidthPercent(100); table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold() .setFontSize(14)); table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont) .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("Mn h?c").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("S SV ").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("Ph thi").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); // ni dung ca bng thng k for (int i = 0; i < listDataTable.size(); i++) { table.addCell(new Paragraph(listDataTable.get(i)).setFont(hfont) .setTextAlignment(TextAlignment.CENTER).setFontSize(14)); } document.add(table); document.add(new Paragraph( "\n\n\n H Ni, ngy thng nm \n Ng?i lp phiu \n ( Ghi r h? tn) ") .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40)); document.close(); } catch (FileNotFoundException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } finally { try { pdfWriter.close(); } catch (IOException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:model.PrintPDF.java
public void thongKeThieuNhi(ArrayList<String> listDataTable, String pathName) { PdfWriter pdfWriter = null; try {/*from www .j av a 2 s. c om*/ pdfWriter = new PdfWriter(pathName); PdfDocument pdfDocument = new PdfDocument(pdfWriter); Document document = new Document(pdfDocument, PageSize.A4.rotate()); PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H, true); document.setMargins(50, 50, 50, 50); document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold() .setTextAlignment(TextAlignment.CENTER).setFontSize(16)); document.add(new Paragraph("Thng k cc chu thiu nhi " + "\n\n").setFont(hfont).setBold() .setTextAlignment(TextAlignment.CENTER).setFontSize(14)); float[] columnWidths = { 1, 3, 3, 3, 4 }; Table table = new Table(columnWidths); table.setWidthPercent(100); table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold() .setFontSize(14)); table.addHeaderCell(new Paragraph("H? v tn").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("Ngy sinh ").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER) .setBold().setFontSize(14)); table.addHeaderCell(new Paragraph("H? v tn cn b ").setFont(hfont) .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14)); // ni dung ca bng thng k for (int i = 0; i < listDataTable.size(); i++) { table.addCell(new Paragraph(listDataTable.get(i)).setFont(hfont) .setTextAlignment(TextAlignment.CENTER).setFontSize(14)); } document.add(table); document.add(new Paragraph( "\n\n\n H Ni, ngy thng nm \n Ng?i lp phiu \n ( Ghi r h? tn) ") .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40)); document.close(); } catch (FileNotFoundException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } finally { try { pdfWriter.close(); } catch (IOException ex) { Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex); } } }