/** * creates the diagram figure header * * @param document * the document we are reporting into * @param string * the string to show in the figure header */ public void createHeader1(Document document, String string) { try { Table headerTable = ReportUtils.createTable(2, 2, 0, 100); Chunk name = new Chunk(string, header1Font); Cell nameCell = new Cell(name); nameCell.setColspan(2); nameCell.setBorderWidthBottom(1.5f); headerTable.addCell(nameCell); document.add(headerTable); } catch (Exception e) { jUCMNavErrorDialog error = new jUCMNavErrorDialog(e.getMessage()); e.printStackTrace(); } }
/** * Constructs a <CODE>PdfTable</CODE>-object. * * @param table a <CODE>Table</CODE> * @param left the left border on the page * @param right the right border on the page * @param top the start position of the top of the table * @since a parameter of this method has been removed in iText 2.0.8 */ PdfTable(Table table, float left, float right, float top) { // constructs a Rectangle (the bottom value will be changed afterwards) super(left, top, right, top); this.table = table; table.complete(); // copying the attributes from class Table cloneNonPositionParameters(table); this.columns = table.getColumns(); positions = table.getWidths(left, right - left); // initialization of some parameters setLeft(positions[0]); setRight(positions[positions.length - 1]); headercells = new ArrayList(); cells = new ArrayList(); updateRowAdditionsInternal(); }
/** * A very simple Table example. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document, PdfTestBase.getOutputStream("MyFirstTable.pdf")); // step 3: we open the document document.open(); // step 4: we create a table and add it to the document Table table = new Table(2, 2); // 2 rows, 2 columns table.addCell("0.0"); table.addCell("0.1"); table.addCell("1.0"); table.addCell("1.1"); document.add(table); document.add(new Paragraph("converted to PdfPTable:")); table.setConvert2pdfptable(true); document.add(table); // step 5: we close the document document.close(); }
public void createWord() { DruidDataSource dataSource = new DruidDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://localhost:3306/xiu?useUnicode=true&characterEncoding=UTF-8"); dataSource.setUsername("root"); dataSource.setPassword(""); Platform platform = PlatformFactory.createNewPlatformInstance(dataSource); Database model = platform.readModelFromDatabase("xiu"); System.out.println(model.toVerboseString()); System.out.println(Boon.toPrettyJson(model)); org.apache.ddlutils.model.Table dbTable = model.findTable("t_user"); ForeignKey[] fks = dbTable.getForeignKeys(); for (ForeignKey fk : fks) { System.out.println(fk.getName()); System.out.println(fk.getFirstReference().getLocalColumnName()); System.out.println(fk.getForeignTableName()); System.out.println(fk.getFirstReference().getForeignColumnName()); } toWord(model); }
/** * Get the PDF Table containing trip information like trip id, date, and destination * * @returns {@link Table} used for a PDF */ protected Table getTripInfo() throws BadElementException { final Table retval = new Table(3); retval.setWidth(100f); retval.setBorder(NO_BORDER); retval.addCell(getHeaderCell("Trip/Event ID")); final Cell dateHeaderCell = getHeaderCell("Date"); retval.addCell(dateHeaderCell); retval.addCell(getHeaderCell("Destination/Event Name")); retval.endHeaders(); retval.addCell(getBorderlessCell(getTripId())); final Cell dateCell = getBorderlessCell(getDate()); retval.addCell(dateCell); retval.addCell(getBorderlessCell(getDestination())); return retval; }
/** * Get the PDF Table with personal information about the initiator and traveler * * @returns {@link Table} used for a PDF */ protected Table getPersonalInfo() throws BadElementException { final Table retval = new Table(2); retval.setWidth(100f); retval.setBorder(NO_BORDER); retval.addCell(getHeaderCell("Traveler")); final Cell initiatorHeaderCell = getHeaderCell("Request Submitted By"); retval.addCell(initiatorHeaderCell); retval.endHeaders(); retval.addCell(getTravelerInfo()); final Cell initiatorCell = getInitiatorInfo(); retval.addCell(initiatorCell); return retval; }
public Table getExpenses() throws BadElementException { final Table retval = new Table(3); retval.setWidth(100f); retval.setBorder(NO_BORDER); retval.addCell(getHeaderCell("Expenses")); retval.addCell(getHeaderCell("Amount")); retval.addCell(getHeaderCell("Receipt Required?")); retval.endHeaders(); for (final Map<String, String> expense : expenses) { retval.addCell(getBorderlessCell(expense.get("expenseType"))); retval.addCell(getBorderlessCell(expense.get("amount"))); retval.addCell(getBorderlessCell(expense.get("receipt"))); } return retval; }
/** * Generates the header cells, which persist on every page of the PDF document. * * @throws BadElementException * IText exception * @throws NetxiliaBusinessException * @throws NetxiliaResourceException */ protected void generateHeaders(ISheet sheet, Table tablePDF, Font font, int columnCount) throws BadElementException, NetxiliaResourceException, NetxiliaBusinessException { Cell hdrCell = getCell("", font, Element.ALIGN_CENTER, 50); hdrCell.setGrayFill(0.9f); hdrCell.setHeader(true); tablePDF.addCell(hdrCell); List<ColumnData> columnData = sheet.receiveColumns(Range.ALL).getNonBlocking(); for (int i = 0; i < columnCount; ++i) { ColumnData column = i < columnData.size() ? columnData.get(i) : null; hdrCell = getCell(CellReference.columnLabel(i), font, Element.ALIGN_CENTER, column != null ? column .getWidth() : 120); hdrCell.setGrayFill(0.9f); hdrCell.setHeader(true); tablePDF.addCell(hdrCell); } }
/** * Renders the contents of the report. * * @param response the report data * @param document the current report document * @throws DocumentException for any other errors encountered */ private void renderItems(ChangeHistoryReportResponse response, Document document) throws DocumentException { // generate header table Table table = new Table(3); table.setBorder(Table.TOP | Table.BOTTOM | Table.LEFT | Table.RIGHT); Cell cell = new Cell(); cell.setBorder(Cell.LEFT); table.setDefaultCell(cell); table.setWidth(100); table.setPadding(1); table.addCell(new Phrase("CSD #" + response.getCsd(), ReportHelper.TABLE_HEADER_FONT)); table.addCell(new Phrase(ReportHelper.formatDate(response.getBirthDay()), ReportHelper.TABLE_HEADER_FONT)); table.addCell(new Phrase(response.getClaimName(), ReportHelper.TABLE_HEADER_FONT)); document.add(table); Map<GroupingKey, List<ChangeHistoryReportResponseItem>> groups = groupItems(response); Set<GroupingKey> keySet = groups.keySet(); for (GroupingKey groupingKey : keySet) { renderGroup(document, groupingKey, groups.get(groupingKey)); } if (response.getItems().isEmpty()) { document.add(new Paragraph("There are no changes on record.", ReportHelper.TABLE_DATA_FONT)); } }
/** * Renders all the records that are part of a group. * * @param document the current report * @param groupingKey the grouping key * @param list the items in the group * @throws DocumentException for any errors encountered */ private void renderGroup(Document document, GroupingKey groupingKey, List<ChangeHistoryReportResponseItem> list) throws DocumentException { Table table = new Table(1); table.setBorder(Table.NO_BORDER); Cell cell = new Cell(); cell.setBorder(Cell.NO_BORDER); table.setDefaultCell(cell); table.setWidth(100); table.setPadding(1); // table header and column widths table.setWidths(new float[] {100}); String groupLabel = "{0} {1}"; String groupHeader = MessageFormat.format(groupLabel, groupingKey.date, groupingKey.user); Cell headerCell = new Cell(new Phrase(groupHeader, ReportHelper.TABLE_HEADER_FONT)); headerCell.setBorder(Cell.BOTTOM); table.addCell(headerCell); for (ChangeHistoryReportResponseItem row : list) { table.addCell(new Phrase(row.getDescription(), ReportHelper.TABLE_DATA_FONT)); } document.add(table); document.add(new Phrase(" ")); // spacer }
/** * Renders the summary of adjustments. * * @param document the current document * @param userChangeCount the map representing the number of changes per user * @param userAccounts the map representing the number of accounts per user * @throws DocumentException for any errors encountered */ private void renderSummary(Document document, Map<String, Integer> userChangeCount, Map<String, Set<String>> userAccounts) throws DocumentException { Table table = new Table(1); table.setBorder(Table.TOP | Table.LEFT | Table.BOTTOM); Cell cell = new Cell(); cell.setBorder(Cell.NO_BORDER); table.setDefaultCell(cell); table.setWidth(100); table.setPadding(1); // table header and column widths table.setWidths(new float[] {100}); String groupLabel = "{0} made {1} changes to {2} accounts during this reporting period."; for (Map.Entry<String, Integer> user : userChangeCount.entrySet()) { Set<String> accountsModified = userAccounts.get(user.getKey()); String userSummary = MessageFormat.format(groupLabel, user.getKey(), user.getValue(), accountsModified.size()); table.addCell(new Phrase(userSummary, ReportHelper.TABLE_DATA_FONT)); } document.add(table); }
/** * Renders the grand total. * @param response the response object * @param document the document report * @throws DocumentException may be thrown by the iText library while rendering the elements */ private void renderGrandTotal(PaymentPendingApprovalReportResponse response, Document document) throws DocumentException { Table table = new Table(2); table.setWidths(new float[]{80, 20}); table.setBorder(Table.NO_BORDER); table.setWidth(40); table.setPadding(1); Cell cell = new Cell(new Phrase("Grand Total", ReportHelper.TABLE_HEADER_FONT)); cell.setBorder(Cell.BOTTOM); cell.setBorderWidth(1f); table.addCell(cell); Cell subTotal = new Cell(new Phrase(response.getItems().size() + "", ReportHelper.TABLE_HEADER_FONT)); subTotal.setBorder(Cell.BOTTOM); subTotal.setBorderWidth(1f); table.addCell(subTotal); document.add(table); }
/** * Render grouping. * @param response The response object * @param document The document report * @throws DocumentException may be thrown by the iText library while rendering the elements */ private void renderGrouping(PaymentPendingApprovalReportResponse response, Document document) throws DocumentException { Table table = new Table(2); table.setWidths(new float[]{80, 20}); table.setBorder(Table.NO_BORDER); table.setWidth(40); table.setPadding(1); Cell cell = new Cell(new Phrase("Recievables Technician", ReportHelper.TABLE_HEADER_FONT)); cell.setBorder(Cell.TOP | Cell.BOTTOM); table.addCell(cell); Cell subTotal = new Cell(new Phrase(response.getItems().size() + "", ReportHelper.TABLE_HEADER_FONT)); subTotal.setBorder(Cell.TOP | Cell.BOTTOM); table.addCell(subTotal); document.add(table); }
/** * Adds a total row to the table. * * @param table * the table. * @param contents * the columns contents. * @param font * the font to use. * @param borderTop * the border top width. * @param borderBottom * the border bottom width. */ private static void addTotalRow(Table table, Object[] contents, RtfFont font, int borderTop, int borderBottom) { Cell labelCell = ReportServiceHelper.createTableCell(contents[0], font, null, ReportServiceHelper.RTF_ALIGN_RIGHT, null, 2); labelCell.setBorderWidthTop(borderTop); labelCell.setBorderWidthBottom(borderBottom); table.addCell(labelCell); Cell numberCell = ReportServiceHelper.createTableCell(contents[1], font, null, ReportServiceHelper.RTF_ALIGN_RIGHT, null, 1); numberCell.setBorderWidthTop(borderTop); numberCell.setBorderWidthBottom(borderBottom); table.addCell(numberCell); Cell totalCell = ReportServiceHelper.createTableCell(contents.length == 3 ? contents[2] : null, font, null, ReportServiceHelper.RTF_ALIGN_RIGHT, null, 1); totalCell.setBorderWidthTop(borderTop); totalCell.setBorderWidthBottom(borderBottom); table.addCell(totalCell); Cell emptyCell = ReportServiceHelper.createEmptyCell(1, null); emptyCell.setBorderWidthTop(borderTop); emptyCell.setBorderWidthBottom(borderBottom); table.addCell(emptyCell); }
/** * Adds a row for the field to the RTF table. * * @param table * the table. * @param label * the field label. * @param value * the field value. * @param emptyCellColSpan * how many columns the empty cell will span. */ private static void addContentRow(Table table, String label, String value, int emptyCellColSpan) { if (emptyCellColSpan > 0) { table.addCell(ReportServiceHelper.createEmptyCell(emptyCellColSpan, ReportServiceHelper.RTF_NO_BORDER)); } table.addCell(ReportServiceHelper .createTableCell( label, emptyCellColSpan > 0 ? ReportServiceHelper.RTF_REPORT_CONTENT_FONT : ReportServiceHelper.RTF_REPORT_HEADER_FONT, null, ReportServiceHelper.RTF_ALIGN_LEFT, ReportServiceHelper.RTF_BORDER_BOTTOM, 4 - emptyCellColSpan - 1)); table.addCell(ReportServiceHelper .createTableCell( value, emptyCellColSpan > 0 ? ReportServiceHelper.RTF_REPORT_CONTENT_FONT : ReportServiceHelper.RTF_REPORT_HEADER_FONT, null, ReportServiceHelper.RTF_ALIGN_RIGHT, ReportServiceHelper.RTF_BORDER_BOTTOM, 1)); }
/** * Constructs a <CODE>PdfTable</CODE>-object. * * @param table a <CODE>Table</CODE> * @param left the left border on the page * @param right the right border on the page * @param top the start position of the top of the table * @param supportUpdateRowAdditions * if true, table rows will be deleted after building the PdfTable table, * in order to preserve memory and detect future row additions */ PdfTable(Table table, float left, float right, float top, boolean supportUpdateRowAdditions) { // constructs a Rectangle (the bottomvalue will be changed afterwards) super(left, top, right, top); this.table = table; table.complete(); // copying the attributes from class Table cloneNonPositionParameters(table); this.columns = table.columns(); positions = table.getWidths(left, right - left); // initialisation of some parameters setLeft(positions[0]); setRight(positions[positions.length - 1]); headercells = new ArrayList(); cells = new ArrayList(); updateRowAdditionsInternal(); if (supportUpdateRowAdditions) { table.deleteAllRows(); } }
/** * creates the data dictionary section in the report * * @param table * the in which to insert the evaluations */ protected void writeEvaluation(Table table, int evalValue ) throws IOException { //evalValue = StrategyEvaluationPreferences.getValueToVisualize(evalValue); // if 0,100, convert back to -100,100 to have the right color. int colorValue = StrategyEvaluationPreferences.getEquivalentValueInFullRangeIfApplicable( urnSpec, evalValue ); Cell evaluationCell = new Cell(evalValue + ""); //$NON-NLS-1$ evaluationCell.setColspan(STRATEGY_CELL_WIDTH); if (colorValue == 0) { evaluationCell.setBackgroundColor(new java.awt.Color(255, 255, 151)); } else if (colorValue == -100) { evaluationCell.setBackgroundColor(new java.awt.Color(252, 169, 171)); } else if (colorValue > -100 && colorValue < 0) { evaluationCell.setBackgroundColor(new java.awt.Color(253, 233, 234)); } else if (colorValue == 100) { evaluationCell.setBackgroundColor(new java.awt.Color(210, 249, 172)); } else if (colorValue > 0 && colorValue < 100) { evaluationCell.setBackgroundColor(new java.awt.Color(240, 253, 227)); } table.addCell(evaluationCell); }
/** * this helper method writes the header of the UCM scenario documentation section * * @param document * the document we are reporting into * @param message * the string to be displayed in the header * @param font * the font we will use to display the header */ public void insertHeader(Document document, String message, Font font) { try { Table table = ReportUtils.createTable(tableParams[0], tableParams[1], tableParams[2], tableParams[3]); Chunk chunk = new Chunk(message, font); Cell descriptionCell = new Cell(chunk); descriptionCell.setColspan(1); descriptionCell.setHorizontalAlignment(Element.ALIGN_LEFT); descriptionCell.setBorderWidthBottom(1.5f); table.addCell(descriptionCell); document.add(table); } catch (Exception e) { jUCMNavErrorDialog error = new jUCMNavErrorDialog(e.getMessage()); e.printStackTrace(); } }
/** * inserts the diagram figure description * * @param document * the document we are reporting into * @param element * the element illustrated by this diagram */ public void insertDiagramDescription(Document document, URNmodelElement element) { try { Table table = ReportUtils.createTable(1, 2, 0, 100); Chunk chunk = new Chunk(Messages.getString("PDFReportDiagram.Description"), descriptionBoldFont); //$NON-NLS-1$ Cell descriptionCell = new Cell(chunk); descriptionCell.setColspan(1); descriptionCell.setHorizontalAlignment(Element.ALIGN_LEFT); descriptionCell.setBorderWidthBottom(1.5f); Chunk descText = new Chunk(element.getDescription(), descriptionFont); table.addCell(descriptionCell); document.add(table); document.add(descText); } catch (Exception e) { jUCMNavErrorDialog error = new jUCMNavErrorDialog(e.getMessage()); e.printStackTrace(); } }
/** * inserts the diagram figure legend * * @param document * the document we are reporting into * @param element * the element illustrated by this diagram * @param i * the diagram number */ public void insertDiagramLegend(Document document, URNmodelElement element, int i) { try { int figureNo = i + 1; Table headerTable = ReportUtils.createTable(1, 1, 0, 100); Chunk name = new Chunk(Messages.getString("RTFReportDiagram.Figure") + figureNo + " - " + element.getName(), figureLegendFont); //$NON-NLS-1$ //$NON-NLS-2$ Cell nameCell = new Cell(name); nameCell.setColspan(1); nameCell.setHorizontalAlignment(Element.ALIGN_CENTER); nameCell.setBorderWidthTop(2f); headerTable.addCell(nameCell); document.add(headerTable); } catch (Exception e) { jUCMNavErrorDialog error = new jUCMNavErrorDialog(e.getMessage()); e.printStackTrace(); } }
/** * creates a Table for reports * * @param nbOfColumns * the number of columns for the table * @param padding * the space padding for the table * @param spacing * the spacing for the table * @param width * the width of the table * * @return Table the table ready to use * */ public static Table createTable(int nbOfColumns, int padding, int spacing, int width) { try { Table table = new Table(nbOfColumns); table.setBorderWidth(0f); table.setPadding(padding); table.setSpacing(spacing); table.setWidth(width); return table; } catch (Exception e) { jUCMNavErrorDialog error = new jUCMNavErrorDialog(e.getMessage()); e.printStackTrace(); return null; } }
protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter pdfWriter, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { Map<String,String> userData = (Map<String,String>) map.get("userData"); Table table = new Table(2); table.addCell("No."); table.addCell("User Name"); for (Map.Entry<String, String> entry : userData.entrySet()) { table.addCell(entry.getKey()); table.addCell(entry.getValue()); } document.add(table); }
private Paragraph generateContent(Grade grade) throws BadElementException { Paragraph content = new Paragraph(); Table table = createTable(grade); content.add(table); return content; }
private Table setTableOptions(Table table) { table.setTableFitsPage(true); table.setCellsFitPage(true); table.setPadding(4); return table; }
/** * Set the alignment of this RtfHeaderFooter. Passes the setting * on to the contained element. */ public void setAlignment(int alignment) { super.setAlignment(alignment); for(int i = 0; i < this.content.length; i++) { if(this.content[i] instanceof Paragraph) { ((Paragraph) this.content[i]).setAlignment(alignment); } else if(this.content[i] instanceof Table) { ((Table) this.content[i]).setAlignment(alignment); } else if(this.content[i] instanceof Image) { ((Image) this.content[i]).setAlignment(alignment); } } }
/** * Imports the rows and settings from the Table into this * RtfTable. * * @param table The source Table */ private void importTable(Table table) { this.rows = new ArrayList(); this.tableWidthPercent = table.getWidth(); this.proportionalWidths = table.getProportionalWidths(); this.cellPadding = (float) (table.getPadding() * TWIPS_FACTOR); this.cellSpacing = (float) (table.getSpacing() * TWIPS_FACTOR); this.borders = new RtfBorderGroup(this.document, RtfBorder.ROW_BORDER, table.getBorder(), table.getBorderWidth(), table.getBorderColor()); this.alignment = table.getAlignment(); int i = 0; Iterator rowIterator = table.iterator(); while(rowIterator.hasNext()) { this.rows.add(new RtfRow(this.document, this, (Row) rowIterator.next(), i)); i++; } for(i = 0; i < this.rows.size(); i++) { ((RtfRow) this.rows.get(i)).handleCellSpanning(); ((RtfRow) this.rows.get(i)).cleanRow(); } this.headerRows = table.getLastHeaderRow(); this.cellsFitToPage = table.isCellsFitPage(); this.tableFitToPage = table.isTableFitsPage(); if(!Float.isNaN(table.getOffset())) { this.offset = (int) (table.getOffset() * 2); } }