Example usage for com.itextpdf.text.pdf PdfWriter getInstance

List of usage examples for com.itextpdf.text.pdf PdfWriter getInstance

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfWriter getInstance.

Prototype


public static PdfWriter getInstance(final Document document, final OutputStream os) throws DocumentException 

Source Link

Document

Use this method to get an instance of the PdfWriter.

Usage

From source file:com.gp.cong.logisoft.lcl.report.LclConsolidationMiniManifestPdfCreator.java

public void createReport(String realPath, String reportLocation, String documentName, String fileId)
        throws FileNotFoundException, DocumentException, Exception {
    LCLBlDAO lCLBlDAO = new LCLBlDAO();
    document = new Document(PageSize.LEGAL.rotate());
    pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(reportLocation));
    bl = lCLBlDAO.getByProperty("lclFileNumber.id", Long.parseLong(fileId));
    lCLBlDAO.getCurrentSession().evict(bl);
    ruleName = bl.getLclFileNumber().getBusinessUnit();
    Long fileid = Long.parseLong(fileId);
    setValues(bl, fileid);/*from  w  ww. ja  v  a2s .  com*/
    LclConsolidationMiniManifestPdfCreator.LclConsolidationMiniManifestPageEvent event = new LclConsolidationMiniManifestPdfCreator.LclConsolidationMiniManifestPageEvent();
    pdfWriter.setPageEvent(event);
    document.open();
    document.add(consigneeTable());
    document.add(consolidateTable(fileId));
    document.close();
}

From source file:com.gp.cong.logisoft.lcl.report.LclConsolidationMiniManifestPdfCreator.java

public String createEmailReport(String realPath, String outputFileName, ExportVoyageHblBatchForm batchForm)
        throws Exception {
    List<Long> actualDrList = new ArrayList<Long>();
    boolean isConsolidate = false;
    if (CommonUtils.isNotEmpty(batchForm.getFileNumberId())) {
        actualDrList.add(Long.parseLong(batchForm.getFileNumberId()));
    } else {//from   w  ww  .j  a va  2 s . c o  m
        actualDrList = new ExportUnitQueryUtils().getAllPickedCargoBkg(Long.parseLong(batchForm.getHeaderId()),
                Long.parseLong(batchForm.getUnitSSId()));
    }
    if (CommonUtils.isNotEmpty(actualDrList)) {
        for (Long fileId : actualDrList) {
            isConsolidate = new LclConsolidateDAO().isConsoildateFile(String.valueOf(fileId));
            if (isConsolidate) {
                LCLBlDAO lCLBlDAO = new LCLBlDAO();
                bl = lCLBlDAO.getByProperty("lclFileNumber.id", fileId);
                lCLBlDAO.getCurrentSession().evict(bl);
                ruleName = bl.getLclFileNumber().getBusinessUnit();
                setValues(bl, fileId);
                if (!isNew) {
                    document = new Document(PageSize.LEGAL.rotate());
                    pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(outputFileName));
                    LclConsolidationMiniManifestPdfCreator.LclConsolidationMiniManifestPageEvent event = new LclConsolidationMiniManifestPdfCreator.LclConsolidationMiniManifestPageEvent();
                    pdfWriter.setPageEvent(event);
                    document.open();
                }
                if (!documentOpenFlag) {
                    documentOpenFlag = true;
                    isNew = true;
                    document.add(consigneeTable());
                    document.add(consolidateTable(String.valueOf(fileId)));
                } else {
                    document.newPage();
                    document.add(consigneeTable());
                    document.add(consolidateTable(String.valueOf(fileId)));
                }
            }
        }
    }
    if (documentOpenFlag) {
        document.close();
    } else {
        outputFileName = null;
    }
    return outputFileName;

}

From source file:com.gp.cong.logisoft.lcl.report.LclVoyageNotificationPdfCreator.java

public void createPdf(String contextPath, String outputFileName, String unitssId, String voyContent)
        throws Exception {
    LclUnitSs lclUnitSs = new LclUnitSsDAO().findById(Long.parseLong(unitssId));
    String voyageNo = lclUnitSs.getLclSsHeader().getScheduleNo();
    String unitNo = lclUnitSs.getLclUnit().getUnitNo();
    document = new Document();
    document.setPageSize(PageSize.A4);//from ww  w  .java  2s . co  m
    document.setMargins(8, 2, 8, 8);
    pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(outputFileName));
    document.open();
    document.add(onStartPage(contextPath, voyageNo, unitNo, voyContent));
    document.add(voyInfo(lclUnitSs));
    document.add(unitInfo(lclUnitSs));
    document.add(dispoInfo(lclUnitSs));
    document.add(voyContent(voyContent));
    document.add(thankyouMsg(contextPath));
    document.close();
}

From source file:com.gp.cong.logisoft.reports.DeliveryOrderPdfCreator.java

public void initialize(String fileName, FclBl bl) throws FileNotFoundException, DocumentException, Exception {
    document = new Document(PageSize.A4);
    document.setMargins(4, 4, 4, 4);/*  w w w  .  ja  v  a 2s  . c o m*/
    pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(fileName));
    document.open();
}

From source file:com.gp.cong.logisoft.reports.LclExportVoyageNotificationPdf.java

