Example usage for com.itextpdf.text Paragraph add

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

Introduction

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

Prototype

@Override
public boolean add(Element o) 

Source Link

Document

Adds an Element to the Paragraph.

Usage

From source file:com.microware.intrahealth.Createpdf2.java

private static void createTable1(Paragraph preface, String Text, String Value) throws BadElementException {

    Context _con = null;//from   ww w. j a v  a  2 s  . co m

    PdfPTable table = new PdfPTable(new float[] { 1, 3 });
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    for (int i = 0; i < 2; i++) {
        //      table.addCell(new PdfPCell(new Phrase(Header[i], smallBold)));
        PdfPCell c1 = new PdfPCell(new Phrase());
        table.addCell(c1);
    }
    PdfPCell[] cells = table.getRow(0).getCells();
    //        for (int j=0;j<cells.length;j++){
    cells[0].setHorizontalAlignment(Element.ALIGN_LEFT);
    //        }

    dataprovider = new DataProvider(_con);

    if (Text.length() > 0 && Value.length() > 0) {
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(Text, subFont));
        table.addCell(phrase);
        table.addCell(Value);
    } else {
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(Text, subFont));
        table.addCell(phrase);
        table.addCell("");
    }

    preface.add(table);

}

From source file:com.microware.intrahealth.Createpdfall.java

