Example usage for com.lowagie.text.pdf PdfPCell setFixedHeight

List of usage examples for com.lowagie.text.pdf PdfPCell setFixedHeight

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPCell setFixedHeight.

Prototype

public void setFixedHeight(float fixedHeight) 

Source Link

Document

Set a fixed height for the cell.

Usage

From source file:org.kuali.ole.module.purap.pdf.PurchaseOrderQuoteRequestsPdf.java

License:Educational Community License

/**
 * Creates the pdf using given input parameters.
 *
 * @param po       The PurchaseOrderDocument to be used to create the pdf.
 * @param document The pdf document whose margins have already been set.
 * @param writer   The PdfWriter to write the pdf document into.
 * @param instName The purchasing institution name
 * @throws DocumentException//from www. j  a v a 2 s .c  o  m
 */
private void createPOQuoteRequestsListPdf(PurchaseOrderDocument po, Document document, PdfWriter writer,
        String instName) throws DocumentException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("createPOQuoteRequestsListPdf() started for po number " + po.getPurapDocumentIdentifier());
    }

    // These have to be set because they are used by the onOpenDocument() method.
    this.po = po;

    // Turn on the page events that handle the header and page numbers.
    PurchaseOrderPdf events = new PurchaseOrderPdf().getPageEvents();
    writer.setPageEvent(this); // Passing in "this" lets it know about the po, campusName, etc.

    document.open();

    PdfPCell cell;
    Paragraph p = new Paragraph();

    float[] headerWidths = { 0.25f, 0.25f, 0.25f, 0.25f };
    headerTable = new PdfPTable(headerWidths);
    headerTable.setWidthPercentage(100);
    headerTable.setHorizontalAlignment(Element.ALIGN_CENTER);

    headerTable.getDefaultCell().setBorderWidth(0);
    headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    headerTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);

    // New row
    cell = new PdfPCell(new Paragraph(instName + "\nRequest for Quotation Vendor List\n\n", titleFont));
    cell.setBorderWidth(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setColspan(4);
    headerTable.addCell(cell);

    // New row
    cell = new PdfPCell(new Paragraph("PO Number: " + po.getPurapDocumentIdentifier(), cellTextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorderWidth(0);
    headerTable.addCell(cell);

    cell = new PdfPCell(new Paragraph("Req. Number: " + po.getRequisitionIdentifier(), cellTextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorderWidth(0);
    headerTable.addCell(cell);

    // Date format pattern: MM-dd-yyyy
    SimpleDateFormat sdf = new SimpleDateFormat(RiceConstants.SIMPLE_DATE_FORMAT_FOR_DATE, Locale.getDefault());
    Date today = SpringContext.getBean(DateTimeService.class).getCurrentSqlDate();
    cell = new PdfPCell(new Paragraph("Printed: " + sdf.format(today), cellTextFont));
    cell.setBorderWidth(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerTable.addCell(cell);

    if (po.getPurchaseOrderQuoteDueDate() != null) {
        Date dueDate = po.getPurchaseOrderQuoteDueDate();
        cell = new PdfPCell(new Paragraph("Due: " + sdf.format(dueDate) + "\n\n", cellTextFont));
    } else {
        cell = new PdfPCell(new Paragraph("Due: N/A\n\n", cellTextFont));
    }
    cell.setBorderWidth(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerTable.addCell(cell);

    document.add(headerTable);

    // ***** List table *****
    LOG.debug("createPOQuoteRequestsListPdf() list table started.");
    float[] listWidths = { 0.20f, 0.20f, 0.20f, 0.20f, 0.20f };
    PdfPTable listTable = new PdfPTable(listWidths);
    listTable.setWidthPercentage(100);
    listTable.setHorizontalAlignment(Element.ALIGN_CENTER);

    cell = new PdfPCell(new Paragraph("Vendor Name", cellTextFont));
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setBorderWidth(0);
    listTable.addCell(cell);
    cell = new PdfPCell(new Paragraph("City", cellTextFont));
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setBorderWidth(0);
    listTable.addCell(cell);
    cell = new PdfPCell(new Paragraph("Attention", cellTextFont));
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setBorderWidth(0);
    listTable.addCell(cell);
    cell = new PdfPCell(new Paragraph("Fax #", cellTextFont));
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setBorderWidth(0);
    listTable.addCell(cell);
    cell = new PdfPCell(new Paragraph("Received", cellTextFont));
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setBorderWidth(0);
    listTable.addCell(cell);

    // The line under the headings.
    cell = new PdfPCell(new Paragraph(" ", cellTitleFont));
    cell.setFixedHeight(1);
    cell.setColspan(5);
    listTable.addCell(cell);

    for (PurchaseOrderVendorQuote poqv : po.getPurchaseOrderVendorQuotes()) {
        cell = new PdfPCell(new Paragraph(poqv.getVendorName(), cellTextFont));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorderWidth(0);
        listTable.addCell(cell);
        if (poqv.getVendorStateCode() != null) {
            cell = new PdfPCell(
                    new Paragraph(poqv.getVendorCityName() + ", " + poqv.getVendorStateCode(), cellTextFont));
        } else if (poqv.getVendorCountryCode() != null) {
            cell = new PdfPCell(
                    new Paragraph(poqv.getVendorCityName() + ", " + poqv.getVendorCountryCode(), cellTextFont));
        } else {
            cell = new PdfPCell(new Paragraph(poqv.getVendorCityName(), cellTextFont));
        }
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorderWidth(0);
        listTable.addCell(cell);
        cell = new PdfPCell(new Paragraph(poqv.getVendorAttentionName(), cellTextFont));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorderWidth(0);
        listTable.addCell(cell);
        cell = new PdfPCell(new Paragraph(poqv.getVendorFaxNumber(), cellTextFont));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorderWidth(0);
        listTable.addCell(cell);
        cell = new PdfPCell(new Paragraph("__________", cellTextFont));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorderWidth(0);
        listTable.addCell(cell);
    }

    document.add(listTable);

    document.close();
    LOG.debug("createPOQuoteRequestsListPdf()pdf document closed.");
}

From source file:org.posterita.businesslogic.performanceanalysis.POSReportManager.java

License:Open Source License

public static String getCompleteOrderPDFReport(Properties ctx, int orderId, String trxName)
        throws OperationException {
    String docStatus = null;/*w  w  w . j  a  v a  2 s .c  o m*/
    String dateOrdered = null;
    String orderType = null;
    String orgName = null;
    String orgAddress = null;
    String salesRep = null;
    String paymentBy = null;
    String customerName = null;
    String customerAddress = null;
    String documentNo = null;
    String currency = "Rs ";
    NumberFormat formatter = new DecimalFormat("###,###,##0.00");

    currency = POSTerminalManager.getDefaultSalesCurrency(ctx).getCurSymbol() + " ";
    MOrder order = new MOrder(ctx, orderId, trxName);

    // getting payment info
    int[] invoiceIds = MInvoice.getAllIDs(MInvoice.Table_Name,
            "AD_CLIENT_ID=" + Env.getAD_Client_ID(ctx) + " and C_ORDER_ID=" + order.get_ID(), null);
    double paymentByCash = 0.0;
    double paymentByCard = 0.0;
    double paymentByCheque = 0.0;

    MInvoice invoice = null;
    String paymentRule = null;
    boolean isMixed = false;

    for (int i = 0; i < invoiceIds.length; i++) {
        invoice = new MInvoice(ctx, invoiceIds[i], trxName);

        if (i == 0) {
            paymentRule = invoice.getPaymentRule();
        } else {
            if (!paymentRule.equalsIgnoreCase(invoice.getPaymentRule())) {
                isMixed = true;
            }
        }

        if (invoice.getPaymentRule().equals(MOrder.PAYMENTRULE_Cash)) {
            paymentByCash += invoice.getGrandTotal().doubleValue();
            paymentBy = Constants.PAYMENT_RULE_CASH;
        }

        if (invoice.getPaymentRule().equals(MOrder.PAYMENTRULE_CreditCard)) {
            paymentByCard += invoice.getGrandTotal().doubleValue();
            paymentBy = Constants.PAYMENT_RULE_CARD;
        }

        if (invoice.getPaymentRule().equals(MOrder.PAYMENTRULE_DirectDebit)) {
            paymentByCard += invoice.getGrandTotal().doubleValue();
            paymentBy = Constants.PAYMENT_RULE_CARD;
        }

        if (invoice.getPaymentRule().equals(MOrder.PAYMENTRULE_Check)) {
            paymentByCheque += invoice.getGrandTotal().doubleValue();
            paymentBy = Constants.PAYMENT_RULE_CHEQUE;
        }

    } // for

    if (isMixed) {
        paymentBy = "Mixed (Cash:" + formatter.format(paymentByCash) + " Card:"
                + formatter.format(paymentByCard) + " Cheque:" + formatter.format(paymentByCheque) + ")";
    }

    // getting orgInfo
    MOrg org = new MOrg(ctx, order.getAD_Org_ID(), trxName);
    int location_id = org.getInfo().getC_Location_ID();
    MLocation location = new MLocation(ctx, location_id, trxName);

    orgName = org.getName();

    String address1 = (location.getAddress1() == null) ? " " : location.getAddress1();
    String address2 = (location.getAddress2() == null) ? " " : location.getAddress2();
    orgAddress = (address1 + " " + address2).trim();

    // getting order type
    orderType = order.getOrderType();

    // getting orderInfo
    docStatus = order.getDocStatusName();
    documentNo = order.getDocumentNo();

    Date d = new Date(order.getCreated().getTime());
    SimpleDateFormat s = new SimpleDateFormat(TimestampConvertor.DEFAULT_DATE_PATTERN1);
    dateOrdered = s.format(d);

    // getting salesrep
    int saleRep_id = order.getSalesRep_ID();
    MUser user = new MUser(ctx, saleRep_id, trxName);
    salesRep = user.getName();

    // getting customer info
    int bpartner_id = order.getBill_BPartner_ID();
    BPartnerBean bean = BPartnerManager.getBpartner(ctx, bpartner_id, trxName);

    String name1 = (bean.getPartnerName() == null) ? " " : bean.getPartnerName();
    String name2 = (bean.getName2() == null) ? " " : bean.getName2();
    customerName = (name1 + " " + name2).trim();

    address1 = (bean.getAddress1() == null) ? " " : bean.getAddress1();
    address2 = (bean.getAddress2() == null) ? " " : bean.getAddress2();
    customerAddress = (address1 + " " + address2).trim();

    ArrayList<WebOrderLineBean> orderLineList = POSManager.populateOrderLines(ctx, order);

    // ----------------------------------- generating pdf
    // --------------------------------------
    String reportName = RandomStringGenerator.randomstring() + ".pdf";
    String reportPath = ReportManager.getReportPath(reportName);

    Font titleFont = new Font(Font.TIMES_ROMAN, 18, Font.BOLD);
    Font subtitleFont = new Font(Font.TIMES_ROMAN, 14, Font.BOLD);

    Font headerFont = new Font(Font.TIMES_ROMAN, 11, Font.BOLD);
    Font simpleFont = new Font(Font.TIMES_ROMAN, 10);

    float cellBorderWidth = 0.0f;

    // step 1: creation of a document-object
    Document document = new Document(PageSize.A4, 30, 30, 20, 40);// l,r,t,b
    // document.getPageSize().set;

    System.out.println(document.leftMargin());

    try {
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file
        PdfWriter.getInstance(document, new FileOutputStream(reportPath));

        // step 3: we open the document
        document.open();
        // step 4: we add a paragraph to the document

        Image logo = null;

        String imageURI = PathInfo.PROJECT_HOME + "images/logo.gif";
        // "images/pos/openBLUE_POS_Logo.gif";

        try {
            byte logoData[] = OrganisationManager.getLogo(ctx, null);
            logo = Image.getInstance(logoData);
        } catch (LogoException ex) {
            logo = Image.getInstance(imageURI);
        }

        logo.setAbsolutePosition(document.left(), document.top() - logo.getHeight());
        document.add(logo);

        PdfPTable table = new PdfPTable(2);
        PdfPCell cell = null;

        //
        table.getDefaultCell().setPadding(5.0f);
        table.setWidthPercentage(100.0f);

        // header cell
        Paragraph title = new Paragraph();
        title.add(new Chunk(orgName, subtitleFont));
        title.add(new Chunk("\n"));
        title.add(new Chunk(orgAddress, subtitleFont));

        // cell = new PdfPCell(new Paragraph(new
        // Chunk("Title1",titleFont)));
        cell = new PdfPCell(title);

        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setFixedHeight(logo.getHeight());
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        cell = new PdfPCell(new Paragraph(""));
        cell.setBorderWidth(cellBorderWidth);
        cell.setFixedHeight(10);
        cell.setColspan(2);
        table.addCell(cell);

        // doc type
        cell = new PdfPCell(new Paragraph(new Chunk(orderType, titleFont)));

        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setBorderWidth(cellBorderWidth);
        cell.setFixedHeight(10);
        cell.setColspan(2);
        table.addCell(cell);

        // row 1
        cell = new PdfPCell(new Paragraph(new Chunk(customerName, headerFont)));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        cell = new PdfPCell(new Paragraph(new Chunk("Sales Rep: " + salesRep, headerFont)));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // row 2
        cell = new PdfPCell(new Paragraph(new Chunk(customerAddress, headerFont)));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setBorderWidth(cellBorderWidth);
        cell.setFixedHeight(10);
        cell.setColspan(2);
        table.addCell(cell);

        // row 3
        cell = new PdfPCell(new Paragraph(new Chunk("Ref No: " + documentNo, headerFont)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // row 4
        cell = new PdfPCell(new Paragraph(new Chunk("Doc Status: " + docStatus, headerFont)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // row 5
        cell = new PdfPCell(new Paragraph(new Chunk("Payment By: " + paymentBy, headerFont)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // row 6
        cell = new PdfPCell(new Paragraph(new Chunk("Date: " + dateOrdered, headerFont)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setColspan(2);
        cell.setFixedHeight(10);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setColspan(2);
        cell.setFixedHeight(10);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // ------------------------------------------------------
        cell = new PdfPCell();
        cell.setColspan(2);
        cell.setBorderWidth(cellBorderWidth);

        PdfPTable t = new PdfPTable(6);
        t.getDefaultCell().setPadding(3.0f);
        t.setWidthPercentage(100.0f);

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

        // setting headers
        t.addCell(new Paragraph(new Chunk("SerNo", headerFont)));
        t.addCell(new Paragraph(new Chunk("Name", headerFont)));
        t.addCell(new Paragraph(new Chunk("Qty", headerFont)));
        t.addCell(new Paragraph(new Chunk("Price", headerFont)));
        t.addCell(new Paragraph(new Chunk("VAT", headerFont)));
        t.addCell(new Paragraph(new Chunk("Total", headerFont)));

        // setting table data
        // --------------------------------writing table
        // data------------------------------
        int serNo = 0;
        int totalQty = 0;
        double totalAmt = 0.0;
        double totalTaxAmt = 0.0;
        double grandTotal = 0.0;

        BigDecimal qty = null;
        BigDecimal lineAmt = null;
        BigDecimal taxAmt = null;
        BigDecimal lineTotalAmt = null;

        for (WebOrderLineBean orderlineBean : orderLineList) {
            serNo++;
            qty = orderlineBean.getQtyOrdered();
            lineAmt = orderlineBean.getLineNetAmt();
            taxAmt = orderlineBean.getTaxAmt();
            lineTotalAmt = orderlineBean.getLineTotalAmt();

            totalQty += qty.intValue();
            totalAmt += lineAmt.doubleValue();
            totalTaxAmt += taxAmt.doubleValue();
            grandTotal += lineTotalAmt.doubleValue();

            t.addCell(new Paragraph(new Chunk(serNo + "", simpleFont)));
            t.addCell(new Paragraph(new Chunk(orderlineBean.getProductName(), simpleFont)));
            t.addCell(new Paragraph(new Chunk(qty.intValue() + "", simpleFont)));
            t.addCell(new Paragraph(new Chunk(formatter.format(lineAmt.doubleValue()), simpleFont)));
            t.addCell(new Paragraph(new Chunk(formatter.format(taxAmt.doubleValue()), simpleFont)));
            t.addCell(new Paragraph(new Chunk(formatter.format(lineTotalAmt.doubleValue()), simpleFont)));
        }
        // -----------------------------------------------------------------------------------

        // setting table footer
        t.getDefaultCell().setBackgroundColor(new Color(240, 240, 240));

        PdfPCell c = new PdfPCell(new Paragraph(new Chunk("ORDER TOTAL", headerFont)));
        c.setColspan(2);
        c.setBackgroundColor(new Color(240, 240, 240));
        t.addCell(c);

        t.addCell(new Paragraph(new Chunk(totalQty + "", simpleFont)));
        t.addCell(new Paragraph(new Chunk(currency + formatter.format(totalAmt), simpleFont)));
        t.addCell(new Paragraph(new Chunk(currency + formatter.format(totalTaxAmt), simpleFont)));
        t.addCell(new Paragraph(new Chunk(currency + formatter.format(grandTotal), simpleFont)));

        t.setSplitRows(true);
        cell.addElement(t);
        // ------------------------------------------------------

        // table.addCell(cell);
        table.setSplitRows(true);

        document.add(table);
        document.add(t);

    } catch (Exception e) {
        throw new OperationException(e);
    }

    // step 5: we close the document
    document.close();

    return reportName;
}

From source file:org.posterita.businesslogic.performanceanalysis.POSReportManager.java

License:Open Source License

public static String getShipmentPDFReport(Properties ctx, int minoutId, String trxName)
        throws OperationException {
    String docStatus = null;//from w w  w  . j a v a 2s .c o m
    String dateOrdered = null;
    String docType = null;
    String orgName = null;
    String orgAddress = null;
    String salesRep = null;
    String phone = "      ";
    String fax = "       ";

    String customerName = null;
    String customerAddress = null;
    String documentNo = null;

    MInOut minout = MinOutManager.loadMInOut(ctx, minoutId, trxName);

    // getting orgInfo
    MOrg org = new MOrg(ctx, minout.getAD_Org_ID(), trxName);
    int location_id = org.getInfo().getC_Location_ID();
    MLocation location = new MLocation(ctx, location_id, trxName);
    MBPartner orgPartner = new MBPartner(ctx, org.getLinkedC_BPartner_ID(trxName), trxName);
    MBPartnerLocation meLocation[] = MBPartnerLocation.getForBPartner(ctx, orgPartner.get_ID());

    if (meLocation.length != 1)
        throw new OperationException("Should have only 1 location for organisation business partner!!");

    MBPartnerLocation orgLocation = meLocation[0];

    if (orgLocation.getPhone() != null)
        phone = orgLocation.getPhone();

    if (orgLocation.getFax() != null)
        fax = orgLocation.getFax();
    ;

    orgName = org.getName();

    String address1 = (location.getAddress1() == null) ? " " : location.getAddress1();
    String address2 = (location.getAddress2() == null) ? " " : location.getAddress2();
    orgAddress = (address1 + " " + address2).trim();

    // getting order type
    MDocType doctype = MDocType.get(ctx, minout.getC_DocType_ID());
    docType = doctype.getName();

    // getting orderInfo
    docStatus = minout.getDocStatusName();
    documentNo = minout.getDocumentNo();

    Date d = new Date(minout.getCreated().getTime());
    SimpleDateFormat s = new SimpleDateFormat(TimestampConvertor.DEFAULT_DATE_PATTERN1);
    dateOrdered = s.format(d);

    // getting salesrep
    int saleRep_id = minout.getSalesRep_ID();
    MUser user = new MUser(ctx, saleRep_id, trxName);
    salesRep = user.getName();

    // getting customer info
    int bpartner_id = minout.getC_BPartner_ID();
    BPartnerBean bean = BPartnerManager.getBpartner(ctx, bpartner_id, trxName);

    String name1 = (bean.getPartnerName() == null) ? " " : bean.getPartnerName();
    String name2 = (bean.getName2() == null) ? " " : bean.getName2();
    customerName = (name1 + " " + name2).trim();

    address1 = (bean.getAddress1() == null) ? " " : bean.getAddress1();
    address2 = (bean.getAddress2() == null) ? " " : bean.getAddress2();
    customerAddress = (address1 + " " + address2).trim();

    ArrayList<WebMinOutLineBean> orderLineList = MinOutManager.getWebMinOutLines(ctx, minout);

    // ----------------------------------- generating pdf
    // --------------------------------------
    String reportName = RandomStringGenerator.randomstring() + ".pdf";
    String reportPath = ReportManager.getReportPath(reportName);

    Font titleFont = new Font(Font.TIMES_ROMAN, 18, Font.BOLD);
    Font subtitleFont = new Font(Font.TIMES_ROMAN, 14, Font.BOLD);

    Font headerFont = new Font(Font.TIMES_ROMAN, 11, Font.BOLD);
    Font simpleFont = new Font(Font.TIMES_ROMAN, 10);

    float cellBorderWidth = 0.0f;

    // step 1: creation of a document-object
    Document document = new Document(PageSize.A4, 30, 30, 20, 40);// l,r,t,b
    // document.getPageSize().set;

    System.out.println(document.leftMargin());

    try {
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file
        PdfWriter.getInstance(document, new FileOutputStream(reportPath));

        // step 3: we open the document
        document.open();
        // step 4: we add a paragraph to the document

        Image logo = null;

        // TODO: make this part dynamic <------------------------------
        // IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!
        String imageURI = PathInfo.PROJECT_HOME + "images/pos/openBLUE_POS_Logo.gif";
        logo = Image.getInstance(imageURI);

        // MAttachment attachment = new
        // MAttachment(ctx,MOrg.Table_ID,org.getID(),null);
        // logo = Image.getInstance(attachment.getEntries()[0].getData());

        try {
            byte logoData[] = OrganisationManager.getLogo(ctx, null);
            logo = Image.getInstance(logoData);
        } catch (LogoException ex) {
            logo = Image.getInstance(imageURI);
        }

        logo.setAbsolutePosition(document.left(), document.top() - logo.getHeight());
        document.add(logo);

        PdfPTable table = new PdfPTable(2);
        PdfPCell cell = null;

        //
        table.getDefaultCell().setPadding(5.0f);
        table.setWidthPercentage(100.0f);

        // header cell
        Paragraph title = new Paragraph();
        title.add(new Chunk(orgName, subtitleFont));
        title.add(new Chunk("\n"));
        title.add(new Chunk(orgAddress, subtitleFont));
        title.add(new Chunk("\n"));
        title.add(new Chunk("Phone: " + phone, subtitleFont));
        title.add(new Chunk("\n"));
        title.add(new Chunk("Fax: " + fax, subtitleFont));

        // cell = new PdfPCell(new Paragraph(new
        // Chunk("Title1",titleFont)));
        cell = new PdfPCell(title);

        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setFixedHeight(logo.getHeight());
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        cell = new PdfPCell(new Paragraph(""));
        cell.setBorderWidth(cellBorderWidth);
        cell.setFixedHeight(10);
        cell.setColspan(2);
        table.addCell(cell);

        // doc type
        cell = new PdfPCell(new Paragraph(new Chunk(docType, titleFont)));

        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setBorderWidth(cellBorderWidth);
        cell.setFixedHeight(10);
        cell.setColspan(2);
        table.addCell(cell);

        // row 1
        cell = new PdfPCell(new Paragraph(new Chunk(customerName, headerFont)));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        cell = new PdfPCell(new Paragraph(new Chunk("Sales Rep: " + salesRep, headerFont)));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // row 2
        cell = new PdfPCell(new Paragraph(new Chunk(customerAddress, headerFont)));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setBorderWidth(cellBorderWidth);
        cell.setFixedHeight(10);
        cell.setColspan(2);
        table.addCell(cell);

        // row 3
        cell = new PdfPCell(new Paragraph(new Chunk("No: " + documentNo, headerFont)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // row 4
        cell = new PdfPCell(new Paragraph(new Chunk("Doc Status: " + docStatus, headerFont)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        /*
         * //row 5 cell = new PdfPCell(new Paragraph(new Chunk("Payment By:
         * "+paymentBy,headerFont))); cell.setColspan(2);
         * cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
         * cell.setBorderWidth(cellBorderWidth); table.addCell(cell);
         */

        // row 6
        cell = new PdfPCell(new Paragraph(new Chunk("Date: " + dateOrdered, headerFont)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setColspan(2);
        cell.setFixedHeight(10);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setColspan(2);
        cell.setFixedHeight(10);
        cell.setBorderWidth(cellBorderWidth);
        table.addCell(cell);

        // ------------------------------------------------------
        cell = new PdfPCell();
        cell.setColspan(2);
        cell.setBorderWidth(cellBorderWidth);

        PdfPTable t = new PdfPTable(3);
        t.getDefaultCell().setPadding(3.0f);
        t.setWidthPercentage(100.0f);

        int[] widths = { 1, 10, 1 };
        t.setWidths(widths);

        // setting headers
        t.addCell(new Paragraph(new Chunk("SerNo", headerFont)));
        t.addCell(new Paragraph(new Chunk("Name", headerFont)));
        t.addCell(new Paragraph(new Chunk("Qty", headerFont)));

        // setting table data
        // --------------------------------writing table
        // data------------------------------
        int serNo = 0;

        BigDecimal qty = null;

        for (WebMinOutLineBean orderlineBean : orderLineList) {
            serNo++;
            qty = orderlineBean.getQtyOrdered();

            t.addCell(new Paragraph(new Chunk(serNo + "", simpleFont)));
            t.addCell(new Paragraph(new Chunk(orderlineBean.getProductName(), simpleFont)));
            t.addCell(new Paragraph(new Chunk(qty.intValue() + "", simpleFont)));
        }
        // -----------------------------------------------------------------------------------

        // table.addCell(cell);
        table.setSplitRows(true);

        document.add(table);
        document.add(t);

    } catch (Exception e) {
        throw new OperationException(e);
    }

    // step 5: we close the document
    document.close();

    return reportName;
}

From source file:org.posterita.businesslogic.performanceanalysis.POSReportManager.java

License:Open Source License

public static String endOfTheDayPDF(Properties ctx, CloseTillBean bean) throws OperationException {
    String reportName = RandomStringGenerator.randomstring() + ".pdf";
    String reportPath = ReportManager.getReportPath(reportName);

    double beginningBalance = (bean.getBeginningBalance() == null ? 0
            : bean.getBeginningBalance().doubleValue());
    double statementDifference = (bean.getNetCashTrx() == null ? 0 : bean.getNetCashTrx().doubleValue());
    double transferAmount = (bean.getBalanceEntered() == null ? 0 : bean.getBalanceEntered().doubleValue());
    double differenceAmount = (bean.getDifference() == null ? 0 : bean.getDifference().doubleValue());
    double endingBalance = (bean.getEndingBalance() == null ? 0 : bean.getEndingBalance().doubleValue());
    double tillCashTotal = (bean.getCashTotal() == null ? 0 : bean.getCashTotal().doubleValue());
    double cashBeanCardTotal = (bean.getCardTotal() == null ? 0 : bean.getCardTotal().doubleValue());
    double tillCardTotal = (bean.getCardTotal() == null ? 0 : bean.getCardTotal().doubleValue());
    double cardDifference = (bean.getCardDifference() == null ? 0 : bean.getCardDifference().doubleValue());
    double cashBeanChequeTotal = (bean.getChequeTotal() == null ? 0 : bean.getChequeTotal().doubleValue());
    double tillChequeTotal = (bean.getChequeTotal() == null ? 0 : bean.getChequeTotal().doubleValue());
    double chequeDifference = (bean.getChequeDifference() == null ? 0
            : bean.getChequeDifference().doubleValue());
    double grandTotal = (bean.getGrandTotal() == null ? 0 : bean.getGrandTotal().doubleValue());

    Font titleFont = new Font(Font.TIMES_ROMAN, 8, Font.BOLD);
    Font subtitleFont = new Font(Font.TIMES_ROMAN, 8, Font.BOLD);

    // Font headerFont = new Font(Font.TIMES_ROMAN, 8,Font.BOLD);
    Font simpleFont = new Font(Font.TIMES_ROMAN, 8);

    final float NO_BORDER = 0.0f;
    // final float THIN_BORDER = 1.0f;

    String currency = "Rs ";
    NumberFormat formatter = new DecimalFormat("###,###,##0.00");
    PdfPCell cell = null;

    // step 1: creation of a document-object
    Document document = new Document(PageSize.A7, 3, 3, 2, 4);// l,r,t,b
    // document.getPageSize().set;

    System.out.println(document.leftMargin());

    try {//from  w w w.  j  a v a2  s  . co m
        currency = POSTerminalManager.getDefaultSalesCurrency(ctx).getCurSymbol();
        PdfWriter.getInstance(document, new FileOutputStream(reportPath));

        document.open();

        PdfPTable layoutTbl = new PdfPTable(1);
        layoutTbl.getDefaultCell().setBorderWidth(NO_BORDER);
        layoutTbl.getDefaultCell().setPadding(2.0f);

        SimpleDateFormat sdf = new SimpleDateFormat(TimestampConvertor.DEFAULT_DATE_PATTERN1);
        Date today = new Date(System.currentTimeMillis());

        // 1.add title
        Paragraph title = new Paragraph(new Chunk("End of the Day Report", titleFont));
        title.setAlignment(Paragraph.ALIGN_CENTER);
        cell = new PdfPCell(title);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidth(NO_BORDER);
        layoutTbl.addCell(cell);

        Paragraph subTitle = new Paragraph(new Chunk(sdf.format(today), subtitleFont));
        subTitle.setAlignment(Paragraph.ALIGN_CENTER);
        cell = new PdfPCell(subTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidth(NO_BORDER);
        layoutTbl.addCell(cell);

        // spacing
        cell = new PdfPCell(new Paragraph(""));
        cell.setFixedHeight(10);
        cell.setBorderWidth(NO_BORDER);
        layoutTbl.addCell(cell);

        // display report data
        PdfPTable table = new PdfPTable(2);
        Phrase phrase = null;

        // row 1
        phrase = new Phrase("Till No:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(bean.getTillName(), simpleFont);
        table.addCell(phrase);

        // row 2
        phrase = new Phrase("Begining Balance:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(beginningBalance), simpleFont);
        table.addCell(phrase);

        // row 3
        phrase = new Phrase("Net Cash Trx:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(statementDifference), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Till Balance Entered:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(transferAmount), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Difference:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(differenceAmount), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Ending Balance:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(endingBalance), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Cash Total:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(tillCashTotal), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Card Amt Entered:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(cashBeanCardTotal), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Card Total:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(tillCardTotal), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Card Difference:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(cardDifference), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Cheque Amt Entered:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(cashBeanChequeTotal), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Cheque Total:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(tillChequeTotal), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Cheque Difference:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(chequeDifference), simpleFont);
        table.addCell(phrase);

        phrase = new Phrase("Grand Total:", simpleFont);
        table.addCell(phrase);

        phrase = new Phrase(currency + formatter.format(grandTotal), simpleFont);
        table.addCell(phrase);

        layoutTbl.addCell(table);

        document.add(layoutTbl);

    } catch (Exception e) {
        throw new OperationException(e);
    }

    document.close();

    return reportName;

}

From source file:org.silverpeas.components.kmelia.workflowextensions.SendInKmelia.java

License:Open Source License

private void generatePDFStepHeader(HistoryStep step, com.lowagie.text.Document document) {
    try {//from w  w  w .  j  a  v  a  2 s  . c  om
        String activity = "";
        if (step.getResolvedState() != null) {
            State resolvedState = step.getProcessInstance().getProcessModel().getState(step.getResolvedState());
            activity = resolvedState.getLabel(getRole(), getLanguage());
        }

        String sAction;
        try {
            if ("#question#".equals(step.getAction())) {
                sAction = getString("processManager.question");
            } else if ("#response#".equals(step.getAction())) {
                sAction = getString("processManager.response");
            } else if ("#reAssign#".equals(step.getAction())) {
                sAction = getString("processManager.reAffectation");
            } else {
                Action action = step.getProcessInstance().getProcessModel().getAction(step.getAction());
                sAction = action.getLabel(getRole(), getLanguage());
            }
        } catch (WorkflowException we) {
            sAction = "##";
        }

        String actor = step.getUser().getFullName();

        String date = DateUtil.getOutputDateAndHour(step.getActionDate(), getLanguage());

        String header = "";
        if (StringUtil.isDefined(activity)) {
            header += activity + " - ";
        }
        header += sAction + " (" + actor + " - " + date + ")";

        Font fontHeader = new Font(Font.HELVETICA, 12, Font.NORMAL);

        PdfPCell pCell = new PdfPCell(new Phrase(header, fontHeader));
        pCell.setFixedHeight(28);
        pCell.setBackgroundColor(new Color(239, 239, 239));
        pCell.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPTable pTable = new PdfPTable(1);
        pTable.setWidthPercentage(100);
        pTable.addCell(pCell);

        document.add(pTable);
    } catch (Exception e) {
        SilverLogger.getLogger(this).error(e.getMessage(), e);
    }
}

From source file:org.tellervo.desktop.util.labels.PDFLabelMaker.java

License:Open Source License

public void addCell(PdfPCell cell) {

    cell.setBorder(borderwidth);//from ww  w  .j  a v a2  s .  co m

    cell.setNoWrap(false);
    cell.setFixedHeight(margins.getLabelHeight());

    //cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    //cell.setVerticalAlignment(Element.ALIGN_TOP);

    if (curX != 0) {
        PdfPCell gapcell = new PdfPCell();
        gapcell.setBorder(borderwidth);
        table.addCell(gapcell);
    }

    curX++;
    table.addCell(cell);

    if (curX == nAcross)
        //table.completeRow();
        curX = 0;
}

From source file:org.viafirma.util.QRCodeUtil.java

License:Apache License

/**
 * @param texto/*  w w  w . j  a  v a  2 s. co  m*/
 *            Texto a colocar
 * @param textoQR
 *            Imagen QR a colocar
 * @param codFirma
 *            Cdigo de Firma a generar.
 * @param url Url del servicio de verificacin desde donde se puede descargar el documento.
 * @param document
 *            Documeto destino
 * @param pageSize
 *            Tamao de la pgina
 * @return 
 * @throws BadElementException
 * @throws MalformedURLException
 * @throws IOException
 * @throws DocumentException
 * @throws ExcepcionErrorInterno
 */
private static float addContent(String texto, String url, String textoQR, String codFirma, Document document,
        Rectangle pageSize, boolean completo, boolean isSellado) throws BadElementException,
        MalformedURLException, IOException, DocumentException, ExcepcionErrorInterno {

    Image imagenCabezera = null;
    float widthCabecera = 0;
    float heightCabecera = 0;
    if (!isSellado) {
        // Recuperamos la imagen de cabecera
        imagenCabezera = Image.getInstance(QRCodeUtil.class.getResource(IMAGE_CABECERA));
        // Colocamos la imagen en la zona superior de la pgina
        imagenCabezera.setAbsolutePosition(0, pageSize.getHeight() - imagenCabezera.getHeight());
        heightCabecera = imagenCabezera.getHeight();
        widthCabecera = imagenCabezera.getWidth();
    }

    // Recuperamos el pie de firma
    Image imagenQR = Image.getInstance(QRCodeUtil.getInstance().generate(texto, url, textoQR, codFirma));

    float rescalado = pageSize.getWidth() / (widthCabecera + document.leftMargin() + document.rightMargin());
    float sizeCabecera = 0;
    if (rescalado < 1f && !isSellado) {
        // Requiere rescalado, la imagen es mayor que la pgina.
        imagenCabezera.scalePercent(rescalado * 100);
        sizeCabecera = rescalado * imagenCabezera.getHeight();
    }

    float sizeCabecerayPie = HEIGHT_QR_CODE_PDF + sizeCabecera + document.bottomMargin() + document.topMargin()
            + SPACE_SEPARACION;
    // float escaleQR = HEIGHT_QR_CODE_PDF / (imagenQR.getHeight() + 5);
    float escaleQR = (pageSize.getWidth() - document.leftMargin() - document.rightMargin())
            / (imagenQR.getWidth() + 6);

    // imagen.setSpacingAfter(120);
    if (!isSellado) {
        document.add(imagenCabezera);
    }
    // Aadimos una caja de texto si estamos mostrando el contenido del
    // fichero firmado.
    if (completo) {
        // Aadimos el espacio ocupado por la imagen
        Paragraph p = new Paragraph("");
        p.setSpacingAfter(heightCabecera * rescalado);
        document.add(p);

        // Aadimos una tabla con borde donde colocar el documento.
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorderWidth(10);
        PdfPCell celda = new PdfPCell();
        celda.setFixedHeight(pageSize.getHeight() - sizeCabecerayPie);
        table.addCell(celda);
        table.setSpacingAfter(SPACE_SEPARACION);
        document.add(table);
    }

    if (completo) {
        // La imagen la colocamos justo debajo
        imagenQR.setAbsolutePosition(document.leftMargin(),
                escaleQR * HEIGHT_QR_CODE_PDF - SPACE_SEPARACION * 2);
    } else {
        imagenQR.setAbsolutePosition(document.leftMargin(), pageSize.getHeight() - sizeCabecerayPie);
    }
    imagenQR.scalePercent(escaleQR * 100);
    document.add(imagenQR);

    return sizeCabecerayPie;
}

From source file:sms.ReportForms.java

public PdfPCell createImageCell(String path) throws IOException {
    PdfPCell cell = null;
    try {/*w w w .  j  a  v a  2s. c o  m*/
        Image img = Image.getInstance(path);
        cell = new PdfPCell(img, true);
        cell.setFixedHeight(60);
        cell.setBorder(Rectangle.NO_BORDER);

    } catch (BadElementException ex) {
        Logger.getLogger(ReportForms.class.getName()).log(Level.SEVERE, null, ex);
    } catch (MalformedURLException ex) {
        Logger.getLogger(ReportForms.class.getName()).log(Level.SEVERE, null, ex);
    }

    return cell;
}

From source file:storemanagment.Printing.java

public PdfPCell createImageCell(String path) throws IOException {
    PdfPCell cell = null;
    try {/*from  ww w .  j a v a2s .  c  om*/
        Image img = Image.getInstance(path);
        cell = new PdfPCell(img, true);
        cell.setFixedHeight(30);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(10);

    } catch (BadElementException ex) {
        Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
    } catch (MalformedURLException ex) {
        Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
    }

    return cell;
}

From source file:test.itext.html.AimsPdf.java

License:Open Source License

public static void addTitle(Document doc, String text)
        throws IOException, BadElementException, DocumentException {
    float[] widths = { 62f, 164f, 62f };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage(100);/*from ww  w  .  j  a  v  a 2  s.  c  o  m*/
    table.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.setSpacingAfter(10);

    Image image = Image.getInstance("app_title.gif");
    image.scalePercent(70);
    PdfPCell cell = new PdfPCell(image);
    cell.setPadding(10);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    Paragraph title = new Paragraph(text, FontFactory.getFont("arial", 12, Font.BOLD));
    cell = new PdfPCell(title);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    image = Image.getInstance("title_shot.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(10);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    doc.add(table);

    table = new PdfPTable(1);
    table.setWidthPercentage(100);
    cell = new PdfPCell();
    cell.setBackgroundColor(Color.BLACK);
    cell.setFixedHeight(1);
    table.addCell(cell);

    doc.add(table);
}