Example usage for com.lowagie.text Rectangle Rectangle

List of usage examples for com.lowagie.text Rectangle Rectangle

Introduction

In this page you can find the example usage for com.lowagie.text Rectangle Rectangle.

Prototype

public Rectangle(Rectangle rect) 

Source Link

Document

Constructs a Rectangle -object.

Usage

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

License:Open Source License

private ByteArrayOutputStream getPdfData(JSONArray data, JSONArray res, HttpServletRequest request)
        throws ServiceException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {//from   w w w.j a va2s.c  o m
        String[] colHeader = getColHeader();
        String[] colIndex = getColIndexes();
        String[] val = getColValues(colHeader, data);
        String[] resources = getResourcesColHeader(res, data);
        String[] mainHeader = { "Dates", "Duration", "Work", "Cost", "Tasks", "Resources" };
        Document document = null;
        if (landscape) {
            Rectangle recPage = new Rectangle(PageSize.A4.rotate());
            recPage.setBackgroundColor(new java.awt.Color(255, 255, 255));
            document = new Document(recPage, 15, 15, 30, 30);
        } else {
            Rectangle recPage = new Rectangle(PageSize.A4);
            recPage.setBackgroundColor(new java.awt.Color(255, 255, 255));
            document = new Document(recPage, 15, 15, 30, 30);
        }
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new EndPage());
        document.open();
        if (showLogo) {
            getCompanyDetails(request);
            addComponyLogo(document, request);
        }
        addTitleSubtitle(document);
        addTable(data, resources, colIndex, colHeader, mainHeader, val, document);
        document.close();
        writer.close();
        baos.close();
    } catch (ConfigurationException ex) {
        throw ServiceException.FAILURE("ExportProjectReport.getPdfData", ex);
    } catch (DocumentException ex) {
        throw ServiceException.FAILURE("ExportProjectReport.getPdfData", ex);
    } catch (JSONException e) {
        throw ServiceException.FAILURE("ExportProjectReport.getPdfData", e);
    } catch (IOException e) {
        throw ServiceException.FAILURE("ExportProjectReport.getPdfData", e);
    } catch (Exception e) {
        throw ServiceException.FAILURE("ExportProjectReport.getPdfData", e);
    }
    return baos;
}

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

License:Open Source License