private static void addContent(Document document, String Header1[], String[] Page1, String[] Page1Value,
        String heading1, String Page1Remark,

        String[] Header2, String[] Page2_1, String[] Page2_1source, String[] Page2_1value, String[] Page2_2,
        String[] Page2_2source, String[] Page2_2value, String[] Page2_3, String[] Page2_3source,
        String[] Page2_3value, String heading2, String heading3, String heading4, String heading5,
        String Remark2Value,/*from w  ww.ja  v a 2  s  .  co m*/

        String[] Header3, String[] Page31, String[] Page3Census1, String[] Page3Value1, String[] Page32,
        String[] Page3Census2, String[] Page3Value2, String heading6, String heading7, String heading8,
        String Page3Remark,

        String[] Header4, String[] Page4_1, String[] Page4Value1, String[] Page4_2, String[] Page4Value2,
        String[] Page4_3, String[] Page4Value3, String heading9, String heading10, String heading11,
        String heading12, String Page4Remark1, String Page4Remark3,

        String[] Header5, String[] Page5Value1, String[] Page5Value2, String[] Page5Value3,
        String[] Page5Value4, String[] Page5_2, String[] Page5Value5, String[] Page5_3, String[] Page5Value6,
        String text5, String value5, String heading13, String heading14, String heading15, String Page5Remark1,
        String Page5Remark2,

        String[] Header6, String[] Page6Value1, String[] Page6Value2, String[] Page6Value3,
        String[] Page6Value4, String text6, String value6, String heading16,

        String[] Header7_1, String[] Page7Value1, String[] Page7Value2, String[] Page7Value3,
        String[] Page7Value4, String[] Page7Value5, String[] Header7_2, String[] Page7Value6,
        String[] Page7Value7, String[] Page7Value8, String[] Page7Value9, String[] Page7Value10,
        String[] Page7Value11, String text7_1, String value7_1, String text7_2, String value7_2,
        String heading17, String heading18, String heading19, String pdf1, String pdf2, int Flag)
        throws Exception {

    Paragraph preface = new Paragraph();
    Image img;
    sHeader[0] = "Question";
    sHeader[1] = "Source";
    sHeader[2] = "Data";

    // We add one empty line

    if (iflag == 26) {
        iflag = 0;
    }

    if (Flag == 2) {

    }

    if (iflag == 0) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(pdf1, catFont1));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(pdf2, catFont2));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading1, catFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page1, Page1Value);
        addEmptyLine(preface, 1);
        iflag = 1;
    }
    if (iflag == 1) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page1Remark);
        addEmptyLine(preface, 1);
        iflag = 2;
    }

    if (iflag == 2) {
        preface.add(new Paragraph(heading2, catFont));
        addEmptyLine(preface, 1);
        createTable2(preface, Header2, Page2_1, Page2_1source, Page2_1value);
        addEmptyLine(preface, 1);
        iflag = 3;
    }
    if (iflag == 3) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading3, catFont));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading4, subFont));
        addEmptyLine(preface, 1);
        createTable2(preface, Header2, Page2_2, Page2_2source, Page2_2value);
        addEmptyLine(preface, 1);
        iflag = 4;
    }
    if (iflag == 4) {
        preface.add(new Paragraph(heading5, subFont));
        addEmptyLine(preface, 1);
        createTable2(preface, Header2, Page2_3, Page2_3source, Page2_3value);
        addEmptyLine(preface, 1);
        iflag = 5;
    }
    if (iflag == 5) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Remark2Value);
        addEmptyLine(preface, 1);
        iflag = 6;
    }

    if (iflag == 6) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading6, catFont));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading7, subFont));
        addEmptyLine(preface, 1);
        createTable2(preface, Header3, Page31, Page3Census1, Page3Value1);
        addEmptyLine(preface, 1);
        iflag = 7;
    }
    if (iflag == 7) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page3Remark);
        addEmptyLine(preface, 1);
        iflag = 8;
    }
    if (iflag == 8) {
        preface.add(new Paragraph(heading8, subFont));
        addEmptyLine(preface, 1);
        createTable2(preface, Header3, Page32, Page3Census2, Page3Value2);
        addEmptyLine(preface, 1);
        iflag = 9;
    }

    if (iflag == 9) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading9, catFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page4_1, Page4Value1);
        addEmptyLine(preface, 1);
        iflag = 10;
    }
    if (iflag == 10) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page4Remark1);
        addEmptyLine(preface, 1);
        iflag = 11;
    }
    if (iflag == 11) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading10, catFont));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading11, subFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page4_2, Page4Value2);
        addEmptyLine(preface, 1);
        iflag = 12;
    }
    if (iflag == 12) {
        preface.add(new Paragraph(heading12, subFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page4_3, Page4Value3);
        addEmptyLine(preface, 1);
        iflag = 13;
    }
    if (iflag == 13) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page4Remark3);
        addEmptyLine(preface, 1);
        iflag = 14;
    }

    if (iflag == 14) {
        preface.add(new Paragraph(heading13, catFont));
        addEmptyLine(preface, 1);
        createTable3(preface, Header5, Page5Value1, Page5Value2, Page5Value3, Page5Value4);
        addEmptyLine(preface, 1);
        iflag = 15;
    }
    if (iflag == 15) {
        createTable7(preface, text5, value5);
        addEmptyLine(preface, 1);
        iflag = 16;
    }
    if (iflag == 16) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading14, catFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page5_2, Page5Value5);
        addEmptyLine(preface, 1);
        iflag = 17;
    }
    if (iflag == 17) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page5Remark1);
        addEmptyLine(preface, 1);
        iflag = 18;
    }
    if (iflag == 18) {
        preface.add(new Paragraph(heading15, catFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page5_3, Page5Value6);
        addEmptyLine(preface, 1);
        iflag = 19;
    }
    if (iflag == 19) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page5Remark2);
        addEmptyLine(preface, 1);
        iflag = 20;
    }

    if (iflag == 20) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading16, catFont));
        addEmptyLine(preface, 1);
        createTable3(preface, Header6, Page6Value1, Page6Value2, Page6Value3, Page6Value4);
        addEmptyLine(preface, 1);
        iflag = 21;
    }
    if (iflag == 21) {
        createTable7(preface, text6, value6);
        addEmptyLine(preface, 1);
        iflag = 22;
    }

    if (iflag == 22) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading17, catFont));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading18, subFont));
        addEmptyLine(preface, 1);
        createTable4(preface, Header1, text7_1, value7_1);
        addEmptyLine(preface, 1);
        iflag = 23;
    }
    if (iflag == 23) {
        createTable5(preface, Header7_1, Page7Value1, Page7Value2, Page7Value3, Page7Value4, Page7Value5);
        addEmptyLine(preface, 1);
        iflag = 24;
    }
    if (iflag == 24) {
        preface.add(new Paragraph(heading19, subFont));
        addEmptyLine(preface, 1);
        createTable6(preface, Header7_2, Page7Value6, Page7Value7, Page7Value8, Page7Value9, Page7Value10,
                Page7Value11);
        addEmptyLine(preface, 1);
        iflag = 25;
    }
    if (iflag == 25) {
        createTable7(preface, text7_2, value7_2);
        addEmptyLine(preface, 1);
        iflag = 26;
    }

    document.add(preface);

}

From source file:com.microware.intrahealth.Createpdfall.java

