List of usage examples for com.lowagie.text Paragraph Paragraph
public Paragraph(Phrase phrase)
Paragraph
with a certain Phrase
. From source file:com.krawler.esp.handlers.PdfGenHandler.java
License:Open Source License
public static PdfPTable addspace(int space, PdfPTable tb) { for (int i = 0; i < space; i++) { PdfPCell cell = new PdfPCell(new Paragraph("")); cell.setBorder(0);/*w w w. j a v a 2 s. c om*/ tb.addCell(cell); } return tb; }
From source file:com.krawler.esp.servlets.ExportPDFServlet.java
License:Open Source License
private int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2, String[] colIndex1, Document document) { float[] f = new float[(stpcol - stcol)]; for (int k = 0; k < f.length; k++) f[k] = 20;// www . j ava 2 s. c o m PdfPTable table = new PdfPTable(f); PdfPCell cell = new PdfPCell(new Paragraph("Agenda Details")); cell.setColspan(6); table.addCell(cell); Font font = FontFactory.getFont("Helvetica", 8, Font.BOLD, Color.BLACK); Font font1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, Color.BLACK); Font f1; int stpcol1 = 0; for (int hcol = stcol; hcol < stpcol; hcol++) { PdfPCell h1 = new PdfPCell(new Paragraph(colwidth2[hcol], font)); // new // Paragraph(colwidth2[hcol],font); table.addCell(h1); } table.setHeaderRows(1); try { for (int row = strow; row < stprow; row++) { if (row % 62 == 61) { document.add(table); table.deleteBodyRows(); table.setSkipFirstHeader(true); } f1 = font1; for (int col = stcol; col < stpcol; col++) { table.addCell(new Paragraph(store.getJSONObject(row).getString(colIndex1[col]), f1)); } } document.newPage(); document.add(table); if (stpcol != colIndex1.length) { if ((colIndex1.length - stpcol) > 5) // column limit stpcol1 = stpcol + 5; else stpcol1 = (colIndex1.length - stpcol) + stpcol; addTable(stpcol, stpcol1, strow, stprow, store, colwidth2, colIndex1, document); } } catch (Exception e) { e.toString(); } return stpcol; }
From source file:com.krawler.esp.servlets.ExportProjectReportServlet.java
License:Open Source License
private ByteArrayOutputStream exportToPdfTimeline(HttpServletRequest request, String as) throws ServiceException { JSONObject s = null;/*from ww w.jav a 2 s .c om*/ ByteArrayOutputStream os = new ByteArrayOutputStream(); try { config = new com.krawler.utils.json.base.JSONObject(request.getParameter("config")); s = new JSONObject(as); JSONArray head = s.getJSONArray("columnheader"); JSONArray store = s.getJSONArray("data"); String[] colwidth2 = new String[head.length() + 3]; String[] colnm = { "info", "level", "flag" }; for (int i = 0; i < colwidth2.length; i++) { if (i < 3) colwidth2[i] = colnm[i]; else { if (head.getJSONObject(i - 3).has("0")) colwidth2[i] = head.getJSONObject(i - 3).getString("0"); else colwidth2[i] = head.getJSONObject(i - 3).getString("1"); } } int maxlevel = 0; for (int k = 0; k < store.length(); k++) { for (int j = 0; j < colwidth2.length; j++) { if (!store.getJSONObject(k).has(colwidth2[j])) store.getJSONObject(k).put(colwidth2[j], ""); } if (store.getJSONObject(k).getInt("level") > maxlevel) maxlevel = store.getJSONObject(k).getInt("level"); } int len = colwidth2.length - 3; int p = 0; if (len <= 5) p = colwidth2.length; else p = 8; Rectangle recPage = new Rectangle(PageSize.A4); recPage.setBackgroundColor(new java.awt.Color(Integer.parseInt(config.getString("bgColor"), 16))); Document document = null; if (config.getBoolean("landscape")) document = new Document(recPage.rotate(), 15, 15, 30, 30); else document = new Document(recPage, 15, 15, 30, 30); PdfWriter writer = PdfWriter.getInstance(document, os); writer.setPageEvent(new EndPage()); document.open(); if (config.getBoolean("showLogo")) { getCompanyDetails(request); addComponyLogo(document, request); } addTitleSubtitle(document); document.add(new Paragraph("\u00a0")); addTableTimeLine(3, p, 0, store.length(), store, colwidth2, maxlevel, document); document.close(); writer.close(); os.close(); } catch (ConfigurationException ex) { throw ServiceException.FAILURE("ExportProjectReport.exportToPdfTimeline", ex); } catch (IOException ex) { throw ServiceException.FAILURE("ExportProjectReport.exportToPdfTimeline", ex); } catch (DocumentException ex) { throw ServiceException.FAILURE("ExportProjectReport.exportToPdfTimeline", ex); } catch (JSONException e) { throw ServiceException.FAILURE("ExportProjectReport.exportToPdfTimeline", e); } return os; }
From source file:com.krawler.esp.servlets.ExportReportServlet.java
License:Open Source License
private ByteArrayOutputStream exportToPdf(Connection conn, HttpServletRequest request, String as) { JSONObject s = null;// w w w .j av a 2 s .c o m ByteArrayOutputStream os = new ByteArrayOutputStream(); try { s = new JSONObject(as); JSONArray head = s.getJSONArray("columnheader"); JSONArray store = s.getJSONArray("data"); String[] colwidth2 = new String[head.length() + 3]; String[] colnm = { "info", "level", "flag" }; for (int i = 0; i < colwidth2.length; i++) { if (i < 3) colwidth2[i] = colnm[i]; else { if (head.getJSONObject(i - 3).has("0")) colwidth2[i] = head.getJSONObject(i - 3).getString("0"); else colwidth2[i] = head.getJSONObject(i - 3).getString("1"); } } int maxlevel = 0; for (int k = 0; k < store.length(); k++) { for (int j = 0; j < colwidth2.length; j++) { if (!store.getJSONObject(k).has(colwidth2[j])) store.getJSONObject(k).put(colwidth2[j], ""); } if (store.getJSONObject(k).getInt("level") > maxlevel) maxlevel = store.getJSONObject(k).getInt("level"); } int len = colwidth2.length - 3; int p = 0; if (len <= 5) p = colwidth2.length; else p = 8; Document document = new Document(PageSize.A4, 15, 15, 15, 15); PdfWriter writer = PdfWriter.getInstance(document, os); writer.setPageEvent(new EndPage()); getCompanyDetails(conn, request); getPageCount(3, p, 0, store.length(), store, colwidth2, maxlevel, document); prepare(document, FILTER_CENTER); document.add(new Paragraph("\u00a0")); addTable(3, p, 0, store.length(), store, colwidth2, maxlevel, document); document.close(); writer.close(); os.close(); } catch (IOException ex) { Logger.getLogger(ExportReportServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(ExportReportServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (JSONException e) { } return os; }
From source file:com.krawler.spring.exportFuctionality.ExportRecord.java
License:Open Source License
private PdfPCell createBalanceSheetCell(String string, FontContext context, int ALIGN_RIGHT, int i, int paddLeft, int paddRight) { PdfPCell cell = new PdfPCell(new Paragraph(fontFamilySelector.process(string, context))); cell.setHorizontalAlignment(ALIGN_RIGHT); cell.setBorder(i);//from w w w . j a v a2 s. c om cell.setPaddingLeft(paddLeft); if (paddRight != 0) { cell.setPaddingRight(paddRight); } return cell; }
From source file:com.krawler.spring.exportFuctionality.ExportRecord.java
License:Open Source License
private PdfPCell createCell(String string, FontContext context, int ALIGN_RIGHT, int i, int padd) { PdfPCell cell = new PdfPCell(new Paragraph(fontFamilySelector.process(string, context))); cell.setHorizontalAlignment(ALIGN_RIGHT); cell.setBorder(i);// w w w . j a v a 2s.c om cell.setPadding(padd); return cell; }
From source file:com.krawler.spring.exportFunctionality.exportDAOImpl.java
License:Open Source License
public void addComponyLogo(Document d, HttpServletRequest request) throws ServiceException { try {/*from w w w. j a va 2 s . co m*/ 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 . jav a2 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 int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2, String[] colHeader, String[] widths, String[] align, String[] xtype, Document document) throws ServiceException { try {//from w ww .j a va 2 s. c o m java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16)); PdfPTable table; float[] tcol; tcol = new float[colHeader.length + 1]; tcol[0] = 40; for (int i = 1; i < colHeader.length + 1; i++) { tcol[i] = Float.parseFloat(widths[i - 1]); } table = new PdfPTable(colHeader.length + 1); table.setWidthPercentage(tcol, document.getPageSize()); table.setSpacingBefore(15); PdfPCell h2 = new PdfPCell( new Paragraph(fontFamilySelector.process("No.", FontContext.TABLE_HEADER, tColor))); if (config.getBoolean("gridBorder")) { h2.setBorder(PdfPCell.BOX); } else { h2.setBorder(0); } h2.setPadding(4); h2.setBorderColor(Color.GRAY); h2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(h2); PdfPCell h1 = null; for (int hcol = stcol; hcol < colwidth2.length; hcol++) { h1 = new PdfPCell(new Paragraph( fontFamilySelector.process(colHeader[hcol], FontContext.TABLE_HEADER, tColor))); h1.setHorizontalAlignment(Element.ALIGN_CENTER); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOX); } else { h1.setBorder(0); } h1.setBorderColor(Color.GRAY); h1.setPadding(4); table.addCell(h1); } table.setHeaderRows(1); for (int row = strow; row < stprow; row++) { h2 = new PdfPCell(new Paragraph( fontFamilySelector.process(String.valueOf(row + 1), FontContext.TABLE_DATA, tColor))); if (config.getBoolean("gridBorder")) { h2.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h2.setBorder(0); } h2.setPadding(4); h2.setBorderColor(Color.GRAY); h2.setHorizontalAlignment(Element.ALIGN_CENTER); h2.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(h2); JSONObject temp = store.getJSONObject(row); for (int col = 0; col < colwidth2.length; col++) { String str = temp.optString((colwidth2[col]), ""); try { if (xtype.length > 0) { str = formatValue(temp.optString((colwidth2[col]), ""), xtype[col]); } } catch (Exception e) { } Paragraph para = new Paragraph(fontFamilySelector.process(str, FontContext.TABLE_DATA, tColor)); h1 = new PdfPCell(para); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h1.setBorder(0); } h1.setPadding(4); h1.setBorderColor(Color.GRAY); if (!align[col].equals("right") && !align[col].equals("left")) { h1.setHorizontalAlignment(Element.ALIGN_CENTER); h1.setVerticalAlignment(Element.ALIGN_CENTER); } else if (align[col].equals("right")) { h1.setHorizontalAlignment(Element.ALIGN_RIGHT); h1.setVerticalAlignment(Element.ALIGN_RIGHT); } else if (align[col].equals("left")) { h1.setHorizontalAlignment(Element.ALIGN_LEFT); h1.setVerticalAlignment(Element.ALIGN_LEFT); } table.addCell(h1); } } document.add(table); document.newPage(); } catch (Exception e) { throw ServiceException.FAILURE("exportDAOImpl.addTable", e); } return stpcol; }
From source file:com.krawler.spring.exportFunctionality.exportDAOImpl.java
License:Open Source License
private PdfPCell calculateDiscount(double disc, KWLCurrency cur) throws SessionExpiredException { PdfPCell cell = null;/* w ww. j a v a 2 s . com*/ if (disc == 0) { cell = new PdfPCell(new Paragraph(fontFamilySelector.process("--", FontContext.NOTE_TEXT))); } else { cell = new PdfPCell(new Paragraph( fontFamilySelector.process(currencyRender(String.valueOf(disc), cur), FontContext.TABLE_DATA))); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(15); cell.setPadding(5); } return cell; }