List of usage examples for com.lowagie.text.pdf PdfPCell setHorizontalAlignment
public void setHorizontalAlignment(int horizontalAlignment)
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);//from ww w . java 2s . c o m cell.setPadding(padd); return cell; }
From source file:com.krawler.spring.exportFuctionality.ExportRecord.java
License:Open Source License
private PdfPTable addCompanyLogo(String logoPath, Company com) { PdfPTable tab1 = new PdfPTable(1); imgPath = logoPath;// ww w. jav a 2 s. co m PdfPCell imgCell = null; try { Image img = Image.getInstance(imgPath); imgCell = new PdfPCell(img); } catch (Exception e) { imgCell = new PdfPCell(new Paragraph(com.getCompanyName(), fontSmallRegular)); } imgCell.setHorizontalAlignment(Element.ALIGN_LEFT); imgCell.setBorder(0); tab1.addCell(imgCell); return tab1; }
From source file:com.krawler.spring.exportFuctionality.ExportRecord.java
License:Open Source License
private PdfPTable addCompanyLogo(String logoPath, String comName) { PdfPTable tab1 = new PdfPTable(1); imgPath = logoPath;//from w ww.j a v a2s . c o m PdfPCell imgCell = null; try { Image img = Image.getInstance(imgPath); imgCell = new PdfPCell(img); } catch (Exception e) { imgCell = new PdfPCell(new Paragraph(comName, fontSmallRegular)); } imgCell.setHorizontalAlignment(Element.ALIGN_LEFT); imgCell.setBorder(0); tab1.addCell(imgCell); return tab1; }
From source file:com.krawler.spring.exportFuctionality.ExportRecord.java
License:Open Source License
private void addHeaderFooter(Document document, PdfWriter writer) throws DocumentException, ServiceException { PdfPTable footer = new PdfPTable(1); PdfPCell footerSeparator = new PdfPCell(new Paragraph("THANK YOU FOR YOUR BUSINESS!", fontTblMediumBold)); footerSeparator.setHorizontalAlignment(Element.ALIGN_CENTER); footerSeparator.setBorder(0);//from w w w. j a v a2 s . c om footer.addCell(footerSeparator); try { Rectangle page = document.getPageSize(); footer.setTotalWidth(page.getWidth() - document.leftMargin()); footer.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(), writer.getDirectContent()); } catch (Exception e) { throw new ExceptionConverter(e); } }
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 va 2s .c o 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.exportFuctionality.ExportRecord.java
License:Open Source License
private PdfPTable addBlankLine(int count) { PdfPTable table = new PdfPTable(1); PdfPCell cell = null; for (int i = 0; i < count; i++) { cell = new PdfPCell(new Paragraph("", fontTblMediumBold)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(3);//from w ww .ja va2 s .co m cell.setBorder(0); table.addCell(cell); } return table; }
From source file:com.krawler.spring.exportFunctionality.exportDAOImpl.java
License:Open Source License
public void addComponyLogo(Document d, HttpServletRequest request) throws ServiceException { try {// w ww . j a va 2s . 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 {/*w w w . jav a2s .c o m*/ 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 {// w w w .j ava 2 s . co 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
public void getHeaderFooter(Document document) throws ServiceException { try {//from ww w .jav a 2 s. c o m java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16)); java.util.Date dt = new java.util.Date(); String date = "yyyy-MM-dd"; java.text.SimpleDateFormat dtf = new java.text.SimpleDateFormat(date); dtf.setTimeZone(TimeZone.getTimeZone("GMT" + this.tdiff)); String DateStr = dtf.format(dt); // -------- header ---------------- header = new PdfPTable(3); header.setWidthPercentage(100); header.setWidths(new float[] { 20, 60, 20 }); String HeadDate = ""; if (config.getBoolean("headDate")) { HeadDate = DateStr; } PdfPCell headerDateCell = new PdfPCell( fontFamilySelector.process(HeadDate, FontContext.SMALL_TEXT, tColor));//fontSmallRegular)); headerDateCell.setBorder(0); headerDateCell.setPaddingBottom(4); headerDateCell.setHorizontalAlignment(PdfCell.ALIGN_LEFT); header.addCell(headerDateCell); PdfPCell headerNotecell = new PdfPCell( fontFamilySelector.process(config.getString("headNote"), FontContext.HEADER_NOTE, tColor)); headerNotecell.setBorder(0); headerNotecell.setPaddingBottom(4); headerNotecell.setHorizontalAlignment(PdfCell.ALIGN_CENTER); header.addCell(headerNotecell); String HeadPager = ""; if (config.getBoolean("headPager")) { HeadPager = String.valueOf(document.getPageNumber());//current page no } PdfPCell headerPageNocell = new PdfPCell( fontFamilySelector.process(HeadPager, FontContext.HEADER_NOTE, tColor));// fontSmallRegular)); headerPageNocell.setBorder(0); headerPageNocell.setPaddingBottom(4); headerPageNocell.setHorizontalAlignment(PdfCell.ALIGN_RIGHT); header.addCell(headerPageNocell); PdfPCell headerSeparator = new PdfPCell(new Phrase("")); headerSeparator.setBorder(PdfPCell.BOX); headerSeparator.setPadding(0); headerSeparator.setColspan(3); header.addCell(headerSeparator); // -------- header end ---------------- // -------- footer ------------------- footer = new PdfPTable(3); PdfPCell footerSeparator = new PdfPCell(new Phrase("")); footerSeparator.setBorder(PdfPCell.BOX); footerSeparator.setPadding(0); footerSeparator.setColspan(3); footer.addCell(footerSeparator); footer.setWidthPercentage(100); footer.setWidths(new float[] { 20, 60, 20 }); String PageDate = ""; if (config.getBoolean("footDate")) { PageDate = DateStr; } PdfPCell pagerDateCell = new PdfPCell( fontFamilySelector.process(PageDate, FontContext.SMALL_TEXT, tColor));//fontSmallRegular)); pagerDateCell.setBorder(0); pagerDateCell.setHorizontalAlignment(PdfCell.ALIGN_LEFT); footer.addCell(pagerDateCell); PdfPCell footerNotecell = new PdfPCell( fontFamilySelector.process(config.getString("footNote"), FontContext.FOOTER_NOTE, tColor));// fontSmallRegular)); footerNotecell.setBorder(0); footerNotecell.setHorizontalAlignment(PdfCell.ALIGN_CENTER); footer.addCell(footerNotecell); String FootPager = ""; if (config.getBoolean("footPager")) { FootPager = String.valueOf(document.getPageNumber());//current page no } PdfPCell footerPageNocell = new PdfPCell( fontFamilySelector.process(FootPager, FontContext.SMALL_TEXT, tColor));// fontSmallRegular)); footerPageNocell.setBorder(0); footerPageNocell.setHorizontalAlignment(PdfCell.ALIGN_RIGHT); footer.addCell(footerPageNocell); // -------- footer end ----------- } catch (Exception e) { throw ServiceException.FAILURE("exportDAOImpl.getHeaderFooter", e); } }