private static void createTable1(Paragraph preface, String[] Header, String[] Text, String[] Value)
        throws BadElementException {

    Context _con = null;/*from   w  w w. j ava2s.co m*/

    PdfPTable table = new PdfPTable(new float[] { 2, 1 });
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    for (int i = 0; i < Header.length; i++) {
        //      table.addCell(new PdfPCell(new Phrase(Header[i], smallBold)));
        PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold));
        c1.getBorder();
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }

    table.setHeaderRows(1);

    PdfPCell[] cells = table.getRow(0).getCells();
    for (int j = 0; j < cells.length; j++) {
        cells[j].setBackgroundColor(new BaseColor(0, 85, 133));

        if (j == 0) {
            cells[j].setHorizontalAlignment(Element.ALIGN_LEFT);
        } else {
            cells[j].setHorizontalAlignment(Element.ALIGN_CENTER);
        }
    }

    dataprovider = new DataProvider(_con);

    if (Text.length == Value.length) {
        for (int i = 0; i < Value.length; i++) {
            Phrase phrase = new Phrase();
            phrase.add(new Chunk(Text[i], subFont));
            table.addCell(phrase);
            table.addCell(Value[i]);
            PdfPCell[] cells1 = table.getRow(i + 1).getCells();
            cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT);
            cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER);
        }
    } else {
        for (int i = 0; i < Value.length; i++) {
            Phrase phrase = new Phrase();
            phrase.add(new Chunk(Text[i], subFont));
            table.addCell(phrase);
            table.addCell("");
            PdfPCell[] cells1 = table.getRow(i + 1).getCells();
            cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT);
        }
    }

    preface.add(table);

}

From source file:com.microware.intrahealth.Createpdfall.java

private static void createTable2(Paragraph preface, String[] Header, String[] Text, String[] Source,
        String[] Value) throws BadElementException {

    Context _con = null;/*w  w w .  ja  v  a 2 s  .co  m*/

    PdfPTable table = new PdfPTable(new float[] { 2, 1, 1 });
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    for (int i = 0; i < Header.length; i++) {
        //      table.addCell(new PdfPCell(new Phrase(Header[i], smallBold)));
        PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold));
        c1.getBorder();
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }

    table.setHeaderRows(1);

    PdfPCell[] cells = table.getRow(0).getCells();
    for (int j = 0; j < cells.length; j++) {
        cells[j].setBackgroundColor(new BaseColor(0, 85, 133));

        if (j == 0) {
            cells[j].setHorizontalAlignment(Element.ALIGN_LEFT);
        } else {
            cells[j].setHorizontalAlignment(Element.ALIGN_CENTER);
        }
    }

    dataprovider = new DataProvider(_con);

    if (Text.length == Value.length) {
        for (int i = 0; i < Value.length; i++) {
            Phrase phrase = new Phrase();
            phrase.add(new Chunk(Text[i], subFont));
            table.addCell(phrase);
            table.addCell(Source[i]);
            table.addCell(Value[i]);
            PdfPCell[] cells1 = table.getRow(i + 1).getCells();
            cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT);
            cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER);
            cells1[2].setHorizontalAlignment(Element.ALIGN_CENTER);
        }
    } else {
        for (int i = 0; i < Value.length; i++) {
            Phrase phrase = new Phrase();
            phrase.add(new Chunk(Text[i], subFont));
            table.addCell(phrase);
            table.addCell("");
            table.addCell("");
            PdfPCell[] cells1 = table.getRow(i + 1).getCells();
            cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT);
        }
    }

    preface.add(table);

}

From source file:com.microware.intrahealth.Createpdfall.java

private static void createTable3(Paragraph preface, String[] Header, String[] Text, String[] Value,
        String[] Value1, String[] Value2) throws BadElementException {

    Context _con = null;//from w  w  w  . j  a va 2s.  c o  m

    PdfPTable table = new PdfPTable(new float[] { 1, 2, 1, 1 });
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    for (int i = 0; i < Header.length; i++) {
        //      table.addCell(new PdfPCell(new Phrase(Header[i], smallBold)));
        PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold));
        c1.getBorder();
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }

    table.setHeaderRows(1);

    PdfPCell[] cells = table.getRow(0).getCells();
    for (int j = 0; j < cells.length; j++) {
        cells[j].setBackgroundColor(new BaseColor(0, 85, 133));

        if (j == 0) {
            cells[j].setHorizontalAlignment(Element.ALIGN_LEFT);
        } else {
            cells[j].setHorizontalAlignment(Element.ALIGN_CENTER);
        }
    }

    dataprovider = new DataProvider(_con);

    if (Text != null && Text.length > 0) {
        if (Text.length == Value.length) {
            for (int i = 0; i < Value.length; i++) {
                table.addCell(Text[i]);
                table.addCell(Value[i]);
                table.addCell(Value1[i]);
                table.addCell(Value2[i]);
            }
        } else {
            for (int i = 0; i < Value.length; i++) {
                table.addCell("");
                table.addCell("");
                table.addCell("");
                table.addCell("");
            }
        }
    } else {
        table.addCell("");
        table.addCell("");
        table.addCell("");
        table.addCell("");
    }

    preface.add(table);

}