private ByteArrayOutputStream getPdfData(JSONArray gridmap, HttpServletRequest request, Session session)
        throws ServiceException, SessionExpiredException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer = null;/* w  ww  .  j  av a  2  s.c  o  m*/
    try {
        String colHeader = "";
        String colHeaderFinal = "";
        String fieldListFinal = "";
        String fieldList = "";
        String width = "";
        String align = "";
        String alignFinal = "";
        String widthFinal = "";
        String colHeaderArrStr[] = null;
        String dataIndexArrStr[] = null;
        String widthArrStr[] = null;
        String alignArrStr[] = null;
        String htmlCode = "";
        String advStr = "";
        int strLength = 0;
        float totalWidth = 0;

        config = new com.krawler.utils.json.base.JSONObject(request.getParameter("config"));
        String tmpTitle = config.getString("title");
        Document document = null;
        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();
            totalWidth = rec.getWidth();
        } 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();
            totalWidth = rec.getWidth();
        }

        writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new EndPage());
        document.open();
        if (config.getBoolean("showLogo")) {
            addComponyLogo(document, request);
        }

        addTitleSubtitle(document);

        if (gridmap != null) {
            for (int i = 0; i < gridmap.length(); i++) {
                JSONObject temp = gridmap.getJSONObject(i);
                colHeader += temp.getString("title");
                if (colHeader.indexOf("*") != -1)
                    colHeader = colHeader.substring(0, colHeader.indexOf("*") - 1) + ",";
                else
                    colHeader += ",";
                fieldList += temp.getString("header") + ",";
                if (!config.getBoolean("landscape")) {
                    int totalWidth1 = (int) ((totalWidth / gridmap.length()) - 5.00);
                    width += "" + totalWidth1 + ","; //resize according to page view[potrait]
                } else
                    width += temp.getString("width") + ",";
                if (temp.getString("align").equals("")) {
                    align += "none" + ",";
                } else {
                    align += temp.getString("align") + ",";
                }
            }
            strLength = colHeader.length() - 1;
            colHeaderFinal = colHeader.substring(0, strLength);
            strLength = fieldList.length() - 1;
            fieldListFinal = fieldList.substring(0, strLength);
            strLength = width.length() - 1;
            widthFinal = width.substring(0, strLength);
            strLength = align.length() - 1;
            alignFinal = align.substring(0, strLength);
            colHeaderArrStr = colHeaderFinal.split(",");
            dataIndexArrStr = fieldListFinal.split(",");
            widthArrStr = widthFinal.split(",");
            alignArrStr = alignFinal.split(",");
        } else {
            fieldList = request.getParameter("header");
            colHeader = request.getParameter("title");
            width = request.getParameter("width");
            align = request.getParameter("align");
            colHeaderArrStr = colHeader.split(",");
            dataIndexArrStr = fieldList.split(",");
            widthArrStr = width.split(",");
            alignArrStr = align.split(",");
        }

        JSONObject obj = null;
        obj = getReport(request, session);
        JSONArray store = obj.getJSONArray("data");

        addTable(0, colHeaderArrStr.length, 0, store.length(), store, dataIndexArrStr, colHeaderArrStr,
                widthArrStr, alignArrStr, document, request, session);

        document.close();

    } catch (ConfigurationException ex) {
        throw ServiceException.FAILURE("ExportProjectReport.getPdfData", ex);
    } catch (DocumentException ex) {
        throw ServiceException.FAILURE("ExportProjectReport.getPdfData", ex);
    } catch (JSONException e) {
        throw ServiceException.FAILURE("ExportProjectReport.getPdfData", e);
    } finally {
        writer.close();
    }
    return baos;
}

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;//from   w  w w .j a v a 2  s  .c om
    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;
}

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

License:Open Source License

