List of usage examples for com.lowagie.text.pdf PdfPTable setHorizontalAlignment
public void setHorizontalAlignment(int horizontalAlignment)
From source file:biblivre3.administration.reports.AllUsersReport.java
License:Open Source License
private final PdfPTable createSummaryTable(Map<String, Integer> tipos) { PdfPTable table = new PdfPTable(2); table.setWidthPercentage(50f);//from w ww . jav a 2s . c o m table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); int total = 0; PdfPCell cell; for (String description : tipos.keySet()) { total += tipos.get(description); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(description.toUpperCase()))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(String.valueOf(tipos.get(description))))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); } cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_TOTAL")))); cell.setBackgroundColor(headerBgColor); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(String.valueOf(total)))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); return table; }
From source file:biblivre3.administration.reports.BibliographyReport.java
License:Open Source License
@Override protected void generateReportBody(Document document, BaseReportDto reportData) throws Exception { BibliographyReportDto dto = (BibliographyReportDto) reportData; Paragraph p1 = new Paragraph(this.getText("REPORTS_BIBLIOGRAPHY_TITLE")); p1.setAlignment(Paragraph.ALIGN_CENTER); document.add(p1);/*from w ww . jav a 2s .c o m*/ document.add(new Phrase("\n")); Paragraph p2 = new Paragraph( this.getHeaderChunk(this.getText("REPORTS_AUTHOR") + ": " + dto.getAuthorName())); p2.setAlignment(Paragraph.ALIGN_LEFT); document.add(p2); document.add(new Phrase("\n")); if (dto.getData() != null) { PdfPTable table = new PdfPTable(8); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); createHeader(table); PdfPCell cell; for (String[] data : dto.getData()) { cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[0]))); cell.setColspan(3); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[1]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[2]))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[3]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[4]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); } document.add(table); document.add(new Phrase("\n")); } }
From source file:biblivre3.administration.reports.DeweyReport.java
License:Open Source License
@Override protected void generateReportBody(Document document, BaseReportDto reportData) throws Exception { DeweyReportDto dto = (DeweyReportDto) reportData; Paragraph p1 = new Paragraph(this.getText("REPORTS_DEWEY_TITLE")); p1.setAlignment(Paragraph.ALIGN_CENTER); document.add(p1);//from w ww .j ava 2 s .c o m document.add(new Phrase("\n\n")); PdfPTable table = new PdfPTable(6); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); createHeader(table); PdfPCell cell; int totalRecords = 0; int totalHoldings = 0; List<String[]> dataList = dto.getData(); Collections.sort(dataList, this); for (String[] data : dataList) { if (StringUtils.isBlank(data[0])) { data[0] = this.getText("REPORTS_DEWEY_UNCLASSIFIED"); } totalRecords += Integer.parseInt(data[1]); totalHoldings += Integer.parseInt(data[2]); } if (totalRecords > 0) { dataList.add(new String[] { this.getText("REPORTS_TOTAL"), String.valueOf(totalRecords), String.valueOf(totalHoldings) }); } for (String[] data : dataList) { cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[0]))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[1]))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[2]))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); } document.add(table); }
From source file:biblivre3.administration.reports.HoldingCreationByDatetReport.java
License:Open Source License
private PdfPTable createTable(List<String[]> dataList) { PdfPTable table = new PdfPTable(4); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); createHeader(table);/*w w w . jav a 2 s. com*/ PdfPCell cell; for (String[] data : dataList) { String name = data[1]; int total = Integer.valueOf(data[2]); if (totalUsuario.containsKey(name)) { totalUsuario.put(name, totalUsuario.get(name) + total); } else { totalUsuario.put(name, total); } cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[0]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(name))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(String.valueOf(total)))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); } return table; }
From source file:biblivre3.administration.reports.LateReturnLendingsReport.java
License:Open Source License
private PdfPTable createTable(List<String[]> lendings) { PdfPTable table = new PdfPTable(6); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.setWidthPercentage(100f);// ww w. j av a 2s . c o m createHeader(table); PdfPCell cell; for (String[] lending : lendings) { cell = new PdfPCell(new Paragraph(this.getNormalChunk(lending[0]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(lending[1]))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(lending[2]))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(lending[3]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); } return table; }
From source file:biblivre3.administration.reports.LendingsByDateReport.java
License:Open Source License
private PdfPTable createTable(LendingsByDateReportDto dto) { PdfPTable table = new PdfPTable(5); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.setWidthPercentage(100f);/*from w ww .ja v a 2s .co m*/ PdfPCell cell; cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_LENDINGS")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_TITLE")))); cell.setBackgroundColor(headerBgColor); cell.setColspan(2); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_AUTHOR")))); cell.setBackgroundColor(headerBgColor); cell.setColspan(2); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); //Table body if (dto.getData() == null || dto.getData().isEmpty()) return table; for (String[] data : dto.getData()) { cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[0]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[1]))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[2]))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); } return table; }
From source file:biblivre3.administration.reports.RequestsByDateReport.java
License:Open Source License
private PdfPTable createTable(List<String[]> dataList) { PdfPTable table = new PdfPTable(7); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.setWidthPercentage(100f);//from w w w . j ava2 s . c om createHeader(table); PdfPCell cell; String lastQuotationId = "0"; String requester = null; String title = null; String quantity = null; String unit_value = null; String total_value = null; for (String[] data : dataList) { if (!data[0].equals(lastQuotationId)) { if (!lastQuotationId.equals("0")) { cell = new PdfPCell(new Paragraph(this.getNormalChunk(requester))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(title))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(quantity))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(unit_value))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(total_value))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); table.addCell(cell); } requester = ""; title = ""; quantity = ""; unit_value = ""; total_value = ""; } lastQuotationId = data[0]; requester = data[1] + "\n"; title += data[2] + "\n"; quantity += data[3] + "\n"; unit_value += data[4] + "\n"; total_value = (data[5] == null ? "-" : data[5]) + "\n"; } if (!lastQuotationId.equals("0")) { cell = new PdfPCell(new Paragraph(this.getNormalChunk(requester))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(title))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(quantity))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(unit_value))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(total_value))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); table.addCell(cell); } return table; }
From source file:biblivre3.administration.reports.SearchesByDateReport.java
License:Open Source License
private PdfPTable createTable(SearchesByDateReportDto dto) { PdfPTable table = new PdfPTable(2); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); //Table header PdfPCell cell;/*w ww . ja va 2s . com*/ cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_DATE")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_TOTAL")))); cell.setBackgroundColor(headerBgColor); cell.setColspan(2); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); //Table body if (dto.getData() == null || dto.getData().isEmpty()) return table; for (String[] data : dto.getData()) { cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[1]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[0]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); } return table; }
From source file:com.ainfosec.macresponse.report.RtfGenerator.java
License:Open Source License
private static void createDataSection(Paragraph paragraph, DisplayObject displayObject) { if (displayObject == null || displayObject.getObjects() == null) { return;/*from w w w .j a v a2s . c o m*/ } // See if the DisplayObject has a list or a single object if (displayObject.getObjects().size() == 1) { TreeObject treeObject = displayObject.getObjects().get(0); // There's only 1 item // For each column, create/add a label with the title and the data int i = 0; for (String columnName : displayObject.getColumnNames()) { StringBuffer sb = new StringBuffer(); // Add the column title sb.append(displayObject.getColumnTitles()[i]); sb.append(": "); // Get the value of the field try { Field field = treeObject.getClass().getDeclaredField(columnName); String val = (String) field.get(treeObject); if (val == null) { val = ""; } // Add the value sb.append(val); sb.append("\n"); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Put the string into the paragraph paragraph.add(sb.toString()); i++; } } else { PdfPTable table = new PdfPTable(displayObject.getColumnTitles().length); table.setWidthPercentage(100); table.setHorizontalAlignment(Element.ALIGN_CENTER); for (String columnName : displayObject.getColumnTitles()) { table.getDefaultCell().setBackgroundColor(Color.CYAN); table.addCell(columnName); table.getDefaultCell().setBackgroundColor(Color.WHITE); } for (TreeObject to1 : displayObject.getObjects()) { for (String columnName : displayObject.getColumnNames()) { try { Field field = to1.getClass().getDeclaredField(columnName); String val = (String) field.get(to1); if (val == null) { val = ""; } table.addCell(val); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } table.getDefaultCell().setColspan(displayObject.getColumnTitles().length); table.getDefaultCell().setBorder(SWT.NONE); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // TODO Paul number the tables table.addCell("Table: " + displayObject.getTitle()); document.add(new RtfTable(document, table)); } }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java
License:Open Source License
private static String parseTable(WikiPDFContext context, Wiki wiki, String line, Document document, Connection db, ArrayList<Integer> wikiListTodo, ArrayList<Integer> wikiListDone, BufferedReader in) throws Exception { if (line == null) { return null; }//from w w w . j a v a2s . c om PdfPTable pdfTable = null; int columnCount = 0; int rowCount = 0; // Keep track of the table's custom styles HashMap<Integer, String> cStyle = new HashMap<Integer, String>(); while (line != null && (line.startsWith("|") || line.startsWith("!"))) { // Build a complete line String lineToParse = line; while (!line.endsWith("|")) { line = in.readLine(); if (line == null) { // there is an error in the line to process return null; } if (line.startsWith("!")) { lineToParse += CRLF + line.substring(1); } } line = lineToParse; // Determine if the row can output boolean canOutput = true; ++rowCount; String cellType = null; Scanner sc = null; if (line.startsWith("||") && line.endsWith("||")) { cellType = "th"; sc = new Scanner(line).useDelimiter("[|][|]"); // sc = new Scanner(line.substring(2, line.length() - 2)).useDelimiter("[|][|]"); } else if (line.startsWith("|")) { cellType = "td"; sc = new Scanner(line.substring(1, line.length() - 1)).useDelimiter("\\|(?=[^\\]]*(?:\\[|$))"); } if (sc != null) { if (rowCount == 1) { // Count the columns, get the specified widths too... while (sc.hasNext()) { ++columnCount; sc.next(); } // Reset the scanner now that the columns have been counted if (line.startsWith("||") && line.endsWith("||")) { sc = new Scanner(line).useDelimiter("[|][|]"); } else if (line.startsWith("|")) { sc = new Scanner(line.substring(1, line.length() - 1)) .useDelimiter("\\|(?=[^\\]]*(?:\\[|$))"); } // Start the table pdfTable = new PdfPTable(columnCount); //pdfTable.setWidthPercentage(100); pdfTable.setHorizontalAlignment(Element.ALIGN_LEFT); pdfTable.setSpacingBefore(10); pdfTable.setWidthPercentage(100); pdfTable.setKeepTogether(true); } // Determine the column span int colSpan = 1; // Determine the cell being output int cellCount = 0; while (sc.hasNext()) { String cellData = sc.next(); if (cellData.length() == 0) { ++colSpan; continue; } // Track the cell count being output ++cellCount; if (rowCount == 1) { // Parse and validate the style input LOG.debug("Checking style value: " + cellData); if (cellData.startsWith("{") && cellData.endsWith("}")) { String[] style = cellData.substring(1, cellData.length() - 1).split(":"); String attribute = style[0].trim(); String value = style[1].trim(); // Determine the width of each column and store it if ("width".equals(attribute)) { // Validate the width style if (StringUtils.hasAllowedOnly("0123456789%.", value)) { cStyle.put(cellCount, attribute + ": " + value + ";"); } } else { LOG.debug("Unsupported style: " + cellData); } canOutput = false; } } // Output the header if (canOutput) { PdfPCell cell = new PdfPCell(); cell.setPadding(10); cell.setBorderColor(new Color(100, 100, 100)); if ("th".equals(cellType)) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); } if (colSpan > 1) { cell.setColspan(colSpan); } // Output the data if (" ".equals(cellData) || "".equals(cellData)) { // Put a blank space in blank cells for output consistency cell.addElement(new Chunk(" ")); LOG.debug(" OUTPUTTING A BLANK"); } else { // Output the cell as a complete wiki float cellWidth = (100.0f / columnCount); parseContent(context, wiki, cellData, document, cell, db, wikiListTodo, wikiListDone, cellWidth); LOG.debug(" OUTPUTTING CONTENT"); } pdfTable.addCell(cell); } } } // read another line to see if it's part of the table line = in.readLine(); } if (pdfTable != null) { LOG.debug("document.add(pdfTable)"); document.add(pdfTable); // document.add(Chunk.NEWLINE); } return line; }