Example usage for com.lowagie.text.pdf PdfPTable setWidthPercentage

List of usage examples for com.lowagie.text.pdf PdfPTable setWidthPercentage

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable setWidthPercentage.

Prototype

public void setWidthPercentage(float widthPercentage) 

Source Link

Document

Sets the width percentage that the table will occupy in the page.

Usage

From source file:org.posterita.core.TabularReport.java

License:Open Source License

/**
 * Get Selling Items Data/*from  w  w w  . jav  a2 s.  c o  m*/
 * @return
 * @throws DocumentException
 * @throws OperationException 
 */
public byte[] getSellingItemsData() throws DocumentException, OperationException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    Document document = new Document(PageSize.A4);
    PdfWriter pdfWriter = PdfWriter.getInstance(document, bos);

    document.open();

    // Font Syle
    Font style1 = new Font(Font.TIMES_ROMAN, 12.0f, Font.BOLD);
    Font style2 = new Font(Font.TIMES_ROMAN, 8.0f, Font.BOLD);
    Font style3 = new Font(Font.TIMES_ROMAN, 8.0f);
    Font style4 = new Font(Font.TIMES_ROMAN, 9.0f, Font.BOLD);
    Font style5 = new Font(Font.TIMES_ROMAN, 6.0f);
    float[] widths = { 2f, 0.5f, 0.5f, 1.0f };

    // Table header
    PdfPTable mytable = new PdfPTable(4);
    mytable.setTotalWidth(widths);
    mytable.setWidthPercentage(100f);
    PdfPCell header = new PdfPCell(new Paragraph(
            new Chunk(getTitle(), style1) + "\n" + new Chunk(getSubtitle(), style2) + "\n", style1));
    header.setColspan(4);
    header.setHorizontalAlignment(Element.ALIGN_CENTER);
    header.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
    mytable.addCell(header);

    //Date Header
    PdfPCell dateHeader = new PdfPCell(new Paragraph(
            "From : " + new Chunk(TimestampConvertor.convertTimeStampToFyracleDate(fromDate), style1), style1));
    dateHeader.setColspan(1);
    dateHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    dateHeader.setBackgroundColor(Color.GRAY);
    dateHeader.setBorderColor(Color.WHITE);
    mytable.addCell(dateHeader);

    dateHeader = new PdfPCell(new Paragraph(
            "To : " + new Chunk(TimestampConvertor.convertTimeStampToFyracleDate(toDate), style1), style1));
    dateHeader.setColspan(3);
    dateHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    dateHeader.setBackgroundColor(Color.GRAY);
    dateHeader.setBorderColor(Color.WHITE);
    mytable.addCell(dateHeader);

    // Info Header
    PdfPCell infoHeader = new PdfPCell(
            new Paragraph("ALL VALUES ARE EXCLUSIVE OF VAT - SALES FIGURES ARE TAKEN AFTER DISCOUNT", style5));
    infoHeader.setColspan(4);
    infoHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
    infoHeader.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
    mytable.addCell(infoHeader);

    // Rows Header
    PdfPCell rowHeader = new PdfPCell(new Paragraph("PRODUCT NAME", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("QTY", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("VALUE", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("SUPPLIER", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    document.add(mytable);

    Object[] headers = reportData.get(0);

    PdfPTable table = new PdfPTable(headers.length);

    table.setTotalWidth(widths);
    table.setWidthPercentage(100f);
    for (Object[] row : reportData) {

        for (Object data : row) {
            PdfPCell dataCell = new PdfPCell(new Phrase(data.toString(), style3));
            table.addCell(dataCell);
        }
    }

    document.add(table);
    document.close();

    return bos.toByteArray();
}

From source file:org.posterita.core.TabularReport.java

License:Open Source License

/**
 * Get Stock Enquiry Report Data//from   w w w .  ja v  a2 s  .  c o  m
 * @return
 * @throws DocumentException
 * @throws OperationException 
 */
public byte[] getStockEnquiryData() throws DocumentException, OperationException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    Document document = new Document(PageSize.A4);
    PdfWriter pdfWriter = PdfWriter.getInstance(document, bos);

    document.open();

    // Font Syle
    Font style1 = new Font(Font.TIMES_ROMAN, 12.0f, Font.BOLD);
    Font style2 = new Font(Font.TIMES_ROMAN, 8.0f, Font.BOLD);
    Font style3 = new Font(Font.TIMES_ROMAN, 8.0f);
    Font style4 = new Font(Font.TIMES_ROMAN, 7.0f, Font.BOLD);
    Font style5 = new Font(Font.TIMES_ROMAN, 6.0f);
    float[] widths = { 1f, 2f, 0.5f, 0.5f, 0.5f, 0.5f };

    // Table header
    PdfPTable mytable = new PdfPTable(6);
    mytable.setTotalWidth(widths);
    mytable.setWidthPercentage(100f);
    PdfPCell header = new PdfPCell(
            new Paragraph(new Chunk(title, style1) + "\n" + new Chunk(subtitle, style2) + "\n", style1));
    header.setColspan(6);
    header.setHorizontalAlignment(Element.ALIGN_CENTER);
    header.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
    mytable.addCell(header);

    //Date Header
    PdfPCell dateHeader = new PdfPCell(new Paragraph(
            "From : " + new Chunk(TimestampConvertor.convertTimeStampToFyracleDate(fromDate), style1), style1));
    dateHeader.setColspan(2);
    dateHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    dateHeader.setBackgroundColor(Color.GRAY);
    dateHeader.setBorderColor(Color.WHITE);
    mytable.addCell(dateHeader);

    dateHeader = new PdfPCell(new Paragraph(
            "To : " + new Chunk(TimestampConvertor.convertTimeStampToFyracleDate(toDate), style1), style1));
    dateHeader.setColspan(4);
    dateHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    dateHeader.setBackgroundColor(Color.GRAY);
    dateHeader.setBorderColor(Color.WHITE);
    mytable.addCell(dateHeader);

    // Info Header
    PdfPCell infoHeader = new PdfPCell(
            new Paragraph("ALL VALUES ARE EXCLUSIVE OF VAT & BASED ON PURCHASE PRICES", style5));
    infoHeader.setColspan(6);
    infoHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
    infoHeader.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
    mytable.addCell(infoHeader);

    // Rows Header
    PdfPCell rowHeader = new PdfPCell(new Paragraph("BARCODE", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("PRODUCT NAME", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("Opening Stock Qty", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("Opening Stock Value", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("Closing Stock Qty", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("Closing Stock Value", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    document.add(mytable);

    Object[] headers = reportData.get(0);

    PdfPTable table = new PdfPTable(headers.length);

    table.setTotalWidth(widths);
    table.setWidthPercentage(100f);
    for (Object[] row : reportData) {

        for (Object data : row) {
            PdfPCell dataCell = new PdfPCell(new Phrase(data.toString(), style3));
            table.addCell(dataCell);
        }
    }

    document.add(table);
    document.close();

    return bos.toByteArray();
}

From source file:org.posterita.core.TabularReport.java

License:Open Source License

public byte[] getInventoryData() throws DocumentException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    Document document = new Document(PageSize.A4);
    PdfWriter pdfWriter = PdfWriter.getInstance(document, bos);

    document.open();/*w w  w . j  av a2  s  . c o  m*/

    // Font Syle
    Font style1 = new Font(Font.TIMES_ROMAN, 12.0f, Font.BOLD);
    Font style2 = new Font(Font.TIMES_ROMAN, 8.0f, Font.BOLD);
    Font style3 = new Font(Font.TIMES_ROMAN, 8.0f);
    Font style4 = new Font(Font.TIMES_ROMAN, 8.0f, Font.BOLD);
    float[] widths = { 1f, 1f, 0.55f, 0.55f, 0.55f, 1f, 1f, 1f, 1f };

    // Table header
    PdfPTable mytable = new PdfPTable(9);
    mytable.setTotalWidth(widths);
    mytable.setWidthPercentage(100f);
    PdfPCell header = new PdfPCell(new Paragraph(getTitle() + "\n" + getSubtitle(), style1));
    header.setColspan(9);
    header.setHorizontalAlignment(Element.ALIGN_CENTER);
    header.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
    mytable.addCell(header);

    // Table sub header        
    PdfPCell subheader = new PdfPCell();
    subheader = new PdfPCell(new Paragraph(""));
    subheader.setColspan(2);
    mytable.addCell(subheader);

    subheader = new PdfPCell(new Paragraph("QUANTITY", style2));
    subheader.setColspan(3);
    subheader.setHorizontalAlignment(Element.ALIGN_CENTER);
    mytable.addCell(subheader);

    subheader = new PdfPCell(new Paragraph("VALUE (Excl. VAT)", style2));
    subheader.setColspan(2);
    subheader.setHorizontalAlignment(Element.ALIGN_CENTER);
    mytable.addCell(subheader);

    subheader = new PdfPCell(new Paragraph("DIFFERENCE", style2));
    subheader.setColspan(2);
    subheader.setHorizontalAlignment(Element.ALIGN_CENTER);
    mytable.addCell(subheader);

    // Rows Header
    PdfPCell rowHeader = new PdfPCell(new Paragraph("BARCODE", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("PRODUCT", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("CSV", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("BOOK", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("COUNT", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("BOOK", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("COUNT", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("QUANTITY", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("VALUE (Excl. VAT)", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    document.add(mytable);

    Object[] headers = reportData.get(0);

    PdfPTable table = new PdfPTable(headers.length);

    table.setTotalWidth(widths);
    table.setWidthPercentage(100f);
    for (Object[] row : reportData) {

        for (Object data : row) {
            PdfPCell dataCell = new PdfPCell(new Phrase(data.toString(), style3));
            table.addCell(dataCell);
        }
    }

    document.add(table);
    document.close();

    return bos.toByteArray();
}

From source file:org.posterita.core.TabularReport2.java

License:Open Source License

public String createPDFReport() throws DocumentException, FileNotFoundException {
    String filename = RandomStringGenerator.randomstring() + ".pdf";
    String filepath = ReportManager.getReportPath(filename);

    FileOutputStream fos = new FileOutputStream(filepath);

    Document document = new Document(PageSize.A4.rotate());
    PdfWriter pdfWriter = PdfWriter.getInstance(document, fos);

    document.open();//  ww  w.  j  av a2  s .  c  o  m

    Font style1 = new Font(Font.HELVETICA, 16.0f, Font.BOLD);
    Font style2 = new Font(Font.HELVETICA, 14.0f);
    Font style3 = new Font(Font.HELVETICA, 10.0f);

    //write content
    Paragraph p = new Paragraph(new Chunk(title, style1));
    p.setAlignment(Element.ALIGN_CENTER);
    document.add(p);

    p = new Paragraph(new Chunk(subtitle, style2));
    p.setAlignment(Element.ALIGN_CENTER);
    document.add(p);

    p = new Paragraph("\n\n");
    document.add(p);

    Object[] headers = reportData.get(0);

    PdfPTable table = new PdfPTable(headers.length);
    table.setWidthPercentage(100.0f);

    //int[] widths = new int[]{1,2,1,4};
    //table.setWidths(widths);

    for (Object[] row : reportData) {
        for (Object data : row) {
            PdfPCell cell = new PdfPCell(new Phrase(data.toString(), style3));
            table.addCell(cell);
        }
    }

    document.add(table);
    document.close();

    return filename;
}

From source file:org.posterita.core.TabularReportMerge.java

License:Open Source License

public byte[] getPDFData() throws DocumentException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    Document document = new Document(PageSize.A4);
    PdfWriter pdfWriter = PdfWriter.getInstance(document, bos);

    document.open();/*from  ww w.  j  a va 2 s  .  c o m*/

    // Font Syle
    Font style1 = new Font(Font.TIMES_ROMAN, 12.0f, Font.BOLD);
    Font style2 = new Font(Font.TIMES_ROMAN, 8.0f, Font.BOLD);
    Font style3 = new Font(Font.TIMES_ROMAN, 8.0f);
    Font style4 = new Font(Font.TIMES_ROMAN, 9.0f, Font.BOLD);
    float[] widths = { 2f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f };

    // Table header
    PdfPTable mytable = new PdfPTable(7);
    mytable.setTotalWidth(widths);
    mytable.setWidthPercentage(100f);
    PdfPCell header = new PdfPCell(
            new Paragraph(new Chunk(title, style1) + "\n" + new Chunk(subtitle, style2) + "\n", style1));
    header.setColspan(7);
    header.setHorizontalAlignment(Element.ALIGN_CENTER);
    header.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
    mytable.addCell(header);

    // Table sub header        
    PdfPCell subheader = new PdfPCell();
    subheader = new PdfPCell(new Paragraph(""));
    mytable.addCell(subheader);

    subheader = new PdfPCell(new Paragraph("QUANTITY", style2));
    subheader.setColspan(2);
    subheader.setHorizontalAlignment(Element.ALIGN_CENTER);
    mytable.addCell(subheader);

    subheader = new PdfPCell(new Paragraph("VALUE (Excl. VAT)", style2));
    subheader.setColspan(2);
    subheader.setHorizontalAlignment(Element.ALIGN_CENTER);
    mytable.addCell(subheader);

    subheader = new PdfPCell(new Paragraph("DISCREPANCY", style2));
    subheader.setColspan(2);
    subheader.setHorizontalAlignment(Element.ALIGN_CENTER);
    mytable.addCell(subheader);

    // Rows Header
    PdfPCell rowHeader = new PdfPCell(new Paragraph("PRODUCT NAME", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("BOOK", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("COUNT", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("BOOK", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("COUNT", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("QTY", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("VALUE", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    document.add(mytable);

    Object[] headers = reportData.get(0);

    PdfPTable table = new PdfPTable(headers.length);

    table.setTotalWidth(widths);
    table.setWidthPercentage(100f);
    for (Object[] row : reportData) {

        for (Object data : row) {
            PdfPCell dataCell = new PdfPCell(new Phrase(data.toString(), style3));
            table.addCell(dataCell);
        }
    }

    document.add(table);
    document.close();

    return bos.toByteArray();
}

From source file:org.posterita.core.TabularReportMerge.java

License:Open Source License

/**
 * Get Selling Items Data/* w  w w  . j  a  v  a2 s  .  com*/
 * @return
 * @throws DocumentException
 * @throws OperationException 
 */
public byte[] getSellingItemsData() throws DocumentException, OperationException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    Document document = new Document(PageSize.A4);
    PdfWriter pdfWriter = PdfWriter.getInstance(document, bos);

    document.open();

    // Font Syle
    Font style1 = new Font(Font.TIMES_ROMAN, 12.0f, Font.BOLD);
    Font style2 = new Font(Font.TIMES_ROMAN, 8.0f, Font.BOLD);
    Font style3 = new Font(Font.TIMES_ROMAN, 8.0f);
    Font style4 = new Font(Font.TIMES_ROMAN, 9.0f, Font.BOLD);
    Font style5 = new Font(Font.TIMES_ROMAN, 6.0f);
    float[] widths = { 2f, 0.5f, 0.5f, 1.0f };

    // Table header
    PdfPTable mytable = new PdfPTable(4);
    mytable.setTotalWidth(widths);
    mytable.setWidthPercentage(100f);
    PdfPCell header = new PdfPCell(
            new Paragraph(new Chunk(title, style1) + "\n" + new Chunk(subtitle, style2) + "\n", style1));
    header.setColspan(4);
    header.setHorizontalAlignment(Element.ALIGN_CENTER);
    header.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
    mytable.addCell(header);

    //Date Header
    PdfPCell dateHeader = new PdfPCell(new Paragraph("From : " + new Chunk(
            TimestampConvertor.convertTimeStamp(fromDate, TimestampConvertor.DEFAULT_DATE_PATTERN1), style1),
            style1));
    dateHeader.setColspan(1);
    dateHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    dateHeader.setBackgroundColor(Color.GRAY);
    dateHeader.setBorderColor(Color.WHITE);
    mytable.addCell(dateHeader);

    dateHeader = new PdfPCell(new Paragraph("To : " + new Chunk(
            TimestampConvertor.convertTimeStamp(toDate, TimestampConvertor.DEFAULT_DATE_PATTERN1), style1),
            style1));
    dateHeader.setColspan(3);
    dateHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    dateHeader.setBackgroundColor(Color.GRAY);
    dateHeader.setBorderColor(Color.WHITE);
    mytable.addCell(dateHeader);

    // Info Header
    PdfPCell infoHeader = new PdfPCell(
            new Paragraph("ALL VALUES ARE EXCLUSIVE OF VAT - SALES FIGURES ARE TAKEN AFTER DISCOUNT", style5));
    infoHeader.setColspan(4);
    infoHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
    infoHeader.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
    mytable.addCell(infoHeader);

    // Rows Header
    PdfPCell rowHeader = new PdfPCell(new Paragraph("PRODUCT NAME", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("QTY", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("VALUE", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("SUPPLIER", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    document.add(mytable);

    Object[] headers = reportData.get(0);

    PdfPTable table = new PdfPTable(headers.length);

    table.setTotalWidth(widths);
    table.setWidthPercentage(100f);
    for (Object[] row : reportData) {

        for (Object data : row) {
            PdfPCell dataCell = new PdfPCell(new Phrase(data.toString(), style3));
            table.addCell(dataCell);
        }
    }

    document.add(table);
    document.close();

    return bos.toByteArray();
}

From source file:org.posterita.core.TabularReportMerge.java

License:Open Source License

/**
 * Get Stock Enquiry Report Data//w ww .j a va  2  s  . c om
 * @return
 * @throws DocumentException
 * @throws OperationException 
 */
public byte[] getStockEnquiryData() throws DocumentException, OperationException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    Document document = new Document(PageSize.A4);
    PdfWriter pdfWriter = PdfWriter.getInstance(document, bos);

    document.open();

    // Font Syle
    Font style1 = new Font(Font.TIMES_ROMAN, 12.0f, Font.BOLD);
    Font style2 = new Font(Font.TIMES_ROMAN, 8.0f, Font.BOLD);
    Font style3 = new Font(Font.TIMES_ROMAN, 8.0f);
    Font style4 = new Font(Font.TIMES_ROMAN, 7.0f, Font.BOLD);
    Font style5 = new Font(Font.TIMES_ROMAN, 6.0f);
    float[] widths = { 1f, 2f, 0.5f, 0.5f, 0.5f, 0.5f };

    // Table header
    PdfPTable mytable = new PdfPTable(6);
    mytable.setTotalWidth(widths);
    mytable.setWidthPercentage(100f);
    PdfPCell header = new PdfPCell(
            new Paragraph(new Chunk(title, style1) + "\n" + new Chunk(subtitle, style2) + "\n", style1));
    header.setColspan(6);
    header.setHorizontalAlignment(Element.ALIGN_CENTER);
    header.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
    mytable.addCell(header);

    //Date Header
    PdfPCell dateHeader = new PdfPCell(new Paragraph("From : " + new Chunk(
            TimestampConvertor.convertTimeStamp(fromDate, TimestampConvertor.DEFAULT_DATE_PATTERN1), style1),
            style1));
    dateHeader.setColspan(2);
    dateHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    dateHeader.setBackgroundColor(Color.GRAY);
    dateHeader.setBorderColor(Color.WHITE);
    mytable.addCell(dateHeader);

    dateHeader = new PdfPCell(new Paragraph("To : " + new Chunk(
            TimestampConvertor.convertTimeStamp(toDate, TimestampConvertor.DEFAULT_DATE_PATTERN1), style1),
            style1));
    dateHeader.setColspan(4);
    dateHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    dateHeader.setBackgroundColor(Color.GRAY);
    dateHeader.setBorderColor(Color.WHITE);
    mytable.addCell(dateHeader);

    // Info Header
    PdfPCell infoHeader = new PdfPCell(
            new Paragraph("ALL VALUES ARE EXCLUSIVE OF VAT & BASED ON PURCHASE PRICES", style5));
    infoHeader.setColspan(6);
    infoHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
    infoHeader.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
    mytable.addCell(infoHeader);

    // Rows Header
    PdfPCell rowHeader = new PdfPCell(new Paragraph("BARCODE", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("PRODUCT NAME", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("Opening Stock Qty", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("Opening Stock Value", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("Closing Stock Qty", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    rowHeader = new PdfPCell(new Paragraph("Closing Stock Value", style4));
    rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
    mytable.addCell(rowHeader);

    document.add(mytable);

    Object[] headers = reportData.get(0);

    PdfPTable table = new PdfPTable(headers.length);

    table.setTotalWidth(widths);
    table.setWidthPercentage(100f);
    for (Object[] row : reportData) {

        for (Object data : row) {
            PdfPCell dataCell = new PdfPCell(new Phrase(data.toString(), style3));
            table.addCell(dataCell);
        }
    }

    document.add(table);
    document.close();

    return bos.toByteArray();
}

From source file:org.revager.export.InvitationPDFExporter.java

License:Open Source License

/**
 * Write the title page of the PDF document.
 * // w  w  w  .  j  av a  2  s  . c  om
 * @throws ExportException
 *             If an error occurs while creating the title page
 */
private void writeTitlePage() throws ExportException {
    try {
        Font plainFontTitle = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 12);

        Font boldFontTitle = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 12);

        Font boldItalicFontTitle = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 12);

        Font plainFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED),
                10);

        Font boldFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font boldItalicFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font italicFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font italicFontSmall = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 9);

        Phrase phraseStrut = new Phrase(" ");
        phraseStrut.setLeading(leading);

        /*
         * date and time of the meeting
         */
        String meetingDate = sdfDate.format(meeting.getPlannedDate().getTime());

        String meetingTime = sdfTime.format(meeting.getPlannedStart().getTime()) + " - "
                + sdfTime.format(meeting.getPlannedEnd().getTime()) + " ["
                + meeting.getPlannedEnd().getTimeZone().getDisplayName() + "]";
        ;

        /*
         * Base table
         */
        PdfPTable table = new PdfPTable(new float[] { 0.04f, 0.96f });
        table.setWidthPercentage(100);
        table.setSplitRows(false);
        table.getDefaultCell().setBorderWidth(0);
        table.getDefaultCell().setPadding(0);

        /*
         * recipient of the invitation
         */
        PdfPCell cell = new PdfPCell();
        cell.setBorder(0);
        cell.setColspan(2);
        cell.setPadding(padding);

        cell.addElement(phraseStrut);

        PdfPTable tableRecipient = new PdfPTable(2);
        tableRecipient.setWidthPercentage(100);
        tableRecipient.setSplitRows(false);
        tableRecipient.getDefaultCell().setBorderWidth(0);
        tableRecipient.getDefaultCell().setPadding(0);

        PdfPCell cellRecipient = new PdfPCell();
        cellRecipient.setBorder(0);
        cellRecipient.setPadding(0);
        cellRecipient.addElement(new Phrase(translate("To:"), plainFontTitle));
        cellRecipient.addElement(new Phrase(attendee.getName(), boldFontTitle));

        tableRecipient.addCell(cellRecipient);

        PdfPCell cellDate = new PdfPCell(new Phrase(sdfDate.format(new Date().getTime()), plainFont));
        cellDate.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cellDate.setBorder(0);
        cellDate.setPadding(0);
        cellDate.setPaddingTop(7);

        tableRecipient.addCell(cellDate);

        cell.addElement(tableRecipient);

        cell.addElement(phraseStrut);
        cell.addElement(phraseStrut);
        cell.addElement(phraseStrut);

        /*
         * subject
         */
        cell.addElement(new Phrase(translate("Invitation for the Meeting on") + " " + meetingDate,
                boldItalicFontTitle));

        cell.addElement(phraseStrut);

        /*
         * invitation text
         */
        Phrase phrase = new Phrase(
                Data.getInstance().getAppData().getSetting(AppSettingKey.PDF_INVITATION_TEXT), plainFont);
        phrase.setLeading(leading);

        cell.addElement(phrase);

        cell.addElement(phraseStrut);

        table.addCell(cell);

        /*
         * meeting date, time and location
         */
        cell = new PdfPCell(new Phrase(meetingDate, boldItalicFont));
        cell.setBorder(0);
        cell.setColspan(2);
        cell.setPadding(padding);
        cell.setPaddingBottom(0);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);

        table.addCell(cell);

        cell = new PdfPCell(new Phrase(meetingTime, italicFont));
        cell.setBorder(0);
        cell.setColspan(2);
        cell.setPadding(padding);
        cell.setPaddingBottom(0);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);

        table.addCell(cell);

        if (!meeting.getPlannedLocation().equals("")) {
            cell = new PdfPCell(
                    new Phrase(translate("Location") + ": " + meeting.getPlannedLocation(), italicFont));
            cell.setBorder(0);
            cell.setColspan(2);
            cell.setPadding(padding);
            cell.setPaddingBottom(0);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);

            table.addCell(cell);
        }

        /*
         * role; review title and description
         */
        cell = new PdfPCell();
        cell.setBorder(0);
        cell.setColspan(2);
        cell.setPadding(padding);

        cell.addElement(phraseStrut);
        cell.addElement(phraseStrut);

        phrase = new Phrase();
        phrase.setLeading(leading);
        phrase.add(new Chunk(MessageFormat.format(translate("You are invited as {0} to this review ({1})."),
                translate(attendee.getRole().toString()), getReviewTitle()), boldFont));

        cell.addElement(phrase);

        cell.addElement(phraseStrut);

        cell.addElement(new Phrase(resiData.getReview().getDescription(), italicFont));

        cell.addElement(phraseStrut);

        /*
         * Predecessor meeting
         */
        if (meetMgmt.getPredecessorMeeting(meeting) != null) {
            String preMeetingDate = sdfDate
                    .format(meetMgmt.getPredecessorMeeting(meeting).getProtocol().getDate().getTime());

            cell.addElement(new Phrase(MessageFormat
                    .format(translate("This meeting ties up to the review meeting of {0}."), preMeetingDate),
                    plainFont));

            cell.addElement(phraseStrut);
        }

        /*
         * If there is a product name defined
         */
        if (!Data.getInstance().getResiData().getReview().getProduct().getName().trim().equals("")) {
            /*
             * the product of this review
             */
            cell.addElement(new Phrase(translate("The following product will be reviewed:"), plainFont));
            cell.addElement(phraseStrut);

            table.addCell(cell);

            /*
             * Write name and version of the reviewed product
             */
            Phrase phrName = new Phrase(Data.getInstance().getResiData().getReview().getProduct().getName(),
                    boldItalicFont);
            phrName.setLeading(leading);

            PdfPCell cellName = new PdfPCell(phrName);
            cellName.setColspan(2);
            cellName.setBorderWidth(0);
            cellName.setPadding(padding);
            cellName.setPaddingBottom(0);
            cellName.setHorizontalAlignment(Element.ALIGN_CENTER);

            table.addCell(cellName);

            /*
             * If there is a product version defined
             */
            if (!Data.getInstance().getResiData().getReview().getProduct().getVersion().trim().equals("")) {
                Phrase phrVersion = new Phrase(
                        translate("Product Version") + ": "
                                + Data.getInstance().getResiData().getReview().getProduct().getVersion(),
                        italicFont);
                phrVersion.setLeading(leading);

                PdfPCell cellVersion = new PdfPCell(phrVersion);
                cellVersion.setColspan(2);
                cellVersion.setBorderWidth(0);
                cellVersion.setPadding(padding);
                cellVersion.setPaddingBottom(0);
                cellVersion.setHorizontalAlignment(Element.ALIGN_CENTER);

                table.addCell(cellVersion);
            }

            table.addCell(createVerticalStrut(PDFTools.cmToPt(0.7f), 2));
        } else {
            table.addCell(cell);
        }

        boolean showBottomStrut = false;

        /*
         * List point used for lists
         */
        Phrase phraseListPoint = new Phrase("", boldFont);
        phraseListPoint.setLeading(leading);

        PdfPCell cellListPoint = new PdfPCell();
        cellListPoint.addElement(phraseListPoint);
        cellListPoint.setBorderWidth(0);
        cellListPoint.setPadding(padding);
        cellListPoint.setPaddingLeft(padding * 2);
        cellListPoint.setPaddingBottom(0);

        /*
         * Textual references
         */
        for (String ref : Application.getInstance().getReviewMgmt().getProductReferences()) {
            Phrase phraseRef = new Phrase(ref, italicFontSmall);
            phraseRef.setLeading(leading);

            PdfPCell cellRef = new PdfPCell();
            cellRef.addElement(phraseRef);
            cellRef.setBorderWidth(0);
            cellRef.setPadding(padding);
            cellRef.setPaddingBottom(0);

            table.addCell(cellListPoint);

            table.addCell(cellRef);

            showBottomStrut = true;
        }

        /*
         * External file references
         */
        for (File ref : Application.getInstance().getReviewMgmt().getExtProdReferences()) {
            Phrase phraseRef = new Phrase();
            phraseRef.add(new Chunk(ref.getName(), italicFontSmall));
            phraseRef.add(new Chunk(" (" + translate("File Attachment") + ")", italicFontSmall));
            phraseRef.setFont(plainFont);
            phraseRef.setLeading(leading);

            PdfPCell cellRef = new PdfPCell();
            cellRef.addElement(phraseRef);
            cellRef.setBorderWidth(0);
            cellRef.setPadding(padding);
            cellRef.setPaddingBottom(0);

            table.addCell(cellListPoint);

            if (attachProdExtRefs) {
                cellRef.setCellEvent(new PDFCellEventExtRef(pdfWriter, ref));
            }

            table.addCell(cellRef);

            showBottomStrut = true;
        }

        if (showBottomStrut) {
            table.addCell(createVerticalStrut(PDFTools.cmToPt(0.4f), 2));
        }

        /*
         * "please prepare" for the reviwers; on questions ask moderators
         */
        cell = new PdfPCell();
        cell.setBorder(0);
        cell.setColspan(2);
        cell.setPadding(padding);

        phrase = new Phrase();
        phrase.setLeading(leading);

        if (attendee.getAspects() != null) {
            phrase.add(new Chunk(translate(
                    "Please prepare for the review meeting by checking the product for the aspects which are associated to you.")
                    + " ", plainFont));
        }

        List<Attendee> moderators = new ArrayList<Attendee>();
        for (Attendee a : Application.getInstance().getAttendeeMgmt().getAttendees()) {
            if (a.getRole() == Role.MODERATOR) {
                moderators.add(a);
            }
        }

        if (moderators.size() == 1 && attendee.getRole() != Role.MODERATOR) {
            phrase.add(new Chunk(translate(
                    "Please do not hesitate to contact the review moderator if you have any questions:") + " ",
                    plainFont));
        } else if (moderators.size() > 1 && attendee.getRole() != Role.MODERATOR) {
            phrase.add(new Chunk(translate(
                    "Please do not hesitate to contact one of the review moderators if you have any questions:")
                    + " ", plainFont));
        }

        cell.addElement(phrase);

        Phrase phraseStrutSmall = new Phrase(" ");
        phraseStrutSmall.setLeading(leading / 2);

        if (moderators.size() > 0 && attendee.getRole() != Role.MODERATOR) {
            for (Attendee mod : moderators) {
                cell.addElement(phraseStrutSmall);
                cell.addElement(new Phrase(mod.getName(), boldFont));
                cell.addElement(new Phrase(mod.getContact(), italicFont));
            }
        }

        table.addCell(cell);

        pdfDoc.add(table);
    } catch (Exception e) {
        /*
         * Not part of unit testing because this exception is only thrown if
         * an internal error occurs.
         */
        throw new ExportException(translate("Cannot generate front page of the PDF document."));
    }
}

From source file:org.revager.export.InvitationPDFExporter.java

License:Open Source License

/**
 * Write the aspects./*w  w w  . j av a 2s .  c  o  m*/
 * 
 * @throws ExportException
 *             If an error occurs while writing the aspects
 */
private void writeAspects() throws ExportException {
    /*
     * If the role of the attendee is not reviewer show all aspects
     */
    List<Aspect> aspects = null;

    if (attendee.getRole() == Role.REVIEWER) {
        aspects = attMgmt.getAspects(attendee);
    } else {
        aspects = aspMgmt.getAspects();
    }

    if (aspects.size() == 0) {
        return;
    }

    try {
        Font descriptionFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font directiveFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font categoryFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font reviewerFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 9);

        /*
         * Build base table for all attendees
         */
        PdfPTable tableAspects = new PdfPTable(1);
        tableAspects.setWidthPercentage(100);
        tableAspects.setSplitRows(false);
        tableAspects.getDefaultCell().setBorderWidth(0);
        tableAspects.getDefaultCell().setPadding(0);

        boolean grayBackground = true;

        for (Aspect asp : aspects) {
            /*
             * Build table for one aspect
             */
            PdfPTable tableAspect = new PdfPTable(new float[] { 0.70f, 0.30f });
            tableAspect.setWidthPercentage(100);
            tableAspect.getDefaultCell().setBorderWidth(0);
            tableAspect.getDefaultCell().setPadding(0);

            PdfPCell cellAspect = new PdfPCell();
            cellAspect.setPadding(0);
            cellAspect.setBorder(0);

            Phrase phraseStrut = new Phrase(" ");
            phraseStrut.setLeading(leading * 0.4f);

            /*
             * directive and description of the aspect
             */
            PdfPCell cell = new PdfPCell();
            cell.setBorderWidth(0);
            cell.setPadding(padding * 0.4f);
            cell.setPaddingBottom(padding * 1.5f);
            cell.addElement(new Phrase(asp.getDirective(), directiveFont));
            cell.addElement(phraseStrut);
            cell.addElement(new Phrase(asp.getDescription(), descriptionFont));

            /*
             * the reviewers of this aspect (moderator only)
             */
            if (attendee.getRole() == Role.MODERATOR) {
                cell.addElement(phraseStrut);
                cell.addElement(phraseStrut);

                String separator = "";

                Phrase phraseReviewers = new Phrase();
                phraseReviewers.setLeading(leading);
                phraseReviewers.setFont(reviewerFont);

                for (Attendee att : attMgmt.getAttendees()) {
                    if (attMgmt.hasAspect(asp, att)) {
                        phraseReviewers.add(new Chunk(separator + att.getName(), reviewerFont));

                        separator = "    ";
                    }
                }

                cell.addElement(phraseReviewers);
            }

            tableAspect.addCell(cell);

            /*
             * category of the aspect
             */
            cell = new PdfPCell(new Phrase(asp.getCategory(), categoryFont));
            cell.setBorderWidth(0);
            cell.setPadding(padding * 0.4f);
            cell.setPaddingTop(padding * 1.1f);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

            tableAspect.addCell(cell);

            cellAspect.addElement(tableAspect);
            cellAspect.setPadding(0);
            cellAspect.setPaddingLeft(padding);
            cellAspect.setPaddingRight(padding);

            if (grayBackground == true) {
                grayBackground = false;
                cellAspect.setBackgroundColor(cellBackground);
            } else {
                grayBackground = true;
            }

            /*
             * Add aspect to the list
             */
            tableAspects.addCell(cellAspect);
        }

        PdfPCell cellBottomLine = new PdfPCell();
        cellBottomLine.setPadding(0);
        cellBottomLine.setBorderWidth(0);
        cellBottomLine.setBorderWidthBottom(1);
        cellBottomLine.setBorderColor(cellBackground);

        tableAspects.addCell(cellBottomLine);

        /*
         * Add the attendee base table to the document
         */
        pdfDoc.add(tableAspects);
    } catch (Exception e) {
        /*
         * Not part of unit testing because this exception is only thrown if
         * an internal error occurs.
         */
        throw new ExportException(translate("Cannot put aspects into the PDF document."));
    }
}

From source file:org.revager.export.InvitationPDFExporter.java

License:Open Source License

@Override
protected void writeContent() throws ExportException {
    try {//from  ww  w.j  av a  2 s. c  o m
        writeTitlePage();

        Font italicFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        PdfPTable tableAspIntro = new PdfPTable(1);
        tableAspIntro.setWidthPercentage(100);

        Phrase phraseAspIntro;

        PdfPCell cellAspIntro = new PdfPCell();
        cellAspIntro.setBorderWidth(0);
        cellAspIntro.setPadding(0);
        cellAspIntro.setPaddingBottom(PDFTools.cmToPt(0.8f));

        if (attendee.getAspects() != null) {
            pdfDoc.newPage();

            phraseAspIntro = new Phrase(translate(
                    "Please prepare for the review meeting by checking the product for the following aspects step by step:"),
                    italicFont);

            cellAspIntro.addElement(phraseAspIntro);

            tableAspIntro.addCell(cellAspIntro);

            pdfDoc.add(tableAspIntro);
        } else if (attendee.getRole() != Role.REVIEWER) {
            pdfDoc.newPage();

            phraseAspIntro = new Phrase(translate("The product will be checked for the following aspects:"),
                    italicFont);

            cellAspIntro.addElement(phraseAspIntro);

            tableAspIntro.addCell(cellAspIntro);

            pdfDoc.add(tableAspIntro);
        }

        writeAspects();
    } catch (Exception e) {
        /*
         * Not part of unit testing because this exception is only thrown if
         * an internal error occurs.
         */
        throw new ExportException(
                translate("Cannot create invitation for the review meeting.") + "\n\n" + e.getMessage());
    }
}