List of usage examples for com.itextpdf.text Document Document
public Document()
Document
-object. From source file:com.groupecom2015.entitieManager.MessageFacade.java
public void sendBuyingConfirmationEmail(List<ArticlePanier> listArt, CompteUser cu) { Date d = new Date(System.currentTimeMillis()); Font font = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD); Font font_2 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL); Font font_3 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); double total = 0.0; String resume = ""; try {//w ww .j a va 2 s . c o m // new File( System.getProperty( "user.home" ) +"/"+ cu.getIdCompte()).mkdirs(); //String FILE = System.getProperty("user.home") +"/"+ cu.getIdCompte()+"/commandeRecu.pdf"; new File("/home/umar/webapp_photo/uploads/" + cu.getIdCompte()).mkdirs(); String FILE = "/home/umar/webapp_photo/uploads/" + cu.getIdCompte() + "/commandRecu.pdf"; Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); Paragraph para = new Paragraph(); para.add(new Paragraph(d + "")); para.add(new Paragraph("")); para.add(new Paragraph("Bonjour, " + cu.getNom(), font)); para.add(new Paragraph("Veuillez trouvez ci-dessous votre le rsum de vos achat", font)); para.add(new Paragraph("")); for (ArticlePanier l : listArt) { para.add(new Paragraph( "" + l.getArticle().getNomArticle() + " " + l.getArticle().getPrixVenteArticle(), font_2)); total += l.getArticle().getPrixVenteArticle(); resume = resume + "\n" + l.getArticle().getNomArticle() + " " + l.getArticle().getPrixVenteArticle() + "\n"; } para.add(new Paragraph("Total : " + total, font_3)); para.add(new Paragraph("")); para.add(new Paragraph("Nous vous remercions pour votre achat", font_2)); document.add(para); document.close(); } catch (Exception e) { e.printStackTrace(); } //sending email with the pdf attached --> dropped final String from = "ecomgroup2015@gmail.com"; //ecomgroup2015@gmail.com final String to = "" + cu.getEmail(); final String fileUpload = "/uploads/" + cu.getIdCompte() + "/commandRecu.pdf"; try { Properties properties = new Properties(); properties.put("mail.smtp.host", "smtp.gmail.com"); properties.put("mail.smtp.port", "587"); //587 properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.starttls.enable", "true"); Session session = Session.getInstance(properties, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(from, "groupeecom"); } }); javax.mail.Message message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(to)); message.setSubject("Votre recipiss d'achat"); message.setText("Bonjour " + cu.getNom() + "\n Veuillez trouvez ci-joint votre rsum d'achat\n" + "\n " + resume + " \n" + total); /*BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText("Cher(e) "+cu.getNom()+"\n veuillez trouver ci-joint votre recipiss d'achat"); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); messageBodyPart = new MimeBodyPart(); String filename = "/uploads/"+cu.getIdCompte()+"/commandRecu.pdf"; DataSource source = new FileDataSource(FILE); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(FILE); multipart.addBodyPart(messageBodyPart); // Send the complete message parts message.setContent(multipart);*/ Transport.send(message); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.homecare.bo.EmployeeInfoBOImpl.java
@Scheduled(cron = "0 0 1 * * ?") @Async//from w w w . j a va 2s .c o m public void generatePDFAndEmailForAllActiveEmployees() { System.out.println("************************************Print All the Reminders"); EmployeeInfo employeeInfoRequest = new EmployeeInfo(); employeeInfoRequest.setStatus("A"); List<EmployeeInfo> employeeList = employeeDAO.getAllEmployees(employeeInfoRequest); Map<Long, List<EmployeeInfo>> employeeListMap = getEmployeeListMap(employeeList); for (Long employerId : employeeListMap.keySet()) { List<EmployeeInfo> employees = employeeListMap.get(employerId); Document document = new Document(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { PdfWriter.getInstance(document, out); document.open(); if (null != employees) { for (EmployeeInfo employeeInfo : employees) { List<String> reminders = getRemindersByEmployee(employeeInfo); com.itextpdf.text.List list = new com.itextpdf.text.List(); if (reminders != null && !reminders.isEmpty()) { document.add(new Chunk(employeeInfo.getLastName() + " " + employeeInfo.getFirstName())); for (String reminder : reminders) { // Add the list items to list list.add(new ListItem(reminder)); } document.add(list); document.newPage(); } } } document.close(); List<EmployerEmailInfo> employerEmailList = employerDAO.getAllEmployerEmails(employerId); EmailUtility emailUtility = new EmailUtility(); emailUtility.sendEmailWithAttachment("Reminders of all the employees", employerEmailList, out.toByteArray()); } catch (Exception e) { e.printStackTrace(); } finally { //clean off if (null != out) { try { out.close(); out = null; } catch (Exception ex) { } } } } }
From source file:com.imageConverter.imageConverter.java
public static void main(String[] args) { try {//from w ww . jav a2 s.c o m //Create Document Object Document convertJpgToPdf = new Document(); //Create PdfWriter for Document to hold physical file PdfWriter.getInstance(convertJpgToPdf, new FileOutputStream("C:\\Users\\HARSHVARDHAN.SOLANKI\\Desktop\\ConvertImagetoPDF.pdf")); convertJpgToPdf.open(); //Get the input image to Convert to PDF Image convertJpg = Image.getInstance("C:\\Users\\HARSHVARDHAN.SOLANKI\\Desktop\\text2.jpg"); //Add image to Document convertJpgToPdf.add(convertJpg); //Close Document convertJpgToPdf.close(); System.out.println("Successfully Converted JPG to PDF in iText"); } catch (Exception i1) { i1.printStackTrace(); } }
From source file:com.imipgroup.hieuvt.pdf.PdfUtils.java
public String createPdf(String fileName) { String filePath = "files/Pdf/" + fileName + ".pdf"; Document document = new Document(); try {// w w w . jav a2 s. co m PdfWriter.getInstance(document, new FileOutputStream(filePath)); document.open(); addMetaData(document); addTitlePage(document); addContent(document); document.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } return filePath; }
From source file:com.imipgroup.hieuvt.pdf.PdfUtils.java
public Document readPdf(String inputPath) { String outputPath = "files/Pdf/testRead.pdf"; Document document = new Document(); PdfWriter writer = null;/*from w ww.jav a 2 s . co m*/ try { writer = PdfWriter.getInstance(document, new FileOutputStream(outputPath)); document.open(); PdfReader reader = new PdfReader(inputPath); int n = reader.getNumberOfPages(); PdfImportedPage page; // Go through all pages for (int i = 1; i <= n; i++) { // only page number 2 will be included if (i == 2) { page = writer.getImportedPage(reader, i); Image instance = Image.getInstance(page); document.add(instance); } } document.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return document; }
From source file:com.innoq.iQpdfutil.Main.java
License:Open Source License
/** * This method produces a new pdf that is written to the output stream. * * <p>/*from w w w . j a va 2s . com*/ * The newly created pdf contains all the pages of all the provided * input pdf files in the right order. Where necessary empty pages * ensure that the pages of every input pdf begin on an odd page. * </p> * */ public static void concatPDFs(Readers readers, OutputStream os) throws DocumentException, IOException { Document document = new Document(); PdfCopy copy = new PdfCopy(document, os); document.open(); for (PdfReader reader : readers) { copyPages(reader, copy); } document.close(); }
From source file:com.insider.kontrollactive.QualityReportActivity.java
public void create(View view) throws Exception { try {/*from w ww . j av a2 s . c o 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(); } EmailGenerator gen = new EmailGenerator(this, cust, date, msg, emailList, attachement, type, Globals.user.getId()); gen.sendEmail(); }
From source file:com.insider.kontrollkunde.QualityReportActivity.java
public void create(View view) throws Exception { Log.d("!!pdf", dir.getAbsolutePath()); try {/*from w w w . j a v a 2 s. c o 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(); } EmailGenerator gen = new EmailGenerator(this, cust, date, msg, emailList, attachement); gen.sendEmail(); }
From source file:com.iox.rms.mbean.UserBean.java
@SuppressWarnings("deprecation") private byte[] generateInvoiceForCustomerPurchase(CustomerProduct cp) { byte[] data = null; if (cp != null) { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {/* w w w . java2s . c o m*/ PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new HeaderFooter()); writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788)); if (!document.isOpen()) { document.open(); } document.setPageSize(PageSize.A4); document.addAuthor("AutoLife"); document.addCreationDate(); document.addCreator("AutoLife"); document.addSubject("Invoice"); document.addTitle("Purchase Invoice"); PdfPTable headerTable = new PdfPTable(3); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance() .getExternalContext().getContext(); String logo = servletContext.getRealPath("") + File.separator + "images" + File.separator + "sattrak-logo.png"; PdfPCell c = new PdfPCell(Image.getInstance(logo)); c.setBorder(0); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerTable.addCell(c); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD); c = new PdfPCell(new Paragraph("INVOICE", font)); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); font = new Font(helvetica, 10, Font.NORMAL | Font.BOLD); c = new PdfPCell(new Paragraph("TRANSACTION REF. NO.: " + cp.getPurchaseTranRef(), font)); c.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); c.setBorder(0); headerTable.addCell(c); document.add(headerTable); font = new Font(helvetica, 12, Font.NORMAL | Font.BOLD); Paragraph p = new Paragraph("DETAILS", font); p.setAlignment(Paragraph.ALIGN_CENTER); document.add(p); PdfPTable pdfTable = new PdfPTable(3); font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("INITIATED DATE", font)); pdfTable.addCell(new Paragraph("PRODUCT", font)); pdfTable.addCell(new Paragraph("AMOUNT", font)); font = new Font(helvetica, 8, Font.NORMAL); pdfTable.addCell( new Paragraph(cp.getPurchaseTransaction().getTranInitDate().toLocaleString(), font)); pdfTable.addCell(new Paragraph(cp.getProductBooked().getDetails(), font)); pdfTable.addCell(new Paragraph("" + cp.getPurchasedAmount(), font)); document.add(pdfTable); document.close(); data = baos.toByteArray(); } catch (Exception ex) { ex.printStackTrace(); } } return data; }
From source file:com.jslsolucoes.tagria.lib.grid.exporter.impl.PdfExporter.java
License:Apache License
public void doExport(OutputStream out) throws DocumentException { Document document = new Document(); PdfWriter.getInstance(document, out); document.open();/*w ww .ja v a 2 s. c o m*/ PdfPTable pdf = new PdfPTable(table.getHeaders().size()); pdf.setWidthPercentage(100); title(pdf); header(pdf); body(pdf); document.add(pdf); document.close(); }