List of usage examples for com.lowagie.text.pdf PdfPCell PdfPCell
public PdfPCell(PdfPCell cell)
PdfPCell
. From source file:org.mapfish.print.PDFUtils.java
License:Open Source License
/** * Create a PDF table cell with support for styling using the {@link org.mapfish.print.config.layout.CellConfig} stuff. *//*from w w w . j av a 2 s. c o m*/ public static PdfPCell createCell(final PJsonObject params, final RenderingContext context, final Block block, final int row, final int col, final int nbRows, final int nbCols, final TableConfig tableConfig) throws DocumentException { final PdfPCell[] cell = new PdfPCell[1]; block.render(params, new Block.PdfElement() { public void add(Element element) throws DocumentException { if (element instanceof PdfPTable) { cell[0] = new PdfPCell((PdfPTable) element); } else { final Phrase phrase = new Phrase(); phrase.add(element); cell[0] = new PdfPCell(phrase); } cell[0].setBorder(PdfPCell.NO_BORDER); cell[0].setPadding(0); if (tableConfig != null) { tableConfig.apply(cell[0], row, col, nbRows, nbCols, context, params); } if (block.getAlign() != null) { cell[0].setHorizontalAlignment(block.getAlign().getCode()); } if (block.getVertAlign() != null) { cell[0].setVerticalAlignment(block.getVertAlign().getCode()); } if (!(block instanceof MapBlock) && !(block instanceof ScalebarBlock) && block.getBackgroundColorVal(context, params) != null) { cell[0].setBackgroundColor(block.getBackgroundColorVal(context, params)); } } }, context); return cell[0]; }
From source file:org.openswing.swing.export.java.ExportToPDF14.java
License:Open Source License
private void processComponent(PdfPTable table, int parentTableCols, Document document, ExportOptions opt, Object obj) throws Throwable { if (obj != null) { GridExportCallbacks callbacks = null; if (obj instanceof GridExportOptions) { callbacks = (GridExportCallbacks) ((GridExportOptions) obj).getCallbacks(); if (callbacks != null) processComponent(table, parentTableCols, document, opt, callbacks.getHeaderComponent()); prepareGrid(table, parentTableCols, document, opt, (GridExportOptions) obj); if (callbacks != null) processComponent(table, parentTableCols, document, opt, callbacks.getFooterComponent()); } else if (obj instanceof ComponentExportOptions) prepareGenericComponent(table, parentTableCols, document, opt, (ComponentExportOptions) obj); else//from ww w . j a v a 2 s.co m return; if (table != null) { PdfPCell cell = new PdfPCell(new Paragraph("\n")); cell.setColspan(parentTableCols); table.addCell(cell); } else document.add(new Paragraph("\n")); } }
From source file:org.openswing.swing.export.java.ExportToPDF14.java
License:Open Source License
private void prepareGenericComponent(PdfPTable parentTable, int parentTableCols, Document document, ExportOptions exportOptions, ComponentExportOptions opt) throws Throwable { if (opt.getCellsContent() == null || opt.getCellsContent().length == 0) return;/* ww w . j ava2s . co m*/ int cols = opt.getCellsContent()[0].length; Object[] row = null; Object obj = null; SimpleDateFormat sdatf = new SimpleDateFormat(exportOptions.getDateTimeFormat()); int[] headerwidths = new int[cols]; for (int i = 0; i < headerwidths.length; i++) headerwidths[i] = (int) PageSize.A4.width() / cols; PdfPTable table = new PdfPTable(cols); table.setWidths(headerwidths); table.setWidthPercentage(90); table.getDefaultCell().setBorderWidth(2); table.getDefaultCell().setBorderColor(Color.black); table.getDefaultCell().setGrayFill(exportOptions.getExportToPDFAdapter().getHeaderGrayFill()); table.getDefaultCell().setPadding(3); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.setHeaderRows(0); table.getDefaultCell().setBorderWidth(0); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP); for (int i = 0; i < opt.getCellsContent().length; i++) { row = opt.getCellsContent()[i]; for (int j = 0; j < row.length; j++) { obj = row[j]; if (obj != null) { if (obj instanceof Date || obj instanceof java.util.Date || obj instanceof java.sql.Timestamp) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(new Phrase(sdatf.format((java.util.Date) obj), (Font) exportOptions.getExportToPDFAdapter().getGenericComponentFont(i, j, obj))); } else { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(new Phrase(obj.toString(), (Font) exportOptions.getExportToPDFAdapter().getGenericComponentFont(i, j, obj))); } } else { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(new Phrase("", (Font) exportOptions.getExportToPDFAdapter().getGenericComponentFont(i, j, null))); } } } if (parentTable != null) { PdfPCell cell = new PdfPCell(table); cell.setColspan(parentTableCols); parentTable.addCell(cell); } else document.add(table); }
From source file:org.openswing.swing.export.java.ExportToPDF14.java
License:Open Source License
private void prepareGrid(PdfPTable parentTable, int parentTableCols, Document document, ExportOptions exportOptions, GridExportOptions opt) throws Throwable { // prepare vo getters methods... String methodName = null;/*from w w w . ja va 2s.co m*/ String attributeName = null; Hashtable gettersMethods = new Hashtable(); Method[] voMethods = opt.getValueObjectType().getMethods(); for (int i = 0; i < voMethods.length; i++) { methodName = voMethods[i].getName(); if (methodName.startsWith("get")) { attributeName = methodName.substring(3, 4).toLowerCase() + methodName.substring(4); if (opt.getExportAttrColumns().contains(attributeName)) gettersMethods.put(attributeName, voMethods[i]); } } Response response = null; int start = 0; int rownum = 0; Object value = null; Object vo = null; int type; SimpleDateFormat sdf = new SimpleDateFormat(exportOptions.getDateFormat()); SimpleDateFormat sdatf = new SimpleDateFormat(exportOptions.getDateTimeFormat()); SimpleDateFormat stf = new SimpleDateFormat(exportOptions.getTimeFormat()); int headerwidths[] = new int[opt.getExportColumns().size()]; int total = 0; for (int i = 0; i < opt.getExportColumns().size(); i++) { headerwidths[i] = Math.max(opt.getExportColumns().get(i).toString().length() * 10, ((Integer) opt.getColumnsWidth().get(opt.getExportAttrColumns().get(i))).intValue()); total += headerwidths[i]; } Paragraph line = null; if (opt.getTitle() != null && !opt.getTitle().equals("")) { line = new Paragraph(opt.getTitle(), (Font) exportOptions.getExportToPDFAdapter().getFontTitle()); line.setAlignment(Element.ALIGN_CENTER); document.add(line); document.add(new Paragraph("\n")); } String[] filters = opt.getFilteringConditions(); if (filters != null) { for (int i = 0; i < filters.length; i++) { line = new Paragraph(filters[i]); document.add(line); } document.add(new Paragraph("\n")); } PdfPTable table = new PdfPTable(opt.getExportColumns().size()); table.setWidths(headerwidths); table.setWidthPercentage(90); table.getDefaultCell().setBorderWidth(2); table.getDefaultCell().setBorderColor(Color.black); table.getDefaultCell().setGrayFill(exportOptions.getExportToPDFAdapter().getHeaderGrayFill()); table.getDefaultCell().setPadding(3); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); for (int i = 0; i < opt.getExportColumns().size(); i++) table.addCell(new Phrase(opt.getExportColumns().get(i).toString(), (Font) exportOptions .getExportToPDFAdapter().getHeaderFont(opt.getExportAttrColumns().get(i).toString()))); table.setHeaderRows(1); table.getDefaultCell().setBorderWidth(1); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP); for (int j = 0; j < opt.getTopRows().size(); j++) { // create a row for each top rows... table.getDefaultCell().setGrayFill(exportOptions.getExportToPDFAdapter().getTopRowsGrayFill(j)); vo = opt.getTopRows().get(j); appendRow(document, exportOptions, table, vo, opt, gettersMethods, sdf, sdatf, stf, j, 0); } do { response = opt.getGridDataLocator().loadData(GridParams.NEXT_BLOCK_ACTION, start, opt.getFilteredColumns(), opt.getCurrentSortedColumns(), opt.getCurrentSortedVersusColumns(), opt.getValueObjectType(), opt.getOtherGridParams()); if (response.isError()) throw new Exception(response.getErrorMessage()); boolean even = false; for (int j = 0; j < ((VOListResponse) response).getRows().size(); j++) { if (even) { table.getDefaultCell().setGrayFill(exportOptions.getExportToPDFAdapter().getEvenRowsGrayFill()); even = false; } else { table.getDefaultCell().setGrayFill(exportOptions.getExportToPDFAdapter().getOddRowsGrayFill()); even = true; } vo = ((VOListResponse) response).getRows().get(j); appendRow(document, exportOptions, table, vo, opt, gettersMethods, sdf, sdatf, stf, rownum, 1); rownum++; } start = start + ((VOListResponse) response).getRows().size(); if (!((VOListResponse) response).isMoreRows()) break; } while (rownum < opt.getMaxRows()); for (int j = 0; j < opt.getBottomRows().size(); j++) { // create a row for each bottom rows... table.getDefaultCell().setGrayFill(exportOptions.getExportToPDFAdapter().getBottomRowsGrayFill(j)); vo = opt.getBottomRows().get(j); appendRow(document, exportOptions, table, vo, opt, gettersMethods, sdf, sdatf, stf, j, 2); } if (parentTable != null) { PdfPCell cell = new PdfPCell(table); cell.setColspan(parentTableCols); parentTable.addCell(cell); } else document.add(table); }
From source file:org.openswing.swing.export.java.ExportToPDF15.java
License:Open Source License
private void prepareGenericComponent(PdfPTable parentTable, int parentTableCols, Document document, ExportOptions exportOptions, ComponentExportOptions opt) throws Throwable { if (opt.getCellsContent() == null || opt.getCellsContent().length == 0) return;/*from w w w .j a v a 2 s .c om*/ int cols = opt.getCellsContent()[0].length; Object[] row = null; Object obj = null; SimpleDateFormat sdatf = new SimpleDateFormat(exportOptions.getDateTimeFormat()); int[] headerwidths = new int[cols]; for (int i = 0; i < headerwidths.length; i++) headerwidths[i] = (int) PageSize.A4.getWidth() / cols; PdfPTable table = new PdfPTable(cols); table.setWidths(headerwidths); table.setWidthPercentage(90); table.getDefaultCell().setBorderWidth(2); table.getDefaultCell().setBorderColor(Color.black); table.getDefaultCell().setGrayFill(exportOptions.getExportToPDFAdapter().getHeaderGrayFill()); table.getDefaultCell().setPadding(3); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.setHeaderRows(0); table.getDefaultCell().setBorderWidth(0); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP); for (int i = 0; i < opt.getCellsContent().length; i++) { row = opt.getCellsContent()[i]; for (int j = 0; j < row.length; j++) { obj = row[j]; if (obj != null) { if (obj instanceof Date || obj instanceof java.util.Date || obj instanceof java.sql.Timestamp) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(new Phrase(sdatf.format((java.util.Date) obj), (Font) exportOptions.getExportToPDFAdapter().getGenericComponentFont(i, j, obj))); } else { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(new Phrase(obj.toString(), (Font) exportOptions.getExportToPDFAdapter().getGenericComponentFont(i, j, obj))); } } else { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(new Phrase("", (Font) exportOptions.getExportToPDFAdapter().getGenericComponentFont(i, j, null))); } } } if (parentTable != null) { PdfPCell cell = new PdfPCell(table); cell.setColspan(parentTableCols); parentTable.addCell(cell); } else document.add(table); }
From source file:org.opentestsystem.delivery.testreg.rest.view.PDFReportView.java
License:Open Source License
private PdfPTable addEmptyCell(final PdfPTable table) { final PdfPCell cell = new PdfPCell(new Paragraph(" No Data Found", HEADER_MESSAGE_FONT)); cell.setColspan(table.getNumberOfColumns()); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell);/* w w w. j a va2s . c om*/ return table; }
From source file:org.opentestsystem.delivery.testreg.rest.view.PDFReportView.java
License:Open Source License
private PdfPTable createMessageHeaders(final String[] headerColumns, final HierarchyLevel level, final String message) throws BadElementException { PdfPTable table = null;/* w w w . j a v a 2 s.c o m*/ if (level != null && level == HierarchyLevel.CLIENT) { table = new PdfPTable(headerColumns.length - 3); } else { table = new PdfPTable(headerColumns.length); } table.setWidthPercentage(100); PdfPCell cell; cell = new PdfPCell(new Paragraph(message, HEADER_MESSAGE_FONT)); cell.setColspan(headerColumns.length); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); return table; }
From source file:org.opentestsystem.delivery.testreg.rest.view.PDFReportView.java
License:Open Source License
private PdfPTable createHeaders(final String[] headerColumns, final PdfPTable table) throws BadElementException { PdfPCell cell;/*from ww w . j av a2 s .co m*/ for (final String header : headerColumns) { cell = new PdfPCell(new Paragraph(header, HEADER_FONT)); cell.setBackgroundColor(Color.GRAY); table.addCell(cell); } return table; }
From source file:org.opentestsystem.delivery.testreg.rest.view.PDFReportView.java
License:Open Source License
private PdfPTable createSummaryHeaders(final String[] headerColumns, final HierarchyLevel level, final PdfPTable table) throws BadElementException { PdfPCell cell;//w ww. ja v a 2 s . com int columnIndex = 0; Map<String, String> crosswalkMap = null; if (level != HierarchyLevel.CLIENT) { crosswalkMap = this.entityCrosswalkService.getFormatType(FormatType.valueOf(level.name())); } for (String header : headerColumns) { columnIndex++; if (level != null && level == HierarchyLevel.CLIENT) { if (columnIndex == 4 || columnIndex == 5 || columnIndex == 6) { continue; } } else { if (columnIndex == 7 || columnIndex == 8) { if (crosswalkMap.get(header) != null) { header = crosswalkMap.get(header); } } } cell = new PdfPCell(new Paragraph(header, HEADER_FONT)); cell.setBackgroundColor(Color.GRAY); table.addCell(cell); } return table; }
From source file:org.opentestsystem.delivery.testreg.rest.view.PDFReportView.java
License:Open Source License
private PdfPTable addData(final PdfPTable table, final List<TestAdminReport> dataSummary, final HierarchyLevel level) throws BadElementException { PdfPCell cell;//from w w w .j a v a2 s .com int count = 1; for (final TestAdminReport dataRow : dataSummary) { cell = new PdfPCell(new Paragraph(count + "", DATA_FONT)); table.addCell(cell); int index = 1; for (final String columnData : dataRow.toStringArray()) { if (level != null && level == HierarchyLevel.CLIENT) { index = index + 1; if (index == 3 || index == 4 || index == 5) { continue; } } cell = new PdfPCell(new Paragraph(columnData, DATA_FONT)); table.addCell(cell); } count++; } return table; }