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

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

Introduction

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

Prototype

public void setTotalWidth(float columnWidth[]) throws DocumentException 

Source Link

Document

Sets the full width of the table from the absolute column width.

Usage

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

License:Open Source License

/**
 * Get Selling Items Data//w  w w.  j av 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 ww  w .j  a  v  a 2 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  .  ja v  a2s .c om*/

    // 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.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 av  a2  s  .co  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/*from w ww .  java2s . 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(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//from w ww . j  a v a  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.PDFPageEventHelper.java

License:Open Source License

@Override
public void onEndPage(PdfWriter writer, Document document) {
    int columnNumber;

    try {/*  ww w .j a va 2  s . co m*/
        Rectangle page = document.getPageSize();
        float pageWidth = page.getWidth() - document.leftMargin() - document.rightMargin();

        /*
         * Write marks
         */
        setMarks(writer, document);

        /*
         * Define fonts
         */
        headBaseFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        Font headFont = new Font(headBaseFont, headFontSize);

        footBaseFont = BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED);
        Font footFont = new Font(footBaseFont, footFontSize);

        /*
         * Cell fill for space between head/foot and content
         */
        PdfPCell cellFill = new PdfPCell();
        cellFill.setMinimumHeight(PDFTools.cmToPt(0.8f));
        cellFill.setBorderWidth(0);

        /*
         * Write head
         */
        if (headLogoPath != null) {
            columnNumber = 2;
        } else {
            columnNumber = 1;
        }

        PdfPTable head = new PdfPTable(columnNumber);

        Phrase phraseTitle = new Phrase(headTitle, headFont);

        PdfPCell cellTitle = new PdfPCell(phraseTitle);
        cellTitle.setHorizontalAlignment(Element.ALIGN_LEFT);
        cellTitle.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cellTitle.setPaddingTop(0);
        cellTitle.setPaddingBottom(PDFTools.cmToPt(0.2f));
        cellTitle.setPaddingLeft(0);
        cellTitle.setPaddingRight(0);
        cellTitle.setBorderWidthTop(0);
        cellTitle.setBorderWidthBottom(0.5f);
        cellTitle.setBorderWidthLeft(0);
        cellTitle.setBorderWidthRight(0);

        head.addCell(cellTitle);

        if (headLogoPath != null) {
            Image headLogo = Image.getInstance(headLogoPath);
            headLogo.scaleToFit(PDFTools.cmToPt(5.0f), PDFTools.cmToPt(1.1f));

            PdfPCell cellLogo = new PdfPCell(headLogo);
            cellLogo.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cellLogo.setVerticalAlignment(Element.ALIGN_BOTTOM);
            cellLogo.setPaddingTop(0);
            cellLogo.setPaddingBottom(PDFTools.cmToPt(0.15f));
            cellLogo.setPaddingLeft(0);
            cellLogo.setPaddingRight(0);
            cellLogo.setBorderWidthTop(0);
            cellLogo.setBorderWidthBottom(0.5f);
            cellLogo.setBorderWidthLeft(0);
            cellLogo.setBorderWidthRight(0);

            head.addCell(cellLogo);

            head.addCell(cellFill);
        }

        head.addCell(cellFill);

        head.setTotalWidth(pageWidth);
        head.writeSelectedRows(0, -1, document.leftMargin(),
                page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());

        /*
         * Write foot
         */
        if (footText == null) {
            footText = " ";
        }

        PdfPTable foot = new PdfPTable(1);

        foot.addCell(cellFill);

        PdfPCell cellFootText = new PdfPCell(new Phrase(footText, footFont));
        cellFootText.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cellFootText.setVerticalAlignment(Element.ALIGN_TOP);
        cellFootText.setPaddingTop(PDFTools.cmToPt(0.15f));
        cellFootText.setPaddingBottom(0);
        cellFootText.setPaddingLeft(0);
        cellFootText.setPaddingRight(0);
        cellFootText.setBorderWidthTop(0.5f);
        cellFootText.setBorderWidthBottom(0);
        cellFootText.setBorderWidthLeft(0);
        cellFootText.setBorderWidthRight(0);

        foot.addCell(cellFootText);

        /*
         * Print page numbers
         */
        PdfContentByte contentByte = writer.getDirectContent();
        contentByte.saveState();

        String text = MessageFormat.format(translate("Page {0} of") + " ", writer.getPageNumber());

        float textSize = footBaseFont.getWidthPoint(text, footFontSize);
        float textBase = document.bottom() - PDFTools.cmToPt(1.26f);
        contentByte.beginText();
        contentByte.setFontAndSize(footBaseFont, footFontSize);

        float adjust;
        if (footText.trim().equals("")) {
            adjust = (pageWidth / 2) - (textSize / 2) - footBaseFont.getWidthPoint("0", footFontSize);
        } else {
            adjust = 0;
        }

        contentByte.setTextMatrix(document.left() + adjust, textBase);
        contentByte.showText(text);
        contentByte.endText();
        contentByte.addTemplate(template, document.left() + adjust + textSize, textBase);

        contentByte.stroke();
        contentByte.restoreState();

        foot.setTotalWidth(pageWidth);
        foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                writer.getDirectContent());
    } catch (Exception e) {
        /*
         * Not part of unit testing because this exception is only thrown if
         * an internal error occurs.
         */
        throw new ExceptionConverter(e);
    }
}

