Example usage for com.itextpdf.text Document add

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

Introduction

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

Prototype


public boolean add(Element element) throws DocumentException 

Source Link

Document

Adds an Element to the Document.

Usage

From source file:com.ainfosec.macresponse.report.PdfGenerator.java

License:Open Source License

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    preface.add(Chunk.NEWLINE);//from ww w  .  j  av  a 2  s.c  o  m
    // Lets write a big header
    preface.add(new Paragraph("MAC Response", chapterTitleFont));

    preface.add(Chunk.NEWLINE);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            contentFont));
    //      preface.add(Chunk.NEWLINE);
    //      preface.add(Chunk.NEWLINE);
    //      preface.add(Chunk.NEWLINE);
    //      preface.add(new Paragraph(
    //            "This document describes something which is very important ",
    //            contentFont));

    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:com.ainfosec.macresponse.report.PdfGenerator.java

License:Open Source License

private static void addTables(Document document, TreeObject rootObject) throws DocumentException {
    // TODO Paul add table of contents/etc.?
    // Table of Contents
    Paragraph paragraph = new Paragraph();
    paragraph.add("Table of Contents\n\n");

    for (TreeObject treeObject : rootObject.getChildObjects()) {
        if (treeObject.isChecked()) {
            addTocSection(paragraph, treeObject, String.valueOf(currentChapter));
            currentChapter++;/*from   w  ww . java2  s  .  com*/
        }
    }
    currentChapter = 1;

    document.add(paragraph);

    // Table of Figures
    // Table of Tables
}

From source file:com.ainfosec.macresponse.report.PdfGenerator.java

License:Open Source License

private static void addContent(Document document, TreeObject rootObject) throws DocumentException {
    for (TreeObject treeObject : rootObject.getChildObjects()) {
        if (treeObject.isChecked()) {
            Paragraph title = new Paragraph(treeObject.getTitle(), chapterTitleFont);
            Chapter chapter = new Chapter(title, currentChapter);
            populateChapter(treeObject, chapter);
            document.add(chapter);
            currentChapter++;//w w  w . ja  v a 2 s . c o m
        }
    }
}

From source file:com.algoboss.erp.util.report.PDFExporter.java

License:Apache License

@Override
public void export(FacesContext context, DataTable table, String filename, boolean pageOnly,
        boolean selectionOnly, String encodingType, MethodExpression preProcessor,
        MethodExpression postProcessor) throws IOException {
    try {//from ww  w  .j  a  v  a2 s  . com
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);

        if (preProcessor != null) {
            preProcessor.invoke(context.getELContext(), new Object[] { document });
        }

        if (!document.isOpen()) {
            document.open();
        }

        document.add(exportPDFTable(context, table, pageOnly, selectionOnly, encodingType));

        if (postProcessor != null) {
            postProcessor.invoke(context.getELContext(), new Object[] { document });
        }

        document.close();

        writePDFToResponse(context.getExternalContext(), baos, filename);

    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }
}

From source file:com.algoboss.erp.util.report.PDFExporter.java

License:Apache License

public void export(FacesContext context, DataTable table, String filename, String encodingType)
        throws IOException {
    try {/* w  w w  .  j  a  v  a 2s  .  c  o m*/
        Document document = new Document(PageSize.A4, 25f, 25f, 25f, 25f);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);

        if (!document.isOpen()) {
            document.open();
        }
        document.addAuthor("Algo Boss");
        document.addCreator("Real's HowTo");
        document.addSubject("Thanks for your support");
        document.addCreationDate();
        document.addTitle(filename);
        //document.setMargins(1f, 1f, 1f, 1f);
        //document.setPageSize(PageSize.A4);
        document.add(exportPDFTable(context, table, false, false, false, encodingType));
        //document.setMargins(1f, 1f, 1f, 1f);
        //document.setPageSize(PageSize.A4);

        document.close();

        //writePDFToResponse(context.getExternalContext(), baos, filename);
        writePDFToResponseNew(context.getExternalContext(), baos, filename);

    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }
}

From source file:com.algoboss.erp.util.report.PDFExporter2.java

License:Apache License

public void export(FacesContext context, DataTable table, String filename, String encodingType)
        throws IOException {
    try {/*from www .  j a  v a 2 s . c  o  m*/
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);

        if (!document.isOpen()) {
            document.open();
        }
        document.setMargins(1f, 1f, 1f, 1f);
        document.setPageSize(PageSize.A4);
        document.add(exportPDFTable(context, table, false, false, true, encodingType));
        document.setMargins(1f, 1f, 1f, 1f);
        document.setPageSize(PageSize.A4);

        document.close();

        //writePDFToResponse(context.getExternalContext(), baos, filename);
        writePDFToResponseNew(context.getExternalContext(), baos, filename);

    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }
}

From source file:com.alnaser.view.GestionProduit.java