public ByteArrayOutputStream getPdfData(JSONArray gridmap, HttpServletRequest request, JSONObject obj)
        throws ServiceException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer = null;/*from   w w  w .  j  a v a 2 s .com*/
    Document document = null;
    try {
        String colHeader = "";
        String colHeaderFinal = "";
        String fieldListFinal = "";
        String fieldList = "";
        String width = "";
        String align = "";
        String xtype = "";
        String alignFinal = "";
        String xtypeFinal = "";
        String widthFinal = "";
        String colHeaderArrStr[] = null;
        String dataIndexArrStr[] = null;
        String widthArrStr[] = null;
        String alignArrStr[] = null;
        String xtypeArrStr[] = null;
        String htmlCode = "";
        String advStr = "";
        int strLength = 0;
        float totalWidth = 0;

        config = new com.krawler.utils.json.base.JSONObject(request.getParameter("config"));
        if (request.getParameter("searchJson") != null && !request.getParameter("searchJson").equals("")) {
            JSONObject json = new JSONObject(request.getParameter("searchJson"));
            JSONArray advSearch = json.getJSONArray("root");
            for (int i = 0; i < advSearch.length(); i++) {
                JSONObject key = advSearch.getJSONObject(i);
                String value = "";
                String name = key.getString("columnheader");
                name = URLDecoder.decode(name);
                name.trim();
                if (name.contains("*")) {
                    name = name.substring(0, name.indexOf("*") - 1);
                }
                if (name.contains("(") && name.charAt(name.indexOf("(") + 1) == '&') {
                    htmlCode = name.substring(name.indexOf("(") + 3, name.length() - 2);
                    char temp = (char) Integer.parseInt(htmlCode, 10);
                    htmlCode = Character.toString(temp);
                    if (htmlCode.equals("$")) {
                        String currencyid = sessionHandlerImpl.getCurrencyID(request);
                        String currency = currencyRender(key.getString("combosearch"), currencyid);
                        name = name.substring(0, name.indexOf("(") - 1);
                        name = name + "(" + htmlCode + ")";
                        value = currency;
                    } else {
                        name = name.substring(0, name.indexOf("(") - 1);
                        value = name + " " + htmlCode;
                    }
                } else {
                    value = key.getString("combosearch");
                }
                advStr += name + " : " + value + ",";
            }
            advStr = advStr.substring(0, advStr.length() - 1);
            config.remove("subtitles");
            config.put("subtitles", "Filtered By: " + advStr);
        }
        if (request.getParameter("frm") != null && !request.getParameter("frm").equals("")) {
            KWLDateFormat dateFormat = (KWLDateFormat) hibernateTemplate.load(KWLDateFormat.class,
                    sessionHandlerImplObj.getDateFormatID(request));
            String prefDate = dateFormat.getJavaForm();
            Date from = new Date(Long.parseLong(request.getParameter("frm")));
            Date to = new Date(Long.parseLong(request.getParameter("to")));
            config.remove("subtitles");
            String timeFormatId = sessionHandlerImplObj.getUserTimeFormat(request);
            String timeZoneDiff = sessionHandlerImplObj.getTimeZoneDifference(request);
            config.put("subtitles", "Filtered By: From : "
                    + authHandler.getPrefDateFormatter(timeFormatId, timeZoneDiff, prefDate).format(from)
                    + " To : "
                    + authHandler.getPrefDateFormatter(timeFormatId, timeZoneDiff, prefDate).format(to));
        }

        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();
            totalWidth = rec.getWidth();
        } 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();
            totalWidth = rec.getWidth();
        }

        writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new EndPage());
        document.open();
        if (config.getBoolean("showLogo")) {
            addComponyLogo(document, request);
        }

        addTitleSubtitle(document);

        if (gridmap != null) {
            for (int i = 0; i < gridmap.length(); i++) {
                JSONObject temp = gridmap.getJSONObject(i);
                colHeader += URLDecoder.decode(temp.getString("title"), "utf-8");
                if (colHeader.indexOf("*") != -1) {
                    colHeader = colHeader.substring(0, colHeader.indexOf("*") - 1) + ",";
                } else {
                    colHeader += ",";
                }
                fieldList += temp.getString("header").replace("$$", "#") + ",";// handled case for custom report. Because dataindex field have "#" symbol and while exporting data URL will break if having # symbol. So replaced # with $$ at JS side and reverted this change at Java side
                if (!config.getBoolean("landscape")) {
                    int totalWidth1 = (int) ((totalWidth / gridmap.length()) - 5.00);
                    width += "" + totalWidth1 + ","; //resize according to page view[potrait]
                } else {
                    width += temp.getString("width") + ",";
                }
                if (temp.optString("align").equals("")) {
                    align += "none" + ",";
                } else {
                    align += temp.getString("align") + ",";
                }
                if (temp.optString("xtype").equals("")) {
                    xtype += "none" + ",";
                } else {
                    xtype += temp.getString("xtype") + ",";
                }
            }
            strLength = colHeader.length() - 1;
            colHeaderFinal = colHeader.substring(0, strLength);
            strLength = fieldList.length() - 1;
            fieldListFinal = fieldList.substring(0, strLength);
            strLength = width.length() - 1;
            widthFinal = width.substring(0, strLength);
            strLength = align.length() - 1;
            alignFinal = align.substring(0, strLength);
            strLength = xtype.length() - 1;
            xtypeFinal = xtype.substring(0, strLength);
            colHeaderArrStr = colHeaderFinal.split(",");
            dataIndexArrStr = fieldListFinal.split(",");
            widthArrStr = widthFinal.split(",");
            alignArrStr = alignFinal.split(",");
            xtypeArrStr = xtypeFinal.split(",");
        } else {
            fieldList = request.getParameter("header");
            colHeader = URLDecoder.decode(request.getParameter("title"));
            width = request.getParameter("width");
            align = request.getParameter("align");
            xtype = request.getParameter("xtype");
            colHeaderArrStr = colHeader.split(",");
            dataIndexArrStr = fieldList.split(",");
            widthArrStr = width.split(",");
            alignArrStr = align.split(",");
            xtypeArrStr = xtype.split(",");
        }

        JSONArray store = null;
        if (obj.isNull("coldata")) {
            store = obj.getJSONArray("data");
        } else {
            store = obj.getJSONArray("coldata");
        }
        addTable(0, colHeaderArrStr.length, 0, store.length(), store, dataIndexArrStr, colHeaderArrStr,
                widthArrStr, alignArrStr, xtypeArrStr, document);

    } catch (DocumentException ex) {
        errorMsg = ex.getMessage();
        throw ServiceException.FAILURE("exportDAOImpl.getPdfData", ex);
    } catch (JSONException e) {
        errorMsg = e.getMessage();
        throw ServiceException.FAILURE("exportDAOImpl.getPdfData", e);
    } catch (Exception e) {
        errorMsg = e.getMessage();
        throw ServiceException.FAILURE("exportDAOImpl.getPdfData", e);
    } finally {
        if (document != null) {
            document.close();
        }
        if (writer != null) {
            writer.close();
        }
    }
    return baos;
}

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