From source file:com.microware.intrahealth.Createpdfall.java

private static void createTable4(Paragraph preface, String[] Header, String Text, String Value)
        throws BadElementException {

    Context _con = null;//from www .j a  v  a 2  s . c  o  m

    PdfPTable table = new PdfPTable(new float[] { 1, 1 });
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    for (int i = 0; i < Header.length; i++) {
        //      table.addCell(new PdfPCell(new Phrase(Header[i], smallBold)));
        PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold));
        c1.getBorder();
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }

    table.setHeaderRows(1);

    PdfPCell[] cells = table.getRow(0).getCells();
    for (int j = 0; j < cells.length; j++) {
        cells[j].setBackgroundColor(new BaseColor(0, 85, 133));

        if (j == 0) {
            cells[j].setHorizontalAlignment(Element.ALIGN_LEFT);
        } else {
            cells[j].setHorizontalAlignment(Element.ALIGN_CENTER);
        }
    }

    dataprovider = new DataProvider(_con);

    if (Text.length() > 0 && Value.length() > 0) {
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(Text, subFont));
        table.addCell(phrase);
        table.addCell(Value);
        PdfPCell[] cells1 = table.getRow(1).getCells();
        cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT);
        cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER);
    } else {
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(Text, subFont));
        table.addCell(phrase);
        table.addCell("");
        PdfPCell[] cells1 = table.getRow(1).getCells();
        cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT);
    }

    preface.add(table);

}

From source file:com.microware.intrahealth.Createpdfall.java

private static void createTable5(Paragraph preface, String[] Header, String[] Text, String[] Value,
        String[] Value1, String[] Value2, String[] Value3) throws BadElementException {

    Context _con = null;/*from ww w.  j av a2s.c o  m*/

    PdfPTable table = new PdfPTable(new float[] { 1, 2, 1, 1, 1 });
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    for (int i = 0; i < Header.length; i++) {
        //      table.addCell(new PdfPCell(new Phrase(Header[i], smallBold)));
        PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold));
        c1.getBorder();
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }

    table.setHeaderRows(1);

    PdfPCell[] cells = table.getRow(0).getCells();
    for (int j = 0; j < cells.length; j++) {
        cells[j].setBackgroundColor(new BaseColor(0, 85, 133));
    }

    dataprovider = new DataProvider(_con);

    if (Text != null && Text.length > 0) {
        if (Text.length == Value.length) {
            for (int i = 0; i < Value.length; i++) {
                table.addCell(Text[i]);
                table.addCell(Value[i]);
                table.addCell(Value1[i]);
                table.addCell(Value2[i]);
                table.addCell(Value3[i]);
            }
        } else {
            for (int i = 0; i < Value.length; i++) {
                table.addCell("");
                table.addCell("");
                table.addCell("");
                table.addCell("");
                table.addCell("");
            }
        }
    } else {
        table.addCell("");
        table.addCell("");
        table.addCell("");
        table.addCell("");
        table.addCell("");
    }

    preface.add(table);

}

From source file:com.microware.intrahealth.Createpdfall.java

private static void createTable6(Paragraph preface, String[] Header, String[] Text, String[] Value,
        String[] Value1, String[] Value2, String[] Value3, String[] Value4) throws BadElementException {

    Context _con = null;/*from w  ww  . j a  v a 2  s .c  om*/

    PdfPTable table = new PdfPTable(new float[] { 1, 2, 1, 1, 1, 1 });
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    for (int i = 0; i < Header.length; i++) {
        //      table.addCell(new PdfPCell(new Phrase(Header[i], smallBold)));
        PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold));
        c1.getBorder();
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }

    table.setHeaderRows(1);

    PdfPCell[] cells = table.getRow(0).getCells();
    for (int j = 0; j < cells.length; j++) {
        cells[j].setBackgroundColor(new BaseColor(0, 85, 133));
    }

    dataprovider = new DataProvider(_con);

    if (Text != null && Text.length > 0) {
        if (Text.length == Value.length) {
            for (int i = 0; i < Value.length; i++) {
                table.addCell(Text[i]);
                table.addCell(Value[i]);
                table.addCell(Value1[i]);
                table.addCell(Value2[i]);
                table.addCell(Value3[i]);
                table.addCell(Value4[i]);
            }
        } else {
            for (int i = 0; i < Value.length; i++) {
                table.addCell("");
                table.addCell("");
                table.addCell("");
                table.addCell("");
                table.addCell("");
                table.addCell("");
            }
        }
    } else {
        table.addCell("");
        table.addCell("");
        table.addCell("");
        table.addCell("");
        table.addCell("");
        table.addCell("");
    }

    preface.add(table);

}

