Example usage for com.itextpdf.text Document close

List of usage examples for com.itextpdf.text Document close

Introduction

In this page you can find the example usage for com.itextpdf.text Document close.

Prototype

boolean close

To view the source code for com.itextpdf.text Document close.

Click Source Link

Document

Has the document already been closed?

Usage

From source file:com.icebreak.p2p.front.controller.trade.download.InvestReceiptPDFCreator.java

/**
 * ???/* www  . j  a  v a2  s . co m*/
 * @param tradeId
 * @param detailId
 * @param servletPath
 * @return ?  byte[]
 * @throws Exception
 */
public byte[] creatFileData4Receipt(long tradeId, long detailId, String servletPath) throws Exception {

    FileInputStream fis = null;
    BufferedInputStream buff = null;

    String fileKey = tradeId + "_" + detailId;//System.currentTimeMillis() + "";
    String filePath = servletPath + "/resources/pdf/investReceipt_" + fileKey + ".pdf";
    this.receiptFilePath = filePath;

    File file = new File(filePath);

    if (!file.exists()) {

        String timeLimit = "";
        String interestRate = "";
        String guaranteeName = "";
        String investFlowCode = null;
        String investor = "";
        String investorReal = "";
        String investorCertNo = "";
        String loanner = "";
        String loannerReal = "";
        String loannerCertNo = "";
        String investAmount = "";
        String totalAmountStr = "";
        String effectiveDate = "";
        String expireDate = "";

        Trade trade = tradeService.getByTradeId(tradeId);
        effectiveDate = DateUtil.simpleFormat(trade.getEffectiveDateTime());
        expireDate = DateUtil.simpleFormat(trade.getExpireDateTime());
        LoanDemandDO loanDemand = loanDemandManager.queryLoanDemandByDemandId(trade.getDemandId());
        guaranteeName = loanDemand.getGuaranteeName();
        if ("W".equals(loanDemand.getTimeLimitUnit()) || "M".equals(loanDemand.getTimeLimitUnit())) {
            timeLimit = loanDemand.getTimeLimit() + "";
        } else if ("Y".equals(loanDemand.getTimeLimitUnit())) {
            timeLimit = loanDemand.getTimeLimit() + "";
        } else {
            timeLimit = loanDemand.getTimeLimit() + "";
        }
        interestRate = CommonUtil.mul(loanDemand.getInterestRate(), 100) + "%";
        List<UserInvestEntry> userInvests = tradeService.getEntriesByTradeIdAndDetailId(tradeId, detailId);
        long totalAmount = 0;
        if (userInvests != null && userInvests.size() > 0) {
            UserInvestEntry tradeItem = userInvests.get(0);
            investAmount = MoneyUtil.getFormatAmount(tradeItem.getAmount());
            long investorId = userInvests.get(0).getInvestorId();
            long loannerId = userInvests.get(0).getLoanerId();
            investorCertNo = getCertNoByUserId(investorId);
            loannerCertNo = getCertNoByUserId(loannerId);
            investor = userInvests.get(0).getInvestorUserName();
            investorReal = userInvests.get(0).getInvestorRealName();
            loannerReal = userInvests.get(0).getLoanerRealName();
            loanner = userInvests.get(0).getLoanerUserName();
            totalAmount = userInvests.get(0).getAmount();
        }

        //?
        /*interest = caculateInterest(new Money(totalAmount), loanDemand.getInterestRate(),
        loanDemand.getTimeLimit(), loanDemand.getTimeLimitUnit());*/

        long divisionAmount = 0;
        long profitAmount = 0;
        List<TradeDetail> details = tradeService.getInvestProfitTrade(detailId);
        if (details != null && details.size() > 0) {
            for (TradeDetail detail : details) {
                divisionAmount += detail.getAmount();
                if (detail.getProfitType() > 0) {
                    profitAmount += detail.getAmount();
                }
            }
        }
        totalAmount += divisionAmount;

        TradeFlowCode tradeFlow = tradeService.queryInvestFlowCodesByTradeDetailId(detailId);
        if (tradeFlow != null) {
            investFlowCode = tradeFlow.getTradeFlowCode();
        }

        String guaranteeLicenseNo = "";
        Map<String, Object> cond = new HashMap<String, Object>();
        cond.put("roleId", 8L);

        cond.put("tradeId", trade.getId());
        List<TradeQueryDetail> det = loanDemandManager.getTradeDetailByConditions(cond);
        if (det != null && det.size() > 0) {
            tradeFlow = tradeService.queryInvestFlowCodesByTradeDetailId(det.get(0).getId());
            if (tradeFlow != null) {
                guaranteeLicenseNo = tradeFlow.getTradeFlowCode();
            }
        }

        LoanDemandDO demand = loanDemandManager.queryLoanDemandByDemandId(trade.getDemandId());
        long divisionTemplateId = demand.getDivisionTemplateId();
        DivisionTemplateLoanDO divisionTemplateLoan = divisionTemplateLoanService
                .getByBaseId(divisionTemplateId);
        List<DivsionRuleRole> investRolelist = divisionService
                .getRuleRole(String.valueOf(divisionTemplateLoan.getInvestTemplateId()));
        List<DivsionRuleRole> repayRolelist = divisionService
                .getRuleRole(String.valueOf(divisionTemplateLoan.getRepayTemplateId()));
        //??
        double totalAnnualInterest = 0;
        investRolelist.addAll(repayRolelist);
        if (investRolelist != null && investRolelist.size() > 0) {
            for (DivsionRuleRole druleRole : investRolelist) {
                if (DivisionPhaseEnum.INVESET_PHASE.code().equals(druleRole.getPhase())) {
                    if ("11".equals(String.valueOf(druleRole.getRoleId()))) {
                        totalAnnualInterest += druleRole.getRule();
                    }

                }
            }
        }

        totalAmountStr = MoneyUtil.getFormatAmount(totalAmount);
        String divisionAmountStr = MoneyUtil.getFormatAmount(divisionAmount);

        FileOutputStream fos = null;
        Document doc = new Document(PageSize.A4, 20, 20, 140, 20);
        try {
            fos = new FileOutputStream(filePath);
            PdfWriter writer = PdfWriter.getInstance(doc, fos);
            doc.open();
            //   
            BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
            Font titleChinese = new Font(bfChinese, 20, Font.BOLD); // ?     
            Paragraph title = new Paragraph(AppConstantsUtil.getProductName() + "?", titleChinese);// 
            title.setAlignment(Element.ALIGN_CENTER); // 
            title.setLeading(1f);//?//?
            doc.add(title);

            Font fontZH = new Font(bfChinese, 12, Font.NORMAL);
            float[] widths = { 20f, 30f, 25f, 25f };
            PdfPTable table = new PdfPTable(widths);

            table.setSpacingBefore(20f);// ?
            table.setTotalWidth(500);// 
            table.setWidthPercentage(100);//%100
            // table.getDefaultCell().setBorder(0);//
            PdfPCell cell;
            //               cell = new PdfPCell(new Paragraph("?",fontZH));
            //               cell.setColspan(4);
            //               table.addCell(cell);

            cell = new PdfPCell(new Paragraph("??", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(AppConstantsUtil.getPlatformName(), fontZH));
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("?", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(loanDemand.getRepayDivisionWayMsg(), fontZH));
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(interestRate, fontZH));
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("?", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(timeLimit, fontZH));
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("??", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(guaranteeName, fontZH));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("??", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Paragraph(StringUtil.nullToEmpty(loanDemand.getGuaranteeLicenseNo()), fontZH));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph((loanDemand.getLoanAmount() / 100) + "", fontZH));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(loanDemand.getLoanPurpose(), fontZH));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("??", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(investFlowCode, fontZH));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("?", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            cell.setColspan(2);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("??", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            cell.setColspan(2);

            table.addCell(cell);
            Paragraph iparas = new Paragraph("??" + investor, fontZH);
            iparas.add(Chunk.NEWLINE);
            iparas.add("??" + investorReal);
            iparas.add(Chunk.NEWLINE);
            iparas.add("??" + StringUtil.subString(investorCertNo, 7, "****"));
            iparas.add(Chunk.NEWLINE);
            iparas.add("?" + effectiveDate);
            iparas.add(Chunk.NEWLINE);
            iparas.add("" + expireDate);
            iparas.add(Chunk.NEWLINE);
            iparas.add("()" + investAmount);
            iparas.add(Chunk.NEWLINE);
            iparas.add("()" + divisionAmountStr);
            iparas.add(Chunk.NEWLINE);
            iparas.add("()" + totalAmountStr);

            cell = new PdfPCell(iparas);
            cell.setColspan(2);
            cell.setRowspan(8);

            cell.setMinimumHeight(120);
            table.addCell(cell);
            Paragraph paras = new Paragraph("??" + loanner, fontZH);
            paras.add(Chunk.NEWLINE);
            paras.add("??" + loannerReal);
            paras.add(Chunk.NEWLINE);
            paras.add("??" + StringUtil.subString(loannerCertNo, 7, "****"));
            paras.add(Chunk.NEWLINE);
            paras.add("?" + effectiveDate);
            paras.add(Chunk.NEWLINE);
            paras.add("" + expireDate);
            paras.add(Chunk.NEWLINE);
            paras.add(Chunk.NEWLINE);
            paras.add(Chunk.NEWLINE);
            paras.add("()" + totalAmountStr);
            cell = new PdfPCell(paras);
            cell.setColspan(2);
            cell.setRowspan(8);
            table.addCell(cell);
            doc.add(table);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            Paragraph tips = new Paragraph("  ?? ?"
                    + AppConstantsUtil.getPlatformName() + "", fontZH);// 
            tips.setLeading(1f);//?//?
            doc.add(tips);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            tips = new Paragraph("  ??" + AppConstantsUtil.getPlatformAddress(), fontZH);// 
            tips.setLeading(1f);//?//?
            doc.add(tips);
            //               XMLWorkerHelper.getInstance().parseXHtml(writer, doc,
            //                     new ByteArrayInputStream(str.getBytes()));
            doc.close();
            logger.info("?");

        } catch (Exception e) {
            logger.error("?", e);
            throw new Exception("?:" + e.getMessage());
        } finally {

            if (fos != null) {
                fos.close();
            }
        }
    }

    byte[] data = new byte[1024];

    file = new File(filePath);
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] temp = new byte[1024];
        int size = 0;

        fis = new FileInputStream(file);
        buff = new BufferedInputStream(fis);

        int i = 0;

        while ((size = buff.read(temp)) != -1) {
            out.write(temp, 0, size);
            i += 1;
        }

        data = out.toByteArray();

        buff.close();
        fis.close();
        //file.delete();

        if (i == 0 && size == -1) { //PDF
            file.delete();
        }
    } catch (FileNotFoundException e) {
        logger.error("?", e);
    } catch (IOException e) {
        logger.error("delete file", e);
    } finally {
        if (fis != null) {
            fis.close();
        }
    }

    return data;
}