License:Open Source License

public ByteArrayOutputStream getPdfData(JSONArray gridmap, String configStr, String titleStr, String headerStr,
        String widthStr, String alignStr, String xtypeStr, JSONObject obj) throws ServiceException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer = null;//  ww w. j a va  2 s  . c  om
    Document document = null;
    try {
        String colHeader = "";
        String colHeaderFinal = "";
        String fieldListFinal = "";
        String fieldList = "";
        String width = "";
        String align = "";
        String xtype = "";
        String alignFinal = "";
        String xtypeFinal = "";
        String widthFinal = "";
        String colHeaderArrStr[] = null;
        String dataIndexArrStr[] = null;
        String widthArrStr[] = null;
        String alignArrStr[] = null;
        String xtypeArrStr[] = null;
        String htmlCode = "";
        String advStr = "";
        int strLength = 0;
        float totalWidth = 0;

        config = new com.krawler.utils.json.base.JSONObject(configStr);
        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();
            totalWidth = rec.getWidth();
        } 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();
            totalWidth = rec.getWidth();
        }

        writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new EndPage());
        document.open();
        //            if (config.getBoolean("showLogo")) {
        //                addComponyLogo(document, request);
        //            }

        addTitleSubtitle(document);

        if (gridmap != null) {
            for (int i = 0; i < gridmap.length(); i++) {
                JSONObject temp = gridmap.getJSONObject(i);
                colHeader += URLDecoder.decode(temp.getString("title"), "utf-8");
                if (colHeader.indexOf("*") != -1) {
                    colHeader = colHeader.substring(0, colHeader.indexOf("*") - 1) + ",";
                } else {
                    colHeader += ",";
                }
                fieldList += temp.getString("header") + ",";
                if (!config.getBoolean("landscape")) {
                    int totalWidth1 = (int) ((totalWidth / gridmap.length()) - 5.00);
                    width += "" + totalWidth1 + ","; //resize according to page view[potrait]
                } else {
                    width += temp.getString("width") + ",";
                }
                if (temp.getString("align").equals("")) {
                    align += "none" + ",";
                } else {
                    align += temp.getString("align") + ",";
                }
                if (temp.getString("xtype").equals("")) {
                    xtype += "none" + ",";
                } else {
                    xtype += temp.getString("xtype") + ",";
                }
            }
            strLength = colHeader.length() - 1;
            colHeaderFinal = colHeader.substring(0, strLength);
            strLength = fieldList.length() - 1;
            fieldListFinal = fieldList.substring(0, strLength);
            strLength = width.length() - 1;
            widthFinal = width.substring(0, strLength);
            strLength = align.length() - 1;
            alignFinal = align.substring(0, strLength);
            xtypeFinal = xtype.substring(0, strLength);
            colHeaderArrStr = colHeaderFinal.split(",");
            dataIndexArrStr = fieldListFinal.split(",");
            widthArrStr = widthFinal.split(",");
            alignArrStr = alignFinal.split(",");
            xtypeArrStr = xtypeFinal.split(",");
        } else {
            fieldList = headerStr;
            colHeader = URLDecoder.decode(titleStr);
            width = widthStr;
            align = alignStr;
            xtype = xtypeStr;
            colHeaderArrStr = colHeader.split(",");
            dataIndexArrStr = fieldList.split(",");
            widthArrStr = width.split(",");
            alignArrStr = align.split(",");
            xtypeArrStr = xtype.split(",");
        }

        JSONArray store = null;
        if (obj.isNull("coldata")) {
            store = obj.getJSONArray("data");
        } else {
            store = obj.getJSONArray("coldata");
        }
        addTable(0, colHeaderArrStr.length, 0, store.length(), store, dataIndexArrStr, colHeaderArrStr,
                widthArrStr, alignArrStr, xtypeArrStr, document);

    } catch (DocumentException ex) {
        errorMsg = ex.getMessage();
        throw ServiceException.FAILURE("exportDAOImpl.getPdfData", ex);
    } catch (JSONException e) {
        errorMsg = e.getMessage();
        throw ServiceException.FAILURE("exportDAOImpl.getPdfData", e);
    } catch (Exception e) {
        errorMsg = e.getMessage();
        throw ServiceException.FAILURE("exportDAOImpl.getPdfData", e);
    } finally {
        if (document != null) {
            document.close();
        }
        if (writer != null) {
            writer.close();
        }
    }
    return baos;
}

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

