Example usage for com.itextpdf.text Document open

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

Introduction

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

Prototype

boolean open

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

Click Source Link

Document

Is the document open or not?

Usage

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;// w  ww.j a  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 w  w . ja  v a 2 s. c om
    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 {/*from  w  w  w.j av a2s. c o  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 a v  a 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  w  w  .ja  va 2 s. c  o  m*/
        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 w  w  w  .  j av a 2  s.c om
        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);
    }
}

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

public void generateOrderPdf(ArrayList<GETOrderModel> gETOrderModels, String filepath, String orderDescription)
        throws FileNotFoundException, DocumentException {
    try {/*w  w  w  .j  a  va  2s.  co m*/
        String html = getHTML(gETOrderModels, orderDescription);

        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(OrderPDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}

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

public String createPdf(String pathTo) throws FileNotFoundException, DocumentException, IOException {
    String html = getHtml();//from  ww  w.ja va  2  s.c  om
    Document document = new Document(PageSize.A3.rotate());

    String path = pathTo;
    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();
    return path;
}

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 .  jav  a 2 s .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   ww w . j  a  v a  2s .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();
}