From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java

public void createPDF(Context context) throws DocumentException, IOException {
    LicenseKey.loadLicenseFile(context.getAssets().open("itextkey.xml"));
    this.mContext = context;
    Map<String, String> pdfParams = new HashMap();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_Hmmss", Locale.US);
    dateFormat.setTimeZone(TimeZone.getDefault());
    this.filename = "txtbook_" + dateFormat.format(new Date()) + ".pdf";
    float leftMargin = Txtbook.RIGHT_MARGIN_EVEN;
    float rightMargin = Txtbook.RIGHT_MARGIN_ODD;
    if (this.settings.addFrontCover.booleanValue()) {
        leftMargin = Txtbook.RIGHT_MARGIN_ODD;
        rightMargin = Txtbook.RIGHT_MARGIN_EVEN;
    }/*from  ww w  .  jav a 2s .  c  o m*/
    Document document = new Document(PageSize.LETTER, leftMargin, rightMargin, Txtbook.TOP_MARGIN,
            Txtbook.TOP_MARGIN);
    File file = new File(Environment.getExternalStorageDirectory(), this.filename);
    if (!(file.exists() && file.canRead())) {
        file.createNewFile();
    }
    this.writer = PdfWriter.getInstance(document, new FileOutputStream(file));
    this.writer.setCompressionLevel(this.settings.compressionLevel);
    this.writer.setStrictImageSequence(true);
    FontFactory.register("assets/fonts/DroidSans.ttf");
    this.sansFont6Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 6.0f, 0,
            new BaseColor(152, 152, 152));
    this.sansFont9 = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 9.0f);
    this.sansFont9Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 9.0f, 0,
            new BaseColor(103, 103, 103));
    this.sansFont11Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 11.0f, 0,
            new BaseColor(152, 152, 152));
    FontFactory.register("assets/fonts/CourierNew.ttf");
    this.serifFont8Gray = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 8.0f, 0,
            new BaseColor(103, 103, 103));
    this.serifFont11 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 11.0f);
    this.serifFont14 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 14.0f);
    this.serifFont24 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 24.0f);
    document.open();
    document.setMarginMirroring(true);
    document.addCreationDate();
    document.addCreator("Created with txt-book for Android www.txt-book.com");
    document.addTitle("txt-book for Android");
    if (this.settings.bookStyle == 1) {
        ConversationHeaderFooter hf = new ConversationHeaderFooter();
        hf.footerFont = this.sansFont9;
        hf.hasFrontCover = this.settings.addFrontCover;
        this.writer.setPageEvent(hf);
    } else {
        StorybookHeaderFooter hf2 = new StorybookHeaderFooter();
        hf2.title = this.settings.bookCoverTitle;
        hf2.headerFont = this.serifFont8Gray;
        hf2.hasFrontCover = this.settings.addFrontCover;
        this.writer.setPageEvent(hf2);
    }
    if (this.settings.addFrontCover.booleanValue()) {
        createFrontCoverPage(document, this.settings.bookCoverTitle,
                this.settings.addFrontCoverImage.booleanValue() ? this.settings.coverPhoto : null);
        pdfParams.put("PDF Front Cover", "YES");
    } else {
        pdfParams.put("PDF Front Cover", "NO");
    }
    if (this.settings.addFrontCoverImage.booleanValue()) {
        pdfParams.put("PDF Front Cover Image", "YES");
    } else {
        pdfParams.put("PDF Front Cover Image", "NO");
    }
    if (this.settings.bookStyle == 1) {
        createContentPagesConversation(document);
    } else {
        createContentPagesStorybook(document, this.settings.bookCoverTitle);
    }
    int pages = this.writer.getPageNumber();
    if (this.settings.bookStyle == 2) {
        ((StorybookHeaderFooter) this.writer.getPageEvent()).reachedEndOfContent = Boolean.valueOf(true);
    } else {
        ((ConversationHeaderFooter) this.writer.getPageEvent()).reachedEndOfContent = Boolean.valueOf(true);
    }
    if (this.settings.addBackCover.booleanValue()) {
        pages++;
        pdfParams.put("PDF Back Cover", "YES");
        if (pages % 2 == 1) {
            createBlankSpacerPage(document);
        }
        createBackCoverPage(document, this.settings.backCoverNote);
    } else {
        pdfParams.put("PDF Back Cover", "NO");
        if (pages % 2 == 1) {
            createBlankSpacerPage(document);
        }
    }
    if (this.settings.bookStyle == 2) {
        pdfParams.put("PDF Style", "Storybook");
    } else {
        pdfParams.put("PDF Style", "Conversation");
    }
    pdfParams.put("PDF Num Pages", Integer.valueOf(this.writer.getPageNumber()).toString());
    document.close();
    FlurryAgent.logEvent("PDF_CREATED", (Map) pdfParams);
}