private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {
    System.out.println("!!!!!!!");
    try {//from  w w  w .j a v a 2 s .  c o m
        OutputStream file = new FileOutputStream(new File("D:\\Test.pdf"));

        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();
        // a table with three columns
        PdfPTable table = new PdfPTable(7);
        // the cell object
        PdfPCell cell, cel2, cel3, cel4, cel5, cel6, cel7;
        // we add a cell with colspan 3
        cell = new PdfPCell(new Phrase("Code"));
        cel2 = new PdfPCell(new Phrase("Ref"));
        cel3 = new PdfPCell(new Phrase("Desg"));
        cel4 = new PdfPCell(new Phrase("Four"));
        cel5 = new PdfPCell(new Phrase("Remise"));
        cel6 = new PdfPCell(new Phrase("Prix"));
        cel7 = new PdfPCell(new Phrase("Stock"));

        table.addCell(cell);
        table.addCell(cel2);
        table.addCell(cel3);
        table.addCell(cel4);
        table.addCell(cel5);
        table.addCell(cel6);
        table.addCell(cel7);

        for (Produit p : list) {
            table.addCell(p.getCodeProduit());
            table.addCell(p.getReference());
            table.addCell(p.getDeseignation());
            table.addCell(p.getFournisseur());
            table.addCell(p.getRemise() + "");
            table.addCell(p.getPrix() + "");
            table.addCell(p.getStock() + "");
        }
        document.add(table);
        document.add(new Paragraph(new Date().toString()));

        document.close();
        file.close();

    } catch (Exception e) {

        e.printStackTrace();
    }

}

From source file:com.alokomkar.aliensonearth.report.AbstractPdfReport.java

/**
 * @param document/*from  ww w .j a  v  a2 s .c  om*/
 * Virtual Function for adding Line Separator.
 */
protected void addLineSeperator(Document document) {
    LineSeparator ls = new LineSeparator();
    try {
        document.add(new Chunk(ls));
        document.add(new Phrase("\n"));
    } catch (DocumentException e) {
        e.printStackTrace();
    }

}

From source file:com.app.gpo.pdf.utils.PDForderLabelCard.java

License:Open Source License

@Override
protected void buildPdfDocument(Map<String, Object> model, Document doc, PdfWriter writer,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    // get data model which is passed by the Spring container
    OrderItem orderItem = (OrderItem) model.get("orderItem");
    Font font = FontFactory.getFont(FontFactory.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    font.setSize(20);/*from  w w  w.j a v  a 2s. co  m*/
    Font font2 = FontFactory.getFont(FontFactory.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    font2.setSize(12);

    String utf = orderItem.getorderItemName();
    byte[] data = utf.getBytes("CP1250");
    String ascii = new String(data);
    String code = orderItem.getorderNumber();
    Paragraph numberText = new Paragraph(code, font);
    numberText.setAlignment(Element.ALIGN_CENTER);
    doc.add(new Phrase("\n"));
    Paragraph nameText = new Paragraph(ascii, font2);
    nameText.setAlignment(Element.ALIGN_CENTER);
    // document.newPage()
    /*BarcodeEAN barcode = new BarcodeEAN();
    barcode.setCodeType(Barcode.CODE128);
    barcode.setCode(code);
    Rectangle barcodeRect = new Rectangle(400,200);
    barcode.placeBarcode(barcodeRect, BaseColor.BLACK, BaseColor.YELLOW);
    doc.add(barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY));*/
    doc.add(numberText);
    doc.add(new Phrase("\n"));
    doc.add(nameText);
}

From source file:com.app.gpo.pdf.utils.PDForderLabelCards.java

License:Open Source License

@Override
protected void buildPdfDocument(Map<String, Object> model, Document doc, PdfWriter writer,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    // get data model which is passed by the Spring container
    List<OrderItem> orderItemList = (List<OrderItem>) model.get("orderItemList");
    Font font = FontFactory.getFont(FontFactory.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    font.setSize(18);//  w w w . j a va2  s .c o m
    Font font2 = FontFactory.getFont(FontFactory.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    font2.setSize(12);

    Iterator<OrderItem> it = orderItemList.iterator();
    while (it.hasNext()) {
        OrderItem orderItem = it.next();
        String utf = orderItem.getorderItemName();
        byte[] data = utf.getBytes("CP1250");
        String ascii = new String(data);
        String code = orderItem.getorderNumber();
        Paragraph numberText = new Paragraph(code, font);
        numberText.setAlignment(Element.ALIGN_CENTER);
        doc.add(new Phrase("\n"));
        Paragraph nameText = new Paragraph(ascii, font2);
        nameText.setAlignment(Element.ALIGN_CENTER);
        // document.newPage()
        /*BarcodeEAN barcode = new BarcodeEAN();
        barcode.setCodeType(Barcode.CODE128);
        barcode.setCode(code);
        Rectangle barcodeRect = new Rectangle(400,200);
        barcode.placeBarcode(barcodeRect, BaseColor.BLACK, BaseColor.YELLOW);
        doc.add(barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY));*/
        doc.add(numberText);
        doc.add(new Phrase("\n"));
        doc.add(nameText);
        doc.newPage();
    }

}