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

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

Introduction

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

Prototype

public void setHorizontalAlignment(int horizontalAlignment) 

Source Link

Document

Sets the horizontal alignment of the table relative to the page.

Usage

From source file:com.krawler.esp.servlets.ExportReportServlet.java

License:Open Source License

private static void prepare(Document d, HeaderFooter hfFooter) {
    PdfPTable table = new PdfPTable(1);
    try {/*from  w w  w . j a v a2s . c  om*/
        d.setFooter(hfFooter);
        d.open();
        imgPath = StorageHandler.GetProfileImgStorePath() + StorageHandler.GetFileSeparator() + imgPath;
        //                  imgPath = "/home/krawler-user/logo.jpg";                
        table.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.setWidthPercentage(50);
        PdfPCell cell = null;
        try {
            Image img = Image.getInstance(imgPath);
            cell = new PdfPCell(img);
        } catch (Exception e) {
            cell = new PdfPCell(new Paragraph(companyName, fontBig));
        }
        cell.setBorder(0);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);

        d.add(table);
    } catch (Exception e) {
        Logger.getLogger(ExportProjectReportServlet.class.getName()).log(Level.SEVERE, null, e);
    }
}

From source file:com.krawler.esp.servlets.ExportReportServlet.java

License:Open Source License

private static void addCenter(Document d) throws DocumentException {

    PdfPTable table = new PdfPTable(1);
    table.setHorizontalAlignment(Element.ALIGN_CENTER);

    table.setWidthPercentage(50);//from www  .  j a  v a 2s  .  c om
    table.setSpacingBefore(10);
    PdfPCell cell = null;
    cell = new PdfPCell(new Paragraph(ProjectName, fontBold));
    cell.setBorder(0);
    cell.setBorderWidth(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph(ReportName, fontRegular));
    cell.setBorder(0);
    cell.setBorderWidth(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);
    // For tasks which prompt user for a start and end date
    if (!(StringUtil.isNullOrEmpty(RepStartDate) && StringUtil.isNullOrEmpty(RepEndDate))) {
        cell = new PdfPCell(new Paragraph("From:" + RepStartDate + " To:" + RepEndDate, fontSmallRegular));
        cell.setBorder(0);
        cell.setBorderWidth(0);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
    }
    table.setSpacingAfter(10);
    d.add(table);
}

From source file:com.krawler.esp.servlets.ExportServlet.java

License:Open Source License

private static void addComponyLogo(Document d, HttpServletRequest req)
        throws ConfigurationException, DocumentException {
    PdfPTable table = new PdfPTable(1);
    imgPath = StorageHandler.GetProfileImgStorePath() + "logo.gif";
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    table.setWidthPercentage(50);//from   w  ww .java 2  s  . com
    PdfPCell cell = null;
    try {
        if (StringUtil.isStandAlone()) {
            imgPath = URLUtil.getPageURL(req, "").concat(defaultCompanyImgPath);
        }
        Image img = Image.getInstance(imgPath);
        cell = new PdfPCell(img);
    } catch (Exception e) {
        cell = new PdfPCell(new Paragraph(companyName, fontBig));
    }
    cell.setBorder(0);
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    table.addCell(cell);
    d.add(table);
}

From source file:com.krawler.esp.servlets.ExportServlet.java

License:Open Source License

private static void addTitleSubtitle(Document d) throws DocumentException, JSONException {
    java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16));
    fontBold.setColor(tColor);//from  ww w. java  2  s. c  o  m
    fontRegular.setColor(tColor);
    PdfPTable table = new PdfPTable(1);
    table.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.setWidthPercentage(100);
    table.setSpacingBefore(6);

    //Report Title
    PdfPCell cell = new PdfPCell(new Paragraph(config.getString("title"), fontBold));
    cell.setBorder(0);
    cell.setBorderWidth(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    //Report Subtitle(s)
    String[] SubTitles = config.getString("subtitles").split("~");// '~' as separator
    for (int i = 0; i < SubTitles.length; i++) {
        cell = new PdfPCell(new Paragraph(SubTitles[i], fontSmallRegular));
        cell.setBorder(0);
        cell.setBorderWidth(0);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
    }
    table.setSpacingAfter(6);
    d.add(table);

    //Separator line
    PdfPTable line = new PdfPTable(1);
    line.setWidthPercentage(100);
    PdfPCell cell1 = null;
    cell1 = new PdfPCell(new Paragraph(""));
    cell1.setBorder(PdfPCell.BOTTOM);
    line.addCell(cell1);
    d.add(line);
}