From source file:org.sonar.report.pdf.DefaultPDFReporter.java

License:Open Source License

private void formatTable(PdfPTable table) {
    Rectangle page = document.getPageSize();
    table.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE);
    table.getDefaultCell().setPaddingBottom(tablePaddingBottom);
    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
    table.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
    table.setSpacingBefore(20);//from   www . jav  a  2 s  .c om
}

From source file:org.sonar.report.pdf.DefaultPDFReporter.java

License:Open Source License

@Override
protected void printFrontPage(Document frontPageDocument, PdfWriter frontPageWriter)
        throws org.dom4j.DocumentException, ReportException {
    try {/*from  ww  w .j  a va 2  s .  com*/
        URL largeLogo;
        if (super.getConfigProperty("front.page.logo").startsWith("http://")) {
            largeLogo = new URL(super.getConfigProperty("front.page.logo"));
        } else {
            largeLogo = this.getClass().getClassLoader()
                    .getResource(super.getConfigProperty("front.page.logo"));
        }
        Image logoImage = Image.getInstance(largeLogo);
        Rectangle pageSize = frontPageDocument.getPageSize();
        float positionX = pageSize.getWidth() / 2f - logoImage.getWidth() / 2f;
        logoImage.setAbsolutePosition(positionX, pageSize.getHeight() - logoImage.getHeight() - 100);
        frontPageDocument.add(logoImage);

        PdfPTable title = new PdfPTable(1);
        title.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        title.getDefaultCell().setBorder(Rectangle.NO_BORDER);

        String projectRow = super.getTextProperty("general.project") + ": " + super.getProject().getName();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String dateRow = df.format(super.getProject().getMeasures().getDate());
        String descriptionRow = super.getProject().getDescription();

        title.addCell(new Phrase(projectRow, Style.FRONTPAGE_FONT_1));
        title.addCell(new Phrase(descriptionRow, Style.FRONTPAGE_FONT_2));
        title.addCell(new Phrase(dateRow, Style.FRONTPAGE_FONT_3));
        title.setTotalWidth(
                pageSize.getWidth() - frontPageDocument.leftMargin() - frontPageDocument.rightMargin());
        title.writeSelectedRows(0, -1, frontPageDocument.leftMargin(),
                pageSize.getHeight() - logoImage.getHeight() - 150, frontPageWriter.getDirectContent());

    } catch (IOException e) {
        e.printStackTrace();
    } catch (BadElementException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:org.sonar.report.pdf.ExecutivePDFReporter.java

License:Open Source License

@Override
protected void printFrontPage(Document frontPageDocument, PdfWriter frontPageWriter)
        throws org.dom4j.DocumentException, ReportException {
    try {/*from   w w  w . j a va  2  s  .c o  m*/
        URL largeLogo;
        if (super.getConfigProperty("front.page.logo").startsWith("http://")) {
            largeLogo = new URL(super.getConfigProperty("front.page.logo"));
        } else {
            largeLogo = this.getClass().getClassLoader()
                    .getResource(super.getConfigProperty("front.page.logo"));
        }
        Image logoImage = Image.getInstance(largeLogo);
        logoImage.scaleAbsolute(360, 200);
        Rectangle pageSize = frontPageDocument.getPageSize();
        logoImage.setAbsolutePosition(Style.FRONTPAGE_LOGO_POSITION_X, Style.FRONTPAGE_LOGO_POSITION_Y);
        frontPageDocument.add(logoImage);

        PdfPTable title = new PdfPTable(1);
        title.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        title.getDefaultCell().setBorder(Rectangle.NO_BORDER);

        String projectRow = super.getProject().getName();
        String versionRow = super.getProject().getMeasures().getVersion();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String dateRow = df.format(super.getProject().getMeasures().getDate());
        String descriptionRow = super.getProject().getDescription();

        title.addCell(new Phrase(projectRow, Style.FRONTPAGE_FONT_1));
        title.addCell(new Phrase(versionRow, Style.FRONTPAGE_FONT_1));
        title.addCell(new Phrase(descriptionRow, Style.FRONTPAGE_FONT_2));
        title.addCell(new Phrase(super.getProject().getMeasure(MetricKeys.PROFILE).getDataValue(),
                Style.FRONTPAGE_FONT_3));
        title.addCell(new Phrase(dateRow, Style.FRONTPAGE_FONT_3));
        title.setTotalWidth(
                pageSize.getWidth() - frontPageDocument.leftMargin() - frontPageDocument.rightMargin());
        title.writeSelectedRows(0, -1, frontPageDocument.leftMargin(), Style.FRONTPAGE_LOGO_POSITION_Y - 150,
                frontPageWriter.getDirectContent());

    } catch (IOException e) {
        e.printStackTrace();
    } catch (BadElementException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}