List of usage examples for com.itextpdf.text Document Document
public Document()
Document
-object. From source file:com.leenmeij.app.utils.CreatePdf.java
/** * Creates the document//from w w w. j ava2s . c o m * @param invoice */ public void createPdf(Invoice invoice) { // Declare a document Document document = new Document(); try { // Create an instance PdfWriter.getInstance(document, new FileOutputStream( fileLocation + invoice.getStartdate() + "-" + invoice.getReservation_id() + ".pdf")); // Create the document document.open(); // Add the content contentPage(document, invoice); // Close the document document.close(); } catch (FileNotFoundException | DocumentException e) { e.printStackTrace(); } }
From source file:com.linksinnovation.elearning.utils.ppt2pdf.Ppt2Pdf.java
public static void convert(FileInputStream inputStream, FileOutputStream out) throws IOException, DocumentException { XMLSlideShow ppt = new XMLSlideShow(inputStream); inputStream.close();//from w w w . j a v a2 s.co m Dimension pgsize = ppt.getPageSize(); Document document = new Document(); PdfWriter pdfWriter = PdfWriter.getInstance(document, out); document.setPageSize(new Rectangle((float) pgsize.getWidth(), (float) pgsize.getHeight())); document.open(); for (XSLFSlide slide : ppt.getSlides()) { System.out.println(pgsize.getWidth() + " " + pgsize.getHeight()); PdfGraphics2D graphics = (PdfGraphics2D) pdfWriter.getDirectContent() .createGraphics((float) pgsize.getWidth(), (float) pgsize.getHeight()); slide.draw(graphics); graphics.dispose(); document.newPage(); } document.close(); }
From source file:com.microware.intrahealth.Createpdfall.java
@SuppressLint("SdCardPath") public boolean write(String fname, String[] Header1, String[] Page1, String[] Page1Value, String heading1, String Page1Remark,/* w w w . j av a 2 s .c o m*/ String[] Header2, String[] Page2_1, String[] Page2_1source, String[] Page2_1value, String[] Page2_2, String[] Page2_2source, String[] Page2_2value, String[] Page2_3, String[] Page2_3source, String[] Page2_3value, String heading2, String heading3, String heading4, String heading5, String Remark2Value, String[] Header3, String[] Page31, String[] Page3Census1, String[] Page3Value1, String[] Page32, String[] Page3Census2, String[] Page3Value2, String heading6, String heading7, String heading8, String Page3Remark, String[] Header4, String[] Page4_1, String[] Page4Value1, String[] Page4_2, String[] Page4Value2, String[] Page4_3, String[] Page4Value3, String heading9, String heading10, String heading11, String heading12, String Page4Remark1, String Page4Remark3, String[] Header5, String[] Page5Value1, String[] Page5Value2, String[] Page5Value3, String[] Page5Value4, String[] Page5_2, String[] Page5Value5, String[] Page5_3, String[] Page5Value6, String text5, String value5, String heading13, String heading14, String heading15, String Page5Remark1, String Page5Remark2, String[] Header6, String[] Page6Value1, String[] Page6Value2, String[] Page6Value3, String[] Page6Value4, String text6, String value6, String heading16, String[] Header7_1, String[] Page7Value1, String[] Page7Value2, String[] Page7Value3, String[] Page7Value4, String[] Page7Value5, String[] Header7_2, String[] Page7Value6, String[] Page7Value7, String[] Page7Value8, String[] Page7Value9, String[] Page7Value10, String[] Page7Value11, String text7_1, String value7_1, String text7_2, String value7_2, String heading17, String heading18, String heading19, String pdf1, String pdf2, int Flag) throws Exception { try { // file = new File(Environment.getExternalStorageDirectory()+IIHSPdf+ "/"+fname+".pdf"); BaseFont urName = BaseFont.createFont("assets/baamini.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); urFontName = new Font(urName, 12); catFont2 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, new BaseColor(0, 85, 133)); if (Flag == 2) { catFont = new Font(urName, 16, Font.BOLD); catFont1 = new Font(urName, 16, Font.BOLD, new BaseColor(0, 85, 133)); subFont = new Font(urName, 14); smallBold = new Font(urName, 12, Font.BOLD, BaseColor.WHITE); } else { catFont = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD); catFont1 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, new BaseColor(0, 85, 133)); subFont = new Font(Font.FontFamily.TIMES_ROMAN, 14); smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, BaseColor.WHITE); } String fpath = "/sdcard/IIHS/Pdfs"; File path = new File(fpath); File file = new File(path, fname + ".pdf"); if (!path.exists()) { path.mkdirs(); if (!file.exists()) { file.createNewFile(); } } else { if (!file.exists()) { file.createNewFile(); } } // Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); // Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 12); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(file.getAbsoluteFile())); document.open(); // addMetaData(document); // addTitlePage(document); addContent(document, Header1, Page1, Page1Value, heading1, Page1Remark, Header2, Page2_1, Page2_1source, Page2_1value, Page2_2, Page2_2source, Page2_2value, Page2_3, Page2_3source, Page2_3value, heading2, heading3, heading4, heading5, Remark2Value, Header3, Page31, Page3Census1, Page3Value1, Page32, Page3Census2, Page3Value2, heading6, heading7, heading8, Page3Remark, Header4, Page4_1, Page4Value1, Page4_2, Page4Value2, Page4_3, Page4Value3, heading9, heading10, heading11, heading12, Page4Remark1, Page4Remark3, Header5, Page5Value1, Page5Value2, Page5Value3, Page5Value4, Page5_2, Page5Value5, Page5_3, Page5Value6, text5, value5, heading13, heading14, heading15, Page5Remark1, Page5Remark2, Header6, Page6Value1, Page6Value2, Page6Value3, Page6Value4, text6, value6, heading16, Header7_1, Page7Value1, Page7Value2, Page7Value3, Page7Value4, Page7Value5, Header7_2, Page7Value6, Page7Value7, Page7Value8, Page7Value9, Page7Value10, Page7Value11, text7_1, value7_1, text7_2, value7_2, heading17, heading18, heading19, pdf1, pdf2, Flag); document.close(); return true; } catch (IOException e) { e.printStackTrace(); return false; } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } }
From source file:com.mobicage.rogerthat.enterprise.samples.hr.bizz.GenerateExpenseNote.java
License:Open Source License
public int handle(final User user, final User manager, final ExpenseNote en) throws MalformedURLException, IOException, DocumentException { log.info("Building list of expenses ..."); List<Expense> expenses = Expense.list(en); log.info("Retrieved " + expenses.size() + " expenses from the datastore"); log.info("Creating ExpenseNoteDocOutputStream"); ExpenseNoteDocOutputStream stream = new ExpenseNoteDocOutputStream(en); Document document = new Document(); PdfWriter.getInstance(document, stream); document.open();//from www . ja v a 2s.c o m document.addTitle("Expense note " + en.id + " of " + user.name); document.addSubject("Expense note generated by Rogerthat Enterprise!"); document.addKeywords("expense note"); document.addAuthor(user.name); document.addCreator("Rogerthat OneApp Enterprise Mobility"); Paragraph preface = new Paragraph(); preface.add(new Paragraph("TP Vision expense note", titleFont)); preface.add(new Paragraph(" ")); DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy"); Date date = new Date(); preface.add(new Paragraph("Date: " + dateFormat.format(date))); preface.add(new Paragraph("Requestor: " + user.name)); preface.add(new Paragraph("Approver: " + manager.name)); preface.add(new Paragraph(" ")); PdfPTable table = new PdfPTable(7); table.setWidthPercentage(110); table.setWidths(new int[] { 5, 15, 15, 35, 10, 15, 10 }); addHeader(table, "Id"); addHeader(table, "Date"); addHeader(table, "Nature"); addHeader(table, "Description"); addHeader(table, "Account"); addHeader(table, "Amount"); addHeader(table, "Voucher"); table.setHeaderRows(1); Collections.sort(expenses, new Comparator<Expense>() { @Override public int compare(Expense e1, Expense e2) { return (int) (e1.date - e2.date); } }); int i = 0; double total = 0; for (Expense expense : expenses) { PdfPCell c1 = new PdfPCell(new Phrase("" + ++i)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.addCell(dateFormat.format(new Date(expense.date * 1000))); table.addCell(expense.nature); table.addCell(expense.description); table.addCell("" + expense.account); c1 = new PdfPCell(new Phrase(DECIMAL_FORMAT.format(expense.amount) + " " + expense.currency)); c1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(c1); table.addCell(expense.voucher); total += expense.amount; } preface.add(table); preface.add(new Paragraph(" ")); preface.add(new Paragraph("Total: " + DECIMAL_FORMAT.format(total), titleFont)); document.add(preface); i = 0; for (Expense expense : expenses) { i++; if (expense.receipt == null) continue; document.newPage(); Paragraph receipt = new Paragraph(); receipt.add(new Paragraph("Attachment " + i, titleFont)); document.add(receipt); Image image = Image.getInstance(new URL(expense.receipt)); image.setRotationDegrees(-90); float scaler = (document.getPageSize().getWidth() / image.getWidth()) * 100; image.scalePercent(scaler); document.add(image); } document.close(); stream.close(); return stream.getSize(); }
From source file:com.multixsoft.hospitapp.utilities.ReportGenerator.java
/** * Metodo que crea el reporte, lo inicializa y manda llamar a un metodo que lo llene de informacin * @param r representa al reporte que ser generado * @return una variable booleana que indica si el reporte se pudo crear con xito o no *//*w w w .j a v a 2 s. co m*/ public boolean createReport(Report r) { boolean resultado = false; try { reporte = new Document(); PdfWriter.getInstance(reporte, new FileOutputStream(pathPDF)); resultado = addInformation(r.getIdAppointment().getPatientNss().getFirstName(), r.getIdAppointment().getPatientNss().getLastName(), r.getIdAppointment().getDoctorUsername().getFirstName(), r.getIdAppointment().getDate(), r.getDescription(), r.getMedicine(), r.getIndications()); } catch (FileNotFoundException fnfe) { fnfe.printStackTrace(); } catch (DocumentException de) { de.printStackTrace(); } return resultado; }
From source file:com.myapp.struts.transaction.transactionAction.java
public ActionForward generatememberreport(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws SQLException, Exception { if (Constants.isSessionActive(request)) { transactionForm transactionForm = (transactionForm) form; try {/*from w w w . ja v a 2s . com*/ Date utilDate = new Date(); java.sql.Date date = new java.sql.Date(utilDate.getTime()); Font bigFont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 12, Font.BOLD, BaseColor.BLACK); Font bigFont_Uderline = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 12, Font.BOLD | Font.UNDERLINE, BaseColor.BLACK); Font boldfont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 9, Font.BOLD); Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); //Or whatever format fits best your needs. Paragraph para1 = new Paragraph("PALKE JEWELLERS", bigFont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); para1 = new Paragraph("MEMBER ACCOUNT DETAILS", bigFont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); para1 = new Paragraph(transactionForm.getSelectedmember(), boldfont); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph( transactionForm.getMemberaddress() + "\n" + transactionForm.getMembercontactno(), boldfont); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); Groups obj = (Groups) hmGroups.get(transactionForm.getGroupid() + ""); if (obj != null) { para1 = new Paragraph("Group : " + obj.getGroupname(), font); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Paid Amount : " + transactionForm.getTotalpaidamount(), font); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Prize Amount : " + transactionForm.getDrawamount(), font); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Total Amount : " + transactionForm.getTotalamount(), boldfont); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Status : " + transactionForm.getStatus(), boldfont); para1.setAlignment(Element.ALIGN_RIGHT); document.add(para1); if (transactionForm.getStatus().equalsIgnoreCase("Settled")) { para1 = new Paragraph(transactionForm.getSettlementcomment(), boldfont); para1.setAlignment(Element.ALIGN_RIGHT); document.add(para1); } String dateStr = sdf.format(date); para1 = new Paragraph("DATED:" + dateStr, font); para1.setAlignment(Element.ALIGN_RIGHT); document.add(para1); // add a couple of blank lines document.add(Chunk.NEWLINE); if (transactionForm.getLstPayment() != null && transactionForm.getLstPayment().size() > 0) { PdfPTable table2 = new PdfPTable(7); float[] columnWidths = { 1.5f, 1.5f, 3f, 4f, 4f, 7f, 2f }; table2.setWidthPercentage(100); table2.setWidths(columnWidths); para1 = new Paragraph("Sl No.", font); para1.setAlignment(Element.ALIGN_CENTER); PdfPCell cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Term", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Receipt No.", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Receipt Date", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Payment Mode", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Remarks", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Paid Amount", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); int x = 1; double total = 0; //Iterator it = hmPayments.entrySet().iterator(); //while (it.hasNext()) { if (hmPayments.size() > 0) { for (int i = 1; i <= obj.getNoofinstallment(); i++) { //float f = columnWidths[i]; Payment f1 = (Payment) hmPayments.get(i + ""); //} //Map.Entry pairs = (Map.Entry) it.next(); //Payment f1 = (Payment) pairs.getValue(); String term = i + ""; para1 = new Paragraph(Integer.toString(x), font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); x++; para1 = new Paragraph(term, font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(f1.getPaymentid() + "", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(sdf.format(f1.getPaiddate()), font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(f1.getPaymentmode() == 1 ? "Cash" : "Cheque/NEFT", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(f1.getRemarks(), font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); //para1 = new Paragraph(f1.getPaidamount() + "", boldfont); para1 = new Paragraph((int) obj.getInstallmentamount() + "", boldfont); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); total = total + obj.getInstallmentamount(); if (hmPayments.size() == i) { break; } } para1 = new Paragraph("Total", boldfont); para1.setAlignment(Element.ALIGN_LEFT); cell = new PdfPCell(para1); cell.setColspan(6); table2.addCell(cell); //String numberStr = String.format("%.2f", total + ""); para1 = new Paragraph(total + "", boldfont); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); //cell.setColspan(7); table2.addCell(cell); table2.setHorizontalAlignment(Element.ALIGN_LEFT); document.add(table2); } else { para1 = new Paragraph("NO PAYMENTS FOUND", boldfont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); } } else { para1 = new Paragraph("NO RECORDS FOUND", boldfont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); } document.add(Chunk.NEWLINE); //document.close(); //fileInputStream = new FileInputStream(new File("C:\\reports\\PaymentReports.pdf")); document.close(); ServletOutputStream outputStream = response.getOutputStream(); baos.writeTo(outputStream); response.setHeader("Content-Disposition", "attachment; filename=\"PaymentStatusReport.pdf\""); response.setContentType("application/pdf"); outputStream.flush(); outputStream.close(); return mapping.findForward("display"); } else { para1 = new Paragraph("NO RECORDS FOUND", boldfont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); document.close(); ServletOutputStream outputStream = response.getOutputStream(); baos.writeTo(outputStream); response.setHeader("Content-Disposition", "attachment; filename=\"PaymentStatusReport.pdf\""); response.setContentType("application/pdf"); outputStream.flush(); outputStream.close(); return mapping.findForward("display"); } } catch (DocumentException i) { System.out.println(i); return mapping.findForward("fail"); } catch (IOException i) { System.out.println(i); return mapping.findForward("fail"); } } else { return mapping.findForward("exp"); } }
From source file:com.mycom.products.mywebsite.backend.util.DownloadHandler.java
License:Open Source License
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET) protected final void downloadUserInformation(@PathVariable int id, HttpServletRequest request, final HttpServletResponse response) throws ServletException, BusinessException, DocumentException { UserBean user = userService.select(id, FetchMode.EAGER); if (user == null) { return;/* w w w. j a v a2 s .c o m*/ } Document document = new Document(); document.setMargins(70, 70, 20, 20); try { response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment; filename=\"" + user.getName() + "_profile.pdf\""); PdfWriter.getInstance(document, response.getOutputStream()); document.open(); Image profileImage = null; try { profileImage = Image.getInstance(user.getContent().getFilePath()); } catch (Exception e) { // e.printStackTrace(); } if (profileImage != null) { profileImage.setAlignment(Image.MIDDLE | Image.TEXTWRAP); profileImage.setBorder(Image.BOX); profileImage.setBorderWidth(5); BaseColor bgcolor = WebColors.getRGBColor("#E5E3E3"); profileImage.setBorderColor(bgcolor); profileImage.scaleToFit(100, 100); document.add(profileImage); } document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); // Adding Table Data PdfPTable table = new PdfPTable(2); // 2 columns. table.setWidthPercentage(100); // Width 100% table.setSpacingBefore(15f); // Space before table table.setSpacingAfter(15f); // Space after table // Set Column widths float[] columnWidths = { 1f, 2f, }; table.setWidths(columnWidths); // Name setTableHeader("Name", table); setTableContent(user.getName(), table); // Gender setTableHeader("Gender", table); String gender = "Male"; if (user.getGender() == Gender.FEMALE) { gender = "Female"; } setTableContent(gender, table); // Age setTableHeader("Age", table); setTableContent("" + user.getAge(), table); // Date of Birth setTableHeader("DOB", table); DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); setTableContent(dateFormatter.format(user.getDob()), table); // Email setTableHeader("Email", table); setTableContent(user.getEmail(), table); // NRC setTableHeader("NRC", table); setTableContent(user.getNrc(), table); // Phone setTableHeader("Phone", table); setTableContent(user.getPhone(), table); // Roles String roleStr = ""; List<RoleBean> roles = user.getRoles(); if (roles != null && roles.size() > 0) { Iterator<RoleBean> itr = roles.iterator(); while (itr.hasNext()) { RoleBean role = itr.next(); roleStr += role.getName(); if (itr.hasNext()) { roleStr += ","; } } } setTableHeader("Role(s)", table); setTableContent(roleStr, table); // Address setTableHeader("Address", table); setTableContent(user.getAddress(), table); document.add(table); document.add(new Paragraph(new Date().toString())); } catch (Exception e) { e.printStackTrace(); } document.close(); }
From source file:com.mycompany.bandaru_exam.accountDriver.java
/** * @param args the command line arguments *//*from ww w .ja v a 2s .c o m*/ public static void main(String[] args) throws FileNotFoundException, DocumentException, BadElementException, IOException { // TODO code application logic here ReadfromExcel rd = new ReadfromExcel(); List<Account> accountList = rd.getAccountListFromExcel(); for (Account a : accountList) { System.out.println(a.getFirstName()); OutputStream file = new FileOutputStream(new File(a.getLastName() + ".pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); //Inserting Image in PDF Image image = Image.getInstance("logo.png"); image.scaleAbsolute(600f, 100f);//image width,height //Now Insert Every Thing Into PDF Document document.open();//PDF document opened........ document.add(image); document.add(new Paragraph("Welcome! " + a.getFirstName() + " " + a.getLastName() + "!")); document.add(new Paragraph(" ")); document.add(new Paragraph(" " + "Below are your Account Details :")); document.add(new Paragraph(" " + "First Name:" + a.getFirstName())); document.add(new Paragraph(" " + "Last Name:" + a.getLastName())); document.add(new Paragraph(" " + "Account Number:" + a.getAccNumber())); document.add(new Paragraph(" " + "Account Balance:$" + a.getBalance())); document.close(); file.close(); } }
From source file:com.mycompany.mavenproject1.Createpdf.java
public void createPDF(String pdfFilename) { Document doc = new Document(); PdfWriter docWriter = null;// ww w.j a v a2 s. com initializeFonts(); try { String path = "C:\\Users\\Thaskioglu\\Downloads\\" + pdfFilename; docWriter = PdfWriter.getInstance(doc, new FileOutputStream(path)); doc.addAuthor("FabulousCar"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("FabulousCar"); doc.addTitle("Invoice"); doc.setPageSize(PageSize.LETTER); doc.open(); PdfContentByte cb = docWriter.getDirectContent(); boolean beginPage = true; int y = 0; for (int i = 0; i < 100; i++) { if (beginPage) { beginPage = false; generateLayout(doc, cb); generateHeader(doc, cb); y = 615; } generateDetail(doc, cb, i, y); y = y - 15; if (y < 50) { printPageNumber(cb); doc.newPage(); beginPage = true; } } printPageNumber(cb); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } finally { if (doc != null) { doc.close(); } if (docWriter != null) { docWriter.close(); } } }
From source file:com.mycompany.mavenproject1.HelloWorld.java
/** * Creates a PDF document.// ww w . j av a 2 s . c om * @param filename the path to the new PDF document * @throws DocumentException * @throws IOException */ public void createPdf(String filename) throws DocumentException, IOException { // step 1 Document document = new Document(); // step 2 PdfWriter.getInstance(document, new FileOutputStream(filename)); // step 3 document.open(); // step 4 document.add(new Paragraph("Hello World!")); // step 5 document.close(); }