From source file:com.krawler.spring.exportFuctionality.ExportinvController.java

License:Open Source License

private ByteArrayOutputStream createForm(String currencyid, String[] header1, String[] header2,
        String[] header3, String[] header4, String[] values1, String[] values2, String[] values3,
        String[] values4, String string, Object ob, Company com, String contextpath, String logoPath,
        DateFormat formatter) throws JSONException, DocumentException, ServiceException, IOException {
    ByteArrayOutputStream baos = null;
    Document document = null;//from w  w  w.  ja  v a2 s . c om
    PdfWriter writer = null;
    try {
        String company[] = new String[3];
        company[0] = com.getCompanyName();
        company[1] = com.getAddress();
        company[2] = com.getEmailID();
        baos = new ByteArrayOutputStream();
        document = new Document(PageSize.A4, 15, 15, 15, 15);
        writer = PdfWriter.getInstance(document, baos);
        document.open();
        addHeaderFooter(document, writer);
        PdfPTable tab1 = null;
        PdfPTable tab2 = null;
        PdfPTable tab3 = null;

        /*-----------------------------Add Company Name in Center ------------------*/
        tab1 = new PdfPTable(1);
        tab1.setHorizontalAlignment(Element.ALIGN_LEFT);
        PdfPCell cell = new PdfPCell(new Paragraph(com.getCompanyName(), fontBig));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(0);
        tab1.addCell(cell);

        tab2 = new PdfPTable(1);
        tab2.setHorizontalAlignment(Element.ALIGN_LEFT);
        imgPath = logoPath;
        PdfPCell imgCell = null;
        try {
            Image img = Image.getInstance(imgPath);
            imgCell = new PdfPCell(img);
        } catch (Exception e) {
            imgCell = new PdfPCell(new Paragraph(com.getCompanyName(), fontBig));
        }
        imgCell.setHorizontalAlignment(Element.ALIGN_LEFT);
        imgCell.setBorder(0);
        tab2.addCell(imgCell);

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new float[] { 40, 60 });
        PdfPCell cellCompimg = new PdfPCell(tab2);
        cellCompimg.setBorder(0);
        table.addCell(cellCompimg);
        PdfPCell cellCompname = new PdfPCell(tab1);
        cellCompname.setBorder(0);
        table.addCell(cellCompname);
        document.add(table);
        document.add(new Paragraph("\n\n\n"));

        /*-----------------------------Add Company information and Invoice Info------------------*/
        PdfPTable table2 = new PdfPTable(3);
        table2.setWidthPercentage(100);
        if (header4.length != 0)
            table2.setWidths(new float[] { 40, 30, 30 });
        else
            table2.setWidths(new float[] { 50, 50, 0 });
        tab1 = getCompanyInfo(company);
        tab2 = createTable(header1, values1);
        PdfPCell cell1 = new PdfPCell(tab1);
        cell1.setBorder(0);
        table2.addCell(cell1);
        PdfPCell cell2 = new PdfPCell(tab2);
        cell2.setBorder(1);
        table2.addCell(cell2);
        PdfPCell cel = new PdfPCell();
        if (header4.length != 0) {
            tab3 = createTable(header4, values4);
            cel = new PdfPCell(tab3);
        } else
            cel = new PdfPCell(new Paragraph("", fontSmallRegular));
        cel.setBorder(1);
        table2.addCell(cel);
        document.add(table2);
        document.add(new Paragraph("\n\n\n"));

        /*-----------------------------Add BillTo Amount Enclosed -------------------------*/
        PdfPTable table3 = new PdfPTable(1);
        table3.setWidthPercentage(100);
        tab1 = createTable(header2, values2);
        PdfPCell cell3 = new PdfPCell(tab1);
        cell3.setBorder(1);
        table3.addCell(cell3);
        document.add(table3);
        document.add(new Paragraph("\n\n\n\n\n\n"));

        /*-----------------------------Add Cutting Line -------------------------*/
        PdfPTable table4 = new PdfPTable(1);
        imgPath = contextpath + "/images/pdf-cut.jpg";
        table4.setHorizontalAlignment(Element.ALIGN_LEFT);
        table4.setWidthPercentage(100);
        PdfPCell cell11 = null;
        try {
            Image img = Image.getInstance(imgPath);
            img.scalePercent(35);
            cell11 = new PdfPCell(img);
        } catch (Exception e) {
        }
        cell11.setBorder(0);
        table4.addCell(cell11);
        document.add(table4);
        document.add(new Paragraph("\n\n"));

        /*-----------------------------Add Product Information ------------------*/
        PdfPTable table5 = new PdfPTable(1);
        table5.setWidthPercentage(100);
        if (string.equals("GoodsReceipt")) {
            GoodsReceipt gr = (GoodsReceipt) ob;
            tab1 = createGoodsReceiptTable(header3, values3, currencyid, gr);
        } else if (string.equals("debit")) {
            DebitNote dn = (DebitNote) ob;
            tab1 = createDebitTable(header3, values3, currencyid, dn);
        } else if (string.equals("billingdebit")) {
            BillingDebitNote dn = (BillingDebitNote) ob;
            tab1 = createDebitTable(header3, values3, currencyid, dn);
        } else if (string.equals("credit")) {
            CreditNote cn = (CreditNote) ob;
            tab1 = createCreditTable(header3, values3, currencyid, cn);
        } else if (string.equals("billingcredit")) {
            BillingCreditNote cn = (BillingCreditNote) ob;
            tab1 = createCreditTable(header3, values3, currencyid, cn);
        } else if (string.equals("PurchaseOrder")) {
            PurchaseOrder po = (PurchaseOrder) ob;
            tab1 = createPurchaseOrderTable(header3, values3, currencyid, po);
        } else if (string.equals("BillingPurchaseOrder")) {
            BillingPurchaseOrder po = (BillingPurchaseOrder) ob;
            tab1 = createPurchaseOrderTable(header3, values3, currencyid, po);
        } else if (string.equals("SalesOrder")) {
            SalesOrder so = (SalesOrder) ob;
            tab1 = createSalesOrderTable(header3, values3, currencyid, so);
        } else if (string.equals("BillingSalesOrder")) {
            BillingSalesOrder so = (BillingSalesOrder) ob;
            tab1 = createSalesOrderTable(header3, values3, currencyid, so);
        } else if (string.equals("Payment")) {
            Payment pay = (Payment) ob;
            tab1 = createPaymentTable(header3, values3, currencyid, pay, formatter);
        } else if (string.equals("Quotation")) {
            Quotation quotation = (Quotation) ob;
            tab1 = createQuotationTable(header3, values3, currencyid, quotation);
        }
        PdfPCell cell5 = new PdfPCell(tab1);
        cell5.setBorder(1);
        table5.addCell(cell5);
        document.add(table5);
        document.add(new Paragraph("\n\n\n"));

        /*-----------------------------Download file ------------------*/
        return baos;
    } catch (Exception ex) {
        return null;
    } finally {
        if (document != null)
            document.close();
        if (writer != null)
            writer.close();
        if (baos != null)
            baos.close();
    }
}

