List of usage examples for com.itextpdf.layout Document setMargins
public void setMargins(float topMargin, float rightMargin, float bottomMargin, float leftMargin)
From source file:com.isw.cec.Servlet.GenerarFoliosServlet.java
License:Open Source License
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String appPath = request.getServletContext().getRealPath(""); String savePath = appPath + File.separator + SAVE_DIR; File fileSaveDir = new File(savePath); if (!fileSaveDir.exists()) fileSaveDir.mkdirs();//from ww w.ja v a 2 s . c om String fileName = java.util.UUID.randomUUID().toString() + ".pdf"; Curso curso = (Curso) request.getAttribute("curso"); List<Entry<String, String>> alum_fol = Reader.getAlumFolios(curso.getID()); OutputStream fos = new FileOutputStream(savePath + File.separator + fileName); PdfWriter writer = new PdfWriter(fos); PdfDocument pdf = new PdfDocument(writer); Document document = new Document(pdf, PageSize.A4); document.setMargins(85, 57, 71, 71); PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN); PdfFont bold = PdfFontFactory.createFont(FontConstants.TIMES_BOLD); Paragraph p = new Paragraph("Folios de los alumnos inscritos al curso"); p.setTextAlignment(TextAlignment.CENTER); document.add(p); p = new Paragraph(curso.getNombre()); p.setFont(bold); p.setTextAlignment(TextAlignment.CENTER); p.setMarginBottom(70); document.add(p); Table table = new Table(new float[] { 1, 1 }); table.setWidthPercent(100); Cell c = new Cell().add(new Paragraph("ALUMNO").setFont(bold)); c.setTextAlignment(TextAlignment.CENTER); table.addHeaderCell(c); c = new Cell().add(new Paragraph("FOLIO").setFont(bold)); c.setTextAlignment(TextAlignment.CENTER); table.addHeaderCell(c); for (Entry<String, String> e : alum_fol) { table.addCell(new Cell().add(new Paragraph(e.getKey()).setFont(font))); table.addCell(new Cell().add(new Paragraph(e.getValue()).setFont(font))); } document.add(table); document.close(); Writer.openCurso(curso.getID(), fileName); response.getWriter().println("OK"); }
From source file:machinetoolstore.core.util.PdfGenerator.java
public static boolean getGeneratedPdfByArtifact(ThreeRollMill artifact, String fileName) throws Exception { PdfWriter writer = new PdfWriter(GENERATED_FILES_PATH + fileName); PdfDocument pdfDocument = new PdfDocument(writer); Document document = new Document(pdfDocument, PageSize.A4); document.setMargins(15, 15, 15, 40); PdfFont mainFont = PdfFontFactory.createFont(FONTS_PATH + "calibril.ttf", "cp1251", false); //Header/*w w w . j a v a2s. com*/ Paragraph headerParagraph = new Paragraph(artifact.getBrand() + " " + artifact.getModel()); headerParagraph.setItalic(); headerParagraph.setTextAlignment(TextAlignment.CENTER); headerParagraph.setFont(mainFont); headerParagraph.setFontSize(20); document.add(headerParagraph); //Image block witch characteristic Table table = new Table(3); table.setWidthPercent(100); //Image cell Cell imageCell = new Cell(); imageCell.setBorder(Border.NO_BORDER); Image machineImage = new Image(ImageDataFactory.create(IMAGE_PATH + artifact.getMainPhoto())); machineImage.setWidth(100); machineImage.setHeight(100); imageCell.add(machineImage); //Main characteristic cell Cell mainCharacteristicCell = new Cell(); List mainCharacteristicList = new List().setSymbolIndent(5).setListSymbol("\uFFFF").setFont(mainFont) .setFontSize(12); mainCharacteristicList.add("ID:").add(":").add(" ?:") .add("?:").add("??:").add(", $:"); mainCharacteristicCell.add(mainCharacteristicList); Cell valuesCell = new Cell(); List valuesList = new List().setSymbolIndent(5).setListSymbol("\uFFFF").setFont(mainFont).setFontSize(12); valuesList.add(artifact.getId().toString()).add(artifact.getManufacturer()) .add(artifact.getYearOfIssue().toString()).add(artifact.getLocation()) .add(artifact.getMachineState()).add(artifact.getMachinePrice().toString()); valuesCell.add(valuesList); table.addCell(imageCell); table.addCell(mainCharacteristicCell); table.addCell(valuesCell); //Paragraph Paragraph contentParagraph = new Paragraph("? ?"); contentParagraph.setItalic(); contentParagraph.setTextAlignment(TextAlignment.CENTER); contentParagraph.setFont(mainFont); contentParagraph.setFontSize(14); contentParagraph.setFixedPosition(1, 635, 600); document.add(contentParagraph); //Main table Table mainTable = new Table(2); mainTable.setFont(mainFont); mainTable.setFontSize(10); mainTable.setMarginTop(35); mainTable.addCell(" ?").addCell(artifact.getType()); mainTable.addCell(" , ") .addCell(artifact.getMaterialThickness().toString()); mainTable.addCell(" , ").addCell(artifact.getMaterialWidth().toString()); mainTable.addCell("? , /").addCell(artifact.getBendingSpeed().toString()); mainTable.addCell("Min max ?, ") .addCell(artifact.getMinDiameterMaxBend().toString()); mainTable.addCell(" , ") .addCell(artifact.getTopRollDiameter().toString()); mainTable.addCell(" ? , ") .addCell(artifact.getMiddleRollDiameter().toString()); mainTable.addCell("??? ? , ") .addCell(artifact.getDistanceOfBottomTwoRolls().toString()); mainTable.addCell( "? ? ? ?, ") .addCell(artifact.getMaterialProofStress().toString()); mainTable.addCell("? ?, ") .addCell(artifact.getMainEnginePower().toString()); mainTable.addCell(" , ").addCell(artifact.getMachineDimensions()); mainTable.addCell("? ?, ").addCell(artifact.getMachineWeight().toString()); mainTable.addCell("?").addCell(artifact.getDescription()); document.add(table); document.add(mainTable); document.close(); return true; }
From source file:model.PrintPDF.java
public void inThongKeCanBo(ArrayList<CanBo> listCanBo, String pathName, String nam, int gt, String tongNhanVien, String soNVVH) {//www . j a va 2s. c o 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 . j a v a 2 s . c o m 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;// w ww . j a va2s .c o m 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 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;//from ww w.ja v a 2 s . c o m 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 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;/* w w w . j a v a 2s.c om*/ 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 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;//from ww w. jav a 2 s .com 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 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); } } }
From source file:wbs.jsf1.pdf.LottoReceiptBean0.java
public byte[] createPdfFrom(Lottoschein lottoschein) { try {//from www . j a va 2 s . c o m zahlen = lottoschein; ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); PdfWriter writer = new PdfWriter(pdfStream); PdfDocument pdf = new PdfDocument(writer); PageSize pageSize = new PageSize(PageSize.A6); Document document = new Document(pdf, pageSize); document.setMargins(20, 20, 40, 20); PdfFont font = PdfFontFactory.createFont(FontConstants.HELVETICA); PdfFont bold = PdfFontFactory.createFont(FontConstants.HELVETICA_BOLD); // Header document.add(getHeaderTable()); // Lottozahlen auflisten document.add(getZiehungsDatenTable(font, bold)); // Losnummer document.add(getLosnummerTable(font, bold)); // Spieltage document.add(getSpieltageTable(font, bold)); // Laufzeit document.add(getLaufzeitTable(font, bold)); // Betrag document.add(getBetragTable(font, bold)); document.close(); LOG.log(Level.INFO, "PDF succesfully created."); return pdfStream.toByteArray(); } catch (IOException ex) { Logger.getLogger(LottoReceiptBean0.class.getName()).log(Level.SEVERE, "pdf creation problem", ex); } return null; }