License:Open Source License

public ByteArrayOutputStream getPdfData(JSONObject grid, HttpServletRequest request, JSONObject obj)
        throws ServiceException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer = null;// w  ww .  j a va  2  s . c o  m
    Document document = null;
    try {
        JSONArray gridmap = grid == null ? null : grid.getJSONArray("data");
        String colHeader = "";
        String colHeaderFinal = "";
        String fieldListFinal = "";
        String fieldList = "";
        String width = "";
        String align = "";
        String alignFinal = "";
        String widthFinal = "";
        String colHeaderArrStr[] = null;
        String dataIndexArrStr[] = null;
        String widthArrStr[] = null;
        String alignArrStr[] = null;
        int strLength = 0;
        float totalWidth = 0;

        config = new com.krawler.utils.json.base.JSONObject(request.getParameter("config"));
        document = null;
        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();
            totalWidth = rec.getWidth();
        } 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();
            totalWidth = rec.getWidth();
        }

        writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new EndPage());
        document.open();
        if (config.getBoolean("showLogo")) {
            addComponyLogo(document, request);
        }

        addTitleSubtitle(document);

        if (gridmap != null) {
            int givenTotalWidth = 0;
            for (int i = 0; i < gridmap.length(); i++) {
                JSONObject temp = gridmap.getJSONObject(i);
                givenTotalWidth += Integer.parseInt(temp.getString("width"));
            }
            double widthRatio = 1;
            if (givenTotalWidth > (totalWidth - 40.00)) {
                widthRatio = (totalWidth - 40.00) / givenTotalWidth; // 40.00 is left + right + table margin [15+15+10] margins of documents
            }
            for (int i = 0; i < gridmap.length(); i++) {
                JSONObject temp = gridmap.getJSONObject(i);
                colHeader += StringUtil.serverHTMLStripper(temp.getString("title"));
                if (colHeader.indexOf("*") != -1) {
                    colHeader = colHeader.substring(0, colHeader.indexOf("*") - 1) + ",";
                } else {
                    colHeader += ",";
                }
                fieldList += temp.getString("header") + ",";
                if (!config.getBoolean("landscape")) {
                    int totalWidth1 = (int) ((totalWidth / gridmap.length()) - 5.00);
                    width += "" + totalWidth1 + ","; //resize according to page view[potrait]
                } else {
                    double adjustedWidth = (Integer.parseInt(temp.getString("width")) * widthRatio);
                    width += ((int) Math.floor(adjustedWidth)) + ",";
                }
                if (temp.getString("align").equals("")) {
                    align += "none" + ",";
                } else {
                    align += temp.getString("align") + ",";
                }
            }
            strLength = colHeader.length() - 1;
            colHeaderFinal = colHeader.substring(0, strLength);
            strLength = fieldList.length() - 1;
            fieldListFinal = fieldList.substring(0, strLength);
            strLength = width.length() - 1;
            widthFinal = width.substring(0, strLength);
            strLength = align.length() - 1;
            alignFinal = align.substring(0, strLength);
            colHeaderArrStr = colHeaderFinal.split(",");
            dataIndexArrStr = fieldListFinal.split(",");
            widthArrStr = widthFinal.split(",");
            alignArrStr = alignFinal.split(",");
        } else {
            fieldList = request.getParameter("header");
            colHeader = request.getParameter("title");
            width = request.getParameter("width");
            align = request.getParameter("align");
            colHeaderArrStr = colHeader.split(",");
            dataIndexArrStr = fieldList.split(",");
            widthArrStr = width.split(",");
            alignArrStr = align.split(",");
        }

        JSONArray store = obj.getJSONArray("data");

        if (grid != null && grid.has("groupdata")) {
            JSONObject groupingConfig = grid.getJSONObject("groupdata");
            addGroupableTable(groupingConfig, 0, colHeaderArrStr.length, 0, store.length(), store,
                    dataIndexArrStr, colHeaderArrStr, widthArrStr, alignArrStr, document, request);
        } else {
            addTable(0, colHeaderArrStr.length, 0, store.length(), store, dataIndexArrStr, colHeaderArrStr,
                    widthArrStr, alignArrStr, document, request);
        }

    } catch (Exception e) {
        throw ServiceException.FAILURE("exportMPXDAOImpl.getPdfData", e);
    } finally {
        if (document != null) {
            document.close();
        }
        if (writer != null) {
            writer.close();
        }
    }
    return baos;
}