From source file:com.krawler.spring.exportFuctionality.ExportinvController.java

License:Open Source License

public PdfPTable getCompanyInfo(String com[]) {
    PdfPTable tab1 = new PdfPTable(1);
    tab1.setHorizontalAlignment(Element.ALIGN_LEFT);
    for (int i = 0; i < 3; i++) {
        PdfPCell cell = new PdfPCell(new Paragraph(com[i], fontMediumBold));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(0);//from  w w w  .jav a 2  s  .c o m
        tab1.addCell(cell);
    }
    return tab1;
}

From source file:com.krawler.spring.exportFuctionality.ExportRecord.java

License:Open Source License

public PdfPTable getCompanyInfo(String com[]) {
    PdfPTable tab1 = new PdfPTable(1);
    tab1.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell cell = new PdfPCell(new Paragraph(com[0], fontMediumBold));
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setBorder(0);/*from  w w  w  .j  a  va2 s. co  m*/
    tab1.addCell(cell);
    for (int i = 1; i < com.length; i++) {
        cell = new PdfPCell(new Paragraph(com[i], fontTblMediumBold));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(0);
        tab1.addCell(cell);
    }
    return tab1;
}

From source file:com.krawler.spring.exportFunctionality.exportDAOImpl.java

License:Open Source License

public void addComponyLogo(Document d, HttpServletRequest request) throws ServiceException {
    try {//from www  . j  ava2s .  com
        PdfPTable table = new PdfPTable(1);
        imgPath = getImgPath(request);
        table.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.setWidthPercentage(50);
        PdfPCell cell = null;
        try {
            Image img = Image.getInstance(imgPath);
            cell = new PdfPCell(img);
        } catch (Exception e) {
            companyName = sessionHandlerImplObj.getCompanyName(request);
            cell = new PdfPCell(new Paragraph(fontFamilySelector.process(companyName, FontContext.LOGO_TEXT)));
        }
        cell.setBorder(0);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        d.add(table);
    } catch (Exception e) {
        throw ServiceException.FAILURE("exportDAOImpl.addComponyLogo", e);
    }
}

From source file:com.krawler.spring.exportFunctionality.exportDAOImpl.java

License:Open Source License

public void addTitleSubtitle(Document d) throws ServiceException {
    try {/*from   w ww . j  a va  2 s  .  c om*/
        java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16));
        PdfPTable table = new PdfPTable(1);
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        table.setWidthPercentage(100);
        table.setSpacingBefore(6);

        //Report Title
        PdfPCell cell = new PdfPCell(new Paragraph(
                fontFamilySelector.process(config.getString("title"), FontContext.REPORT_TITLE, tColor)));//fontBold));
        cell.setBorder(0);
        cell.setBorderWidth(0);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);

        //Report Subtitle(s)
        String[] SubTitles = config.getString("subtitles").split("~");// '~' as separator
        for (int i = 0; i < SubTitles.length; i++) {
            cell = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(SubTitles[i], FontContext.REPORT_TITLE, tColor)));
            cell.setBorder(0);
            cell.setBorderWidth(0);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
        }
        table.setSpacingAfter(6);
        d.add(table);

        //Separator line
        PdfPTable line = new PdfPTable(1);
        line.setWidthPercentage(100);
        PdfPCell cell1 = null;
        cell1 = new PdfPCell(new Paragraph(""));
        cell1.setBorder(PdfPCell.BOTTOM);
        line.addCell(cell1);
        d.add(line);
    } catch (Exception e) {
        throw ServiceException.FAILURE("exportDAOImpl.addTitleSubtitle", e);
    }
}

From source file:com.krawler.spring.exportFunctionality.exportDAOImpl.java

License:Open Source License

public ByteArrayOutputStream getInvoicePdfData(HttpServletRequest request, JSONObject obj,
        Map<String, Object> DataInfo, Company com, DateFormat formatter, String currencyid,
        JSONArray productDetails, int mode, String letterHead, String preText, String postText)
        throws ServiceException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer = null;/*  w w w .  j a  v a  2 s . co m*/
    Document document = null;
    try {
        config = new com.krawler.utils.json.base.JSONObject(DataInfo.get("config").toString());
        String baseUrl = URLUtil.getRequestPageURL(request, UnprotectedLoginPageFull);
        Rectangle rec = null;
        if (config.getBoolean("landscape")) {
            Rectangle recPage = new Rectangle(PageSize.A4.rotate());
            recPage.setBackgroundColor(new java.awt.Color(Integer.parseInt(config.getString("bgColor"), 16)));
            document = new Document(recPage, 15, 15, 30, 30);
            rec = document.getPageSize();
        } else {
            Rectangle recPage = new Rectangle(PageSize.A4);
            recPage.setBackgroundColor(new java.awt.Color(Integer.parseInt(config.getString("bgColor"), 16)));
            document = new Document(recPage, 15, 15, 30, 30);
            rec = document.getPageSize();
        }
        writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new EndPage());
        document.open();
        if (config.getBoolean("showLogo")) {
            addComponyLogo(document, request);
        }

        if (!StringUtil.isNullOrEmpty(letterHead)) {
            PdfPTable letterHeadTable = new PdfPTable(1);
            getHtmlCell(letterHead, letterHeadTable, baseUrl);
            letterHeadTable.setHorizontalAlignment(Element.ALIGN_LEFT);
            document.add(letterHeadTable);
        }

        addTitleSubtitle(document);
        createInvoicePdf(document, mode, DataInfo, com, formatter, currencyid, productDetails, preText,
                postText, baseUrl);
    } catch (DocumentException ex) {
        errorMsg = ex.getMessage();
        throw ServiceException.FAILURE("exportDAOImpl.getInvoicePdfData", ex);
    } catch (JSONException e) {
        errorMsg = e.getMessage();
        throw ServiceException.FAILURE("exportDAOImpl.getInvoicePdfData", e);
    } catch (Exception e) {
        e.printStackTrace();
        errorMsg = e.getMessage();
        throw ServiceException.FAILURE("exportDAOImpl.getInvoicePdfData", e);
    } finally {
        if (document != null) {
            document.close();
        }
        if (writer != null) {
            writer.close();
        }
    }
    return baos;
}