public void createPdf(String realPath, String outputFileName, Long notificationId, String companyName,
        LclFileNumber fileNumber) throws DocumentException, IOException, Exception {
    LclExportNotiFicationForm lclExportNotiFicationForm = new LclExportsVoyageNotificationDAO()
            .getNotificationDetail(notificationId);
    LclSsDetail lclSsDetail = null;// w ww .j  a  v a  2  s  .  c  o  m
    String pod = "", finalDest = "";
    String voyageHeading = "Voyage Notification";

    if (lclExportNotiFicationForm != null) {
        lclSsDetail = new LclSsDetailDAO().findByTransMode(lclExportNotiFicationForm.getHeaderId(), "V");
        if (lclSsDetail != null) {
            pod = new LclUtils().getConcatenatedOriginByUnlocation(lclSsDetail.getArrival());
            finalDest = new LclUtils()
                    .getConcatenatedOriginByUnlocation(lclSsDetail.getLclSsHeader().getDestination());
        }
    }
    companyCode = new SystemRulesDAO().getSystemRules("CompanyCode");
    String path = LoadLogisoftProperties.getProperty(
            companyCode.equalsIgnoreCase("03") ? "application.image.logo" : "application.image.econo.logo");

    Document document = new Document(PageSize.A4);
    PdfWriter.getInstance(document, new FileOutputStream(outputFileName));
    document.open();
    document.add(imageBlock(realPath, path));
    document.add(headerPage(voyageHeading));
    document.add(informationBlock(companyName, pod, finalDest));
    document.add(changesBlock(lclSsDetail, lclExportNotiFicationForm));
    document.add(containerBlock(companyName, finalDest, fileNumber, lclExportNotiFicationForm));
    document.add(reasonBlock(lclExportNotiFicationForm));
    document.add(footerBlock());
    document.close();
}

From source file:com.grant.report.BillPdf.java

public void printBill(PrintDetails printDetails) {
    try {/*w  ww .j av a  2  s.  c om*/

        String newInvo = printDetails.getInvoiceNo().replaceAll("\\|", "_");
        FILE = "E:/" + newInvo + ".pdf";
        invoNo = printDetails.getInvoiceNo();

        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(FILE));
        document.open();
        addMetaData(document);
        addTitlePage(document, printDetails);
        //addContent(document);
        document.close();
    } catch (FileNotFoundException | DocumentException e) {
        e.printStackTrace();
    }

}

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 {// ww w .j  ava 2s.c  om
        // 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.handpoint.headstart.client.ui.ReceiptActivity.java

License:Apache License

private File createPdfFromReceipt(String html, String fileNamePrefix) {
    //We cannot trust that the html is well formed
    org.jsoup.nodes.Document doc = Jsoup.parse(html);
    html = doc.toString();/*w ww. ja  va  2 s.  co m*/

    File file = null;
    try {
        Document document = new Document(PageSize.LETTER);
        file = getOutputMediaFile(fileNamePrefix);
        PdfWriter instance = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        InputStream is = new ByteArrayInputStream(html.getBytes());
        XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
        worker.parseXHtml(instance, document, is);
        document.close();

    } catch (Exception e) {
        logger.log(Level.SEVERE, TAG + " :Failed to create .pdf document from receipt.", e);
        Toast.makeText(ReceiptActivity.this, getString(R.string.create_pdf), Toast.LENGTH_LONG).show();
    }
    return file;
}

From source file:com.havoc.hotel.util.BookingPdf.java

public static String generateBookingPDF(Booking booking)
        throws DocumentException, FileNotFoundException, IOException {
    Document document = new Document(PageSize.A4);
    String bookingname = booking.getFirstName() + " " + booking.getLastName();
    document.addHeader("HOTEL HAVOC", "Hotel havoc Booking confirmation");
    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(FILE + "Booking" + "" + booking.getCustomer().getFirstName() + ".pdf "));
    writer.setViewerPreferences(PdfWriter.PageModeUseOC);
    writer.setPdfVersion(PdfWriter.VERSION_1_7);
    document.open();/*from  ww  w. j a v  a2  s .com*/
    String html = htmlTemplate(booking);

    List unorderedList = new List(List.UNORDERED);

    unorderedList.add(new ListItem("Name       :" + booking.getFirstName() + " " + booking.getLastName()));
    //        unorderedList.add(new ListItem("Room Price :" + booking.getRoom().getRoomPrice()));
    unorderedList.add(new ListItem("Total Price :" + booking.getTotalPrice()));
    unorderedList.add(new ListItem("check in   :" + booking.getCheckinDate()));
    unorderedList.add(new ListItem("Total Nights:" + booking.getTotalNights()));
    unorderedList.add(new ListItem("check out  :" + booking.getCheckoutDate()));
    unorderedList.add(new ListItem("Booked By  :" + booking.getCustomer().getUsername()));

    document.add(unorderedList);
    document.close();
    return bookingname;

}

From source file:com.homecare.bo.EmployeeInfoBOImpl.java

@Scheduled(cron = "0 0 1 * * ?")
@Async// w ww  . ja  va 2 s . com
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) {
                }
            }
        }
    }
}