From source file:com.microware.intrahealth.Createpdfall.java

private static void createTable7(Paragraph preface, String Text, String Value) throws BadElementException {

    Context _con = null;/*from  w w w.j  a v a 2  s  .c  om*/

    PdfPTable table = new PdfPTable(new float[] { 1, 2 });
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    for (int i = 0; i < 2; i++) {
        //      table.addCell(new PdfPCell(new Phrase(Header[i], smallBold)));
        PdfPCell c1 = new PdfPCell(new Phrase());
        table.addCell(c1);
    }
    PdfPCell[] cells = table.getRow(0).getCells();
    //        for (int j=0;j<cells.length;j++){
    cells[0].setHorizontalAlignment(Element.ALIGN_LEFT);
    //        }

    dataprovider = new DataProvider(_con);

    if (Text.length() > 0 && Value.length() > 0) {
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(Text, subFont));
        table.addCell(phrase);
        table.addCell(Value);
    } else {
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(Text, subFont));
        table.addCell(phrase);
        table.addCell("");
    }

    preface.add(table);

}

From source file:com.mobicage.rogerthat.enterprise.samples.hr.bizz.GenerateExpenseNote.java

License:Open Source License

public int handle(final User user, final User manager, final ExpenseNote en)
        throws MalformedURLException, IOException, DocumentException {

    log.info("Building list of expenses ...");
    List<Expense> expenses = Expense.list(en);
    log.info("Retrieved " + expenses.size() + " expenses from the datastore");

    log.info("Creating ExpenseNoteDocOutputStream");
    ExpenseNoteDocOutputStream stream = new ExpenseNoteDocOutputStream(en);

    Document document = new Document();
    PdfWriter.getInstance(document, stream);
    document.open();//from w  w  w  .ja  va  2s .  c om

    document.addTitle("Expense note " + en.id + " of " + user.name);
    document.addSubject("Expense note generated by Rogerthat Enterprise!");
    document.addKeywords("expense note");
    document.addAuthor(user.name);
    document.addCreator("Rogerthat OneApp Enterprise Mobility");

    Paragraph preface = new Paragraph();

    preface.add(new Paragraph("TP Vision expense note", titleFont));
    preface.add(new Paragraph(" "));

    DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
    Date date = new Date();
    preface.add(new Paragraph("Date: " + dateFormat.format(date)));
    preface.add(new Paragraph("Requestor: " + user.name));
    preface.add(new Paragraph("Approver: " + manager.name));
    preface.add(new Paragraph(" "));

    PdfPTable table = new PdfPTable(7);
    table.setWidthPercentage(110);
    table.setWidths(new int[] { 5, 15, 15, 35, 10, 15, 10 });
    addHeader(table, "Id");
    addHeader(table, "Date");
    addHeader(table, "Nature");
    addHeader(table, "Description");
    addHeader(table, "Account");
    addHeader(table, "Amount");
    addHeader(table, "Voucher");
    table.setHeaderRows(1);

    Collections.sort(expenses, new Comparator<Expense>() {
        @Override
        public int compare(Expense e1, Expense e2) {
            return (int) (e1.date - e2.date);
        }
    });
    int i = 0;
    double total = 0;
    for (Expense expense : expenses) {
        PdfPCell c1 = new PdfPCell(new Phrase("" + ++i));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
        table.addCell(dateFormat.format(new Date(expense.date * 1000)));
        table.addCell(expense.nature);
        table.addCell(expense.description);
        table.addCell("" + expense.account);
        c1 = new PdfPCell(new Phrase(DECIMAL_FORMAT.format(expense.amount) + " " + expense.currency));
        c1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(c1);
        table.addCell(expense.voucher);
        total += expense.amount;
    }

    preface.add(table);

    preface.add(new Paragraph(" "));
    preface.add(new Paragraph("Total: " + DECIMAL_FORMAT.format(total), titleFont));

    document.add(preface);

    i = 0;
    for (Expense expense : expenses) {
        i++;
        if (expense.receipt == null)
            continue;

        document.newPage();
        Paragraph receipt = new Paragraph();
        receipt.add(new Paragraph("Attachment " + i, titleFont));
        document.add(receipt);
        Image image = Image.getInstance(new URL(expense.receipt));
        image.setRotationDegrees(-90);
        float scaler = (document.getPageSize().getWidth() / image.getWidth()) * 100;

        image.scalePercent(scaler);
        document.add(image);
    }

    document.close();
    stream.close();

    return stream.getSize();

}