From source file:com.imageConverter.imageConverter.java

public static void main(String[] args) {

    try {/*from w  w  w .  j av  a  2 s  . co 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 {/*from   w  ww  .  ja v a2 s .  c o  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  ww w.ja  v  a2  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.incosyz.sms.other.SendOrderMail.java

public void savePdf(GETOrderModel gETOrderModel, String savePath) throws IOException, DocumentException {
    String html = getHTML(gETOrderModel);
    File file = new File("./src/com/incosyz/sms/temp/" + gETOrderModel.getOrderModel().getOrderId() + ".html");
    //            file.createNewFile();
    FileWriter fileWriter = new FileWriter(file);
    BufferedWriter bw = new BufferedWriter(fileWriter);
    bw.write(html);//from w  ww. j  a v a2s  . c  o  m
    bw.close();

    Document d = new Document(PageSize.A4);
    String filePath = savePath + ".pdf";

    FileOutputStream fileOutputStream = new FileOutputStream(filePath);
    PdfWriter pdfWriter = PdfWriter.getInstance(d, fileOutputStream);

    d.addAuthor("Incosyz");
    d.addTitle("Sale Detail");
    d.addTitle("Sale Detail");

    d.open();

    FileInputStream fileInputStream = new FileInputStream(file);
    XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, d, fileInputStream);

    d.close();
    fileOutputStream.close();

    if (file.isFile()) {
        file.delete();
    }

}

From source file:com.incosyz.sms.other.SendOrderMail.java

public void sendOrder(GETOrderModel gETOrderModel, String txt) throws IOException, MessagingException {
    try {/* w w w  .ja  v a 2s. co  m*/
        String html = getHTML(gETOrderModel);
        File file = new File(
                "./src/com/incosyz/sms/temp/" + gETOrderModel.getOrderModel().getOrderId() + ".html");
        //            file.createNewFile();
        FileWriter fileWriter = new FileWriter(file);
        BufferedWriter bw = new BufferedWriter(fileWriter);
        bw.write(html);
        bw.close();

        Document d = new Document(PageSize.A4);
        String filePath = "./src/com/incosyz/sms/temp/" + gETOrderModel.getOrderModel().getOrderId() + ".pdf";

        FileOutputStream fileOutputStream = new FileOutputStream(filePath);
        PdfWriter pdfWriter = PdfWriter.getInstance(d, fileOutputStream);

        d.addAuthor("Incosyz");
        d.addTitle("Sale Detail");
        d.addTitle("Sale Detail");

        d.open();

        FileInputStream fileInputStream = new FileInputStream(file);
        XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, d, fileInputStream);

        d.close();
        fileOutputStream.close();

        MailSender mailSender = new MailSender();
        MimeBodyPart body = (MimeBodyPart) mailSender.getBody();
        body.setText("");
        mailSender.setSubject(txt + " Sale Detail Round No : " + gETOrderModel.getOrderModel().getRoundNo()
                + "  | Order Amount : Rs "
                + CurrancyFormat.getCurrancyFormat(gETOrderModel.getOrderModel().getOrderAmount()));
        mailSender.setAttachmentPath(filePath);
        mailSender.sendMail();

        if (file.isFile()) {
            File f = new File(filePath);
            f.delete();
            file.delete();
        }

    } catch (DocumentException ex) {
        Logger.getLogger(SendOrderMail.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.incosyz.sms.pdfcontroller.ChequePDF.java

public void sendPdf(ArrayList<CheckModel> checkModels, String chequeDescription)
        throws DocumentException, MessagingException {
    try {//  w w w  .j ava  2  s  .  c  om

        String html = getHTML(checkModels, chequeDescription);

        Document document = new Document(PageSize.A4.rotate());

        String path = "./src/com/incosyz/sms/temp/tmporders.pdf";
        File f = new File(path);
        FileOutputStream fileOutputStream = new FileOutputStream(f);
        PdfWriter pdfWriter = PdfWriter.getInstance(document, fileOutputStream);

        document.open();

        StringReader fileReader = new StringReader(html);
        XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, fileReader);

        document.close();
        fileOutputStream.close();

        MailSender mailSender = new MailSender();
        MimeBodyPart body = (MimeBodyPart) mailSender.getBody();
        body.setText(html, "utf-8", "html");
        mailSender.setAttachmentPath(path);
        mailSender.setSubject(chequeDescription);
        mailSender.sendMail();
    } catch (IOException ex) {
        Logger.getLogger(ChequePDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.incosyz.sms.pdfcontroller.ChequePDF.java

public void generateOrderPdf(ArrayList<CheckModel> checkModels, String filepath, String chequeDescription)
        throws FileNotFoundException, DocumentException {
    try {//from w ww.j  a  v  a 2s.  c om
        String html = getHTML(checkModels, chequeDescription);

        Document document = new Document(PageSize.A4.rotate());

        File f = new File(filepath);
        FileOutputStream fileOutputStream = new FileOutputStream(f);
        PdfWriter pdfWriter = PdfWriter.getInstance(document, fileOutputStream);

        document.open();

        StringReader fileReader = new StringReader(html);
        XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, fileReader);

        document.close();
        fileOutputStream.close();
    } catch (IOException ex) {
        Logger.getLogger(ChequePDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.incosyz.sms.pdfcontroller.OrderPDF.java

public void sendPdf(ArrayList<GETOrderModel> gETOrderModels, String orderDescription)
        throws DocumentException, MessagingException {
    try {//from www . j av a2s .c  o m
        String html = getHTML(gETOrderModels, orderDescription);

        Document document = new Document(PageSize.A4.rotate());

        String path = "./src/com/incosyz/sms/temp/tmporders.pdf";
        File f = new File(path);
        FileOutputStream fileOutputStream = new FileOutputStream(f);
        PdfWriter pdfWriter = PdfWriter.getInstance(document, fileOutputStream);

        document.open();

        StringReader fileReader = new StringReader(html);
        XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, fileReader);

        document.close();
        fileOutputStream.close();

        MailSender mailSender = new MailSender();
        MimeBodyPart body = (MimeBodyPart) mailSender.getBody();
        body.setText(html, "utf-8", "html");
        mailSender.setAttachmentPath(path);
        mailSender.setSubject(orderDescription);
        mailSender.sendMail();
    } catch (IOException ex) {
        Logger.getLogger(OrderPDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}