From source file:com.mycompany.devman.domain.Raport.java

public static void main(String[] args) {

    Document document = new Document(); // Tworzymy dokument

    //* Ustawianie rozmiarw dokumentu
    Rectangle rect = new Rectangle(PageSize.A4); //Tworzenie elementu - rozmiaru dokumentu, ktry bdzie kwadratem o rozmiarze 210mm x 297mm - format a4
    // Utilities.millimetersToPoints(210), Utilities.millimetersToPoints(297)
    document.setPageSize(rect);/*w  w w.  j  av  a 2 s  . c o m*/

    Font[] fonts = { new Font(), new Font(Font.HELVETICA, 14, Font.NORMAL) };

    try { //Blok Try jest po to poniewa nie zawsze moemy mie miejsce tam gdzie chcemy zapisa pdf
        PdfWriter.getInstance(document, new FileOutputStream("raport.pdf"));

        document.open(); //Otwarcie dokumentu - teraz moemy do niego wsadza co kolwiek chcemy
        Paragraph paragraph = new Paragraph();
        paragraph.add("Raport");
        document.add(paragraph); //dodanie paragrafu do dokumentu
        document.close();
    } catch (Exception e) {
        e.printStackTrace(); // Wywietli error
    }

}

From source file:com.pureinfo.srm.patent.action.PatentPrintPdfAction.java

License:Open Source License

/**
 * @see com.pureinfo.ark.interaction.ActionBase#executeAction()
 *///ww w .j ava2  s . co  m
public ActionForward executeAction() throws PureException {
    int nYear = request.getRequiredInt("year", "");

    Rectangle rectPageSize = new Rectangle(PageSize.A4);
    rectPageSize.setBackgroundColor(Color.WHITE);
    rectPageSize.setBorderColor(Color.BLACK);
    rectPageSize = rectPageSize.rotate();
    Document doc = new Document(rectPageSize, 10, 10, 10, 10);
    doc.addTitle(nYear + "");
    doc.addAuthor("PureInfo");
    try {
        BaseFont bfontTitle = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font fontTitle = new Font(bfontTitle, 18, Font.NORMAL);
        Paragraph paraTitle = new Paragraph(nYear + "",
                fontTitle);
        paraTitle.setAlignment(ElementTags.ALIGN_CENTER);

        BaseFont bfontContent = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font fontContent = new Font(bfontContent, 10, Font.NORMAL);

        FileFactory fileFactory = FileFactory.getInstance();
        String sPath = fileFactory.lookupPathConfigByFlag(FileFactory.FLAG_DOWNLOADTEMP, true).getLocalPath();

        FileUtil.insurePathExists(sPath);
        PdfWriter.getInstance(doc, new FileOutputStream(new File(sPath, "patent.pdf")));

        doc.open();
        doc.add(paraTitle);
        doc.add(new Paragraph("   "));

        String[] arrTitles = new String[] { "", "", "", "", "", "",
                "", "", "" };
        PdfPTable pTable = new PdfPTable(arrTitles.length);
        pTable.setWidths(new int[] { 5, 10, 9, 9, 20, 15, 12, 10, 10 });

        for (int i = 0; i < arrTitles.length; i++) {
            PdfPCell pCell = new PdfPCell();
            Paragraph para = new Paragraph(arrTitles[i], fontContent);
            para.setAlignment(ElementTags.ALIGN_CENTER);

            pCell.addElement(para);
            pTable.addCell(pCell);
        }

        /**
         * 
         */
        IPatentMgr mgr = (IPatentMgr) ArkContentHelper.getContentMgrOf(Patent.class);
        List patents = mgr.findAllAuthorizedOf(nYear);
        int i = 0;
        for (Iterator iter = patents.iterator(); iter.hasNext(); i++) {
            Patent patent = (Patent) iter.next();
            this.addPatentCell(pTable, String.valueOf(i + 1), fontContent);
            this.addPatentCell(pTable, patent.getPatentSid(), fontContent);
            this.addPatentCell(pTable, ForceConstants.DATE_FORMAT.format(patent.getApplyDate()), fontContent);
            this.addPatentCell(pTable, patent.getWarrantDate() == null ? ""
                    : ForceConstants.DATE_FORMAT.format(patent.getWarrantDate()), fontContent);
            this.addPatentCell(pTable, patent.getName(), fontContent);
            this.addPatentCell(pTable, patent.getAllAuthosName(), fontContent);
            this.addPatentCell(pTable, patent.getRightPerson(), fontContent);
            this.addPatentCell(pTable, getCollegeName(patent), fontContent);
            this.addPatentCell(pTable, patent.getPatentTypeName(), fontContent);
        }

        doc.add(pTable);
        doc.close();

    } catch (DocumentException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace(System.err);
    } catch (IOException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace(System.err);
    }

    List list = new ArrayList();
    list.add(new Pair("/download/patent.pdf", ""));
    request.setAttribute("forward", list);
    return mapping.findForward("success");
}

From source file:com.teag.reports.CashFlows.java

private void page1() {
    CashFlowTable cft = new CashFlowTable();
    ClientBean cb = new ClientBean();
    CFRow row;//from  w  w w.jav a 2 s .c o m
    CFRow continueRow = null;
    float tallest = 0;

    cb.setPrimaryId(clientID);

    cft.setCb(cb);
    cft.init();
    cft.genTable();

    cft.reset();
    int colCount = MAX_ROWS;

    drawHeader(userInfo.getClientHeading(), "");
    Rectangle agt = placeHeading();

    float baseWidths[] = this.initWidths(colCount - 1);
    float widths[] = this.calcWidths(baseWidths, 11.f * 72);

    Rectangle rct = new Rectangle(prctFull);
    rct.setLeft(_1_4TH);
    rct.setRight(rct.getLeft() + 756);

    Rectangle r = doRow(leList(), widths, agt, 17);
    rct.setTop(r.getBottom());
    r = doRow(agesList(), widths, rct, 17);

    rct.setTop(r.getBottom());

    r = doRow(fiscalYearList(), widths, rct, 17);
    rct.setTop(r.getBottom());

    tallest = tallest < r.getHeight() ? r.getHeight() : tallest;

    while ((row = cft.getRow()) != null) {
        boolean flag;
        if (row.getColNumber() == 0 && row.getIndentLevel() == 0) {
            continueRow = row;
        }

        do {
            flag = false;
            boolean nPage = false;
            String pdfRow[] = buildRow(row, colCount);
            if (row.getHeader().startsWith("III.") && !row.getHeader().endsWith("(cont.)")) {
                nPage = true;
            }
            if (row.getHeader().startsWith("IV.") && !row.getHeader().endsWith("(cont.)")) {
                nPage = true;
            }

            // Rectangle r = doSimpleRow(pdfRow, rct);
            if (nPage) {
                // need to span to a new page
                newPage();
                drawHeader(client, "");
                agt = placeHeading();
                rct.setLeft(_1_4TH);
                rct.setRight(rct.getLeft() + 756);

                r = doRow(leList(), widths, agt, 17);
                rct.setTop(r.getBottom());
                r = doRow(agesList(), widths, rct, 17);
                rct.setTop(r.getBottom());
                r = doRow(fiscalYearList(), widths, rct, 17);
                rct.setTop(r.getBottom());
                tallest = tallest < r.getHeight() ? r.getHeight() : tallest;
                if (continueRow != null) {
                    if (!row.equals(continueRow)) {
                        row = continueRow;
                        row.setHeader(row.getHeader() + " (cont.)");
                        flag = true;

                    }
                }
                nPage = false;
            }

            r = this.doRow(pdfRow, widths, rct, colCount - 1);
            tallest = tallest < r.getHeight() ? r.getHeight() : tallest;
            rct.setTop(r.getBottom());

            if (rct.getTop() < (.5f * 72) + tallest) {
                // need to span to a new page
                newPage();
                drawHeader(client, "");
                agt = placeHeading();

                rct.setLeft(_1_4TH);
                rct.setRight(rct.getLeft() + 756);

                r = doRow(leList(), widths, agt, 17);
                rct.setTop(r.getBottom());
                r = doRow(agesList(), widths, rct, 17);
                rct.setTop(r.getBottom());
                r = doRow(fiscalYearList(), widths, rct, 17);
                rct.setTop(r.getBottom());
                tallest = tallest < r.getHeight() ? r.getHeight() : tallest;

                if (continueRow != null) {
                    if (!row.equals(continueRow)) {
                        row = continueRow;
                        row.setHeader(row.getHeader() + " (cont.)");
                        flag = true;
                    }
                }
            }
        } while (flag == true);
    }
    cft.cleanUp();
}

From source file:com.teag.reports.CashFlows.java

private Rectangle placeHeading() {

    String header = "Estimate Of Net Worth & Estate Distribution - Scenario #1 As Is (in 000's)";
    BaseFont font = PageUtils.LoadFont("GARA.TTF");

    Rectangle rect = new Rectangle(document.getPageSize());
    rect.setBottom(rect.getTop() - (72 * .6f));
    HeadingText ht = new HeadingText(this.writer);
    rect.setBottom(rect.getBottom() - (72 * .33f));
    ht.setColor(57, 57, 57);//from  w  w  w  .j  av a2  s .c  o m
    ht.setCapsColor(98, 98, 98);
    ht.display(rect, 12f, font, 3f, header, HeadingText.DHT_CENTER);
    rect.setTop(rect.getBottom() - _1_8TH);
    rect.setBottom(prctFull.getBottom());
    rect.setLeft(_1_2TH);
    rect.setRight(rect.getLeft() + 11.f * 72);
    PageBorder pb = new PageBorder(writer);
    pb.setLicense(userInfo.getPlannerFirstName() + " " + userInfo.getPlannerLastName());
    pb.drawNoBorder(document, Integer.toString(pageNum));
    drawLifeExp();
    return (rect);
}