List of usage examples for com.lowagie.text.pdf PdfPTable setSpacingBefore
public void setSpacingBefore(float spacing)
From source file:com.qcadoo.mes.workPlans.pdf.document.operation.component.OperationProductOutTable.java
License:Open Source License
public void print(GroupingContainer groupingContainer, Entity operationComponent, Document document, Locale locale) throws DocumentException { Map<Long, Map<OperationProductColumn, ColumnAlignment>> map = groupingContainer .getOperationComponentIdProductInColumnToAlignment(); Map<OperationProductColumn, ColumnAlignment> operationProductColumnAlignmentMap = map .get(operationComponent.getId()); int columnCount = operationProductColumnAlignmentMap.size(); Map<String, HeaderAlignment> headerAlignments = new HashMap<String, HeaderAlignment>(columnCount); List<String> headers = new ArrayList<String>(columnCount); fill(locale, operationProductColumnAlignmentMap, headers, headerAlignments); PdfPTable table = pdfHelper.createTableWithHeader(columnCount, headers, false, headerAlignments); PdfPCell defaultCell = table.getDefaultCell(); for (Entity operationProduct : operationProductOutComponents(operationComponent)) { for (Map.Entry<OperationProductColumn, ColumnAlignment> e : operationProductColumnAlignmentMap .entrySet()) {/*from w ww . j av a2 s . c o m*/ alignColumn(defaultCell, e.getValue()); table.addCell(operationProductPhrase(operationProduct, e.getKey())); } } int additionalRows = workPlansService .getAdditionalRowsFromParameter(ParameterFieldsWP.ADDITIONAL_OUTPUT_ROWS); for (int i = 0; i < additionalRows; i++) { for (Map.Entry<OperationProductColumn, ColumnAlignment> e : operationProductColumnAlignmentMap .entrySet()) { alignColumn(defaultCell, e.getValue()); table.addCell(" "); } } table.setSpacingAfter(18); table.setSpacingBefore(9); document.add(table); }
From source file:com.qcadoo.report.internal.PdfHelperImpl.java
License:Open Source License
private PdfPTable setTableProperties(final List<String> header, final boolean lastColumnAligmentToLeft, final PdfPTable table, final Map<String, HeaderAlignment> alignments) { table.setWidthPercentage(100f);/* w w w . java 2 s. co m*/ table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setSpacingBefore(7.0f); // table.getDefaultCell().setBackgroundColor(ColorUtils.getBackgroundColor()); table.getDefaultCell().setBorderColor(ColorUtils.getLineDarkColor()); table.getDefaultCell().setBorderWidth(1.0f); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.getDefaultCell().setPadding(5.0f); table.getDefaultCell().disableBorderSide(Rectangle.RIGHT); if (alignments == null || alignments.isEmpty()) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); int i = 0; for (String element : header) { i++; if (i == header.size()) { table.getDefaultCell().enableBorderSide(Rectangle.RIGHT); } table.addCell(new Phrase(element, FontUtils.getDejavuBold7Dark())); if (i == 1) { table.getDefaultCell().disableBorderSide(Rectangle.LEFT); } } } else { int i = 0; for (String element : header) { i++; HeaderAlignment alignment = alignments.get(element); if (HeaderAlignment.LEFT.equals(alignment)) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); } else if (HeaderAlignment.RIGHT.equals(alignment)) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); } if (i == header.size()) { table.getDefaultCell().enableBorderSide(Rectangle.RIGHT); } table.addCell(new Phrase(element, FontUtils.getDejavuBold7Dark())); if (i == 1) { table.getDefaultCell().disableBorderSide(Rectangle.LEFT); } } } table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(null); table.getDefaultCell().disableBorderSide(Rectangle.RIGHT); table.getDefaultCell().setBorderColor(ColorUtils.getLineLightColor()); return table; }
From source file:com.safetys.framework.jmesa.view.pdfp.PdfPView.java
License:Apache License
@SuppressWarnings("deprecation") public PdfPTable render() { PdfPTable pdfpTable = new PdfPTable(getTable().getRow().getColumns().size()); pdfpTable.setSpacingBefore(3); Row row = getTable().getRow();/* w w w. j av a 2 s .c o m*/ List<Column> columns = row.getColumns(); // build table headers for (Iterator<Column> iter = columns.iterator(); iter.hasNext();) { Column column = iter.next(); PdfPCell cell = new PdfPCell(new Paragraph(column.getTitle(), getHeaderCellFont())); cell.setPadding(3.0f); cell.setBackgroundColor(getHeaderBackgroundColor()); pdfpTable.addCell(cell); } // build table body Collection<?> items = getCoreContext().getPageItems(); int rowcount = 0; for (Object item : items) { rowcount++; columns = row.getColumns(); for (Iterator<Column> iter = columns.iterator(); iter.hasNext();) { Column column = iter.next(); String property = column.getProperty(); Object value = column.getCellRenderer().getCellEditor().getValue(item, property, rowcount); PdfPCell cell = new PdfPCell( new Paragraph(value == null ? "" : String.valueOf(value), getCellFont())); cell.setPadding(3.0f); if (isRowEven(rowcount)) { cell.setBackgroundColor(getEvenCellBackgroundColor()); } else { cell.setBackgroundColor(getOddCellBackgroundColor()); } pdfpTable.addCell(cell); } } return pdfpTable; }
From source file:de.sub.goobi.forms.ProzessverwaltungForm.java
License:Open Source License
/** * Generate result as PDF./*from w w w.ja v a2s. c o m*/ */ public void generateResultAsPdf() { FacesContext facesContext = FacesContext.getCurrentInstance(); if (!facesContext.getResponseComplete()) { /* * Vorbereiten der Header-Informationen */ HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); try { ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext(); String contentType = servletContext.getMimeType("search.pdf"); response.setContentType(contentType); response.setHeader("Content-Disposition", "attachment;filename=\"search.pdf\""); ServletOutputStream out = response.getOutputStream(); SearchResultGeneration sr = new SearchResultGeneration(this.filter, this.showClosedProcesses, this.showArchivedProjects); HSSFWorkbook wb = sr.getResult(); List<List<HSSFCell>> rowList = new ArrayList<>(); HSSFSheet mySheet = wb.getSheetAt(0); Iterator<Row> rowIter = mySheet.rowIterator(); while (rowIter.hasNext()) { HSSFRow myRow = (HSSFRow) rowIter.next(); Iterator<Cell> cellIter = myRow.cellIterator(); List<HSSFCell> row = new ArrayList<>(); while (cellIter.hasNext()) { HSSFCell myCell = (HSSFCell) cellIter.next(); row.add(myCell); } rowList.add(row); } Document document = new Document(); Rectangle a4quer = new Rectangle(PageSize.A3.getHeight(), PageSize.A3.getWidth()); PdfWriter.getInstance(document, out); document.setPageSize(a4quer); document.open(); if (rowList.size() > 0) { Paragraph p = new Paragraph(rowList.get(0).get(0).toString()); document.add(p); PdfPTable table = new PdfPTable(9); table.setSpacingBefore(20); for (List<HSSFCell> row : rowList) { for (HSSFCell hssfCell : row) { // TODO aufhbschen und nicht toString() nutzen String stringCellValue = hssfCell.toString(); table.addCell(stringCellValue); } } document.add(table); } document.close(); out.flush(); facesContext.responseComplete(); } catch (Exception e) { logger.error(e); } } }
From source file:domain.reports.menu.PDFReportMenu.java
License:LGPL
/** * Return a report section formatted as a table * @param data/*from w w w. jav a2 s .c o m*/ * @return */ PdfPTable getGroupDetail(Recordset master, Recordset detail) throws Throwable { //cols PdfPTable datatable = new PdfPTable(2); //header datatable.getDefaultCell().setPadding(1); int headerwidths[] = { 50, 50 }; // percentage datatable.setWidths(headerwidths); datatable.setWidthPercentage(70); // percentage datatable.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell c = null; String v = ""; //encabezados de columnas c = new PdfPCell(new Phrase("ITEMS DEL MEN", tblHeaderFont)); c.setGrayFill(0.95f); c.setColspan(2); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Item del men", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Servicio", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); while (detail.next()) { v = detail.getString("description"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(c); v = detail.getString("path"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(c); } datatable.setSpacingBefore(20); return datatable; }
From source file:domain.reports.role.PDFReportRole.java
License:LGPL
/** * Return a report section formatted as a table * @param data// w w w.j av a 2s. com * @return */ PdfPTable getGroupDetail(Recordset master, Recordset detail) throws Throwable { //cols PdfPTable datatable = new PdfPTable(4); //header datatable.getDefaultCell().setPadding(1); int headerwidths[] = { 20, 20, 20, 20 }; // percentage datatable.setWidths(headerwidths); datatable.setWidthPercentage(100); // percentage datatable.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell c = null; String v = ""; //encabezados de columnas c = new PdfPCell(new Phrase("USUARIOS DEL ROL", tblHeaderFont)); c.setGrayFill(0.95f); c.setColspan(4); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Login de Usuario", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Apellido", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Nombre", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Email", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); while (detail.next()) { v = detail.getString("userlogin"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); v = detail.getString("lname"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); v = detail.getString("fname"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); v = detail.getString("email"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); } datatable.setSpacingBefore(20); return datatable; }
From source file:fr.opensagres.xdocreport.itext.extension.ExtendedParagraph.java
License:Open Source License
protected PdfPTable createWrapperTable(PdfPCell wrapperCell, boolean addParagraph) { PdfPTable wrapperTable = null; // wrap this paragraph into a table if necessary if (wrapperCell != null) { // background color or borders were set if (addParagraph) { wrapperCell.addElement(this); }//from w ww . jav a2 s.c o m wrapperTable = createTable(wrapperCell); if (getSpacingBefore() > 0.0f || getSpacingAfter() > 0.0f) { // top or bottom margin was set, promote it to enclosing table wrapperTable.setSpacingBefore(getSpacingBefore()); setSpacingBefore(0.0f); wrapperTable.setSpacingAfter(getSpacingAfter()); setSpacingAfter(0.0f); } if (getIndentationLeft() > 0.0f || getIndentationRight() > 0.0f) { // left or right margin was set, have to wrap the cell again PdfPCell outerCell = createCell(); outerCell.setPaddingLeft(getIndentationLeft()); setIndentationLeft(0.0f); outerCell.setPaddingRight(getIndentationRight()); setIndentationRight(0.0f); outerCell.addElement(wrapperTable); wrapperTable = createTable(outerCell); } } return wrapperTable; }
From source file:fr.opensagres.xdocreport.itext.extension.ExtendedPdfPTable.java
License:Open Source License
private PdfPTable createTable(PdfPCell cell) { PdfPTable table = new PdfPTable(1); table.setSpacingBefore(this.spacingBefore()); table.setSpacingAfter(this.spacingAfter()); table.setHorizontalAlignment(this.getHorizontalAlignment()); table.setTotalWidth(cell.getPaddingLeft() + this.getTotalWidth() + cell.getPaddingRight()); table.setLockedWidth(true);//w ww.j a v a 2s . co m table.setSplitLate(false); table.addCell(cell); return table; }
From source file:fr.opensagres.xdocreport.itext.extension.TableWithAlignment.java
License:Open Source License
public static void main(String[] args) { Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10); try {//from w w w . j a v a2 s.c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("TableWithAlignment.pdf")); document.open(); PdfPTable table = new PdfPTable(2); table.getDefaultCell().setUseAscender(true); table.getDefaultCell().setUseDescender(true); table.setWidths(new float[] { 5, 10 }); table.setWidthPercentage(10); PdfPCell cell1 = new PdfPCell(); cell1.addElement(new Chunk("cell1")); table.addCell(cell1); PdfPCell cell2 = new PdfPCell(); cell2.addElement(new Chunk("cell2")); table.addCell(cell2); table.setSpacingBefore(-100); document.add(table); } catch (Exception de) { de.printStackTrace(); } document.close(); }
From source file:gov.utah.dts.det.ccl.documents.templating.templates.AbstractCaseloadTemplate.java
@Override public void render(Map<String, Object> context, OutputStream outputStream, FileDescriptor descriptor) throws TemplateException { Long specialistId = (Long) context.get("specId"); if (specialistId == null) { throw new TemplateException("Specialist id is required."); }// w ww . j a va 2 s.c om CaseloadSortBy sortBy = CaseloadSortBy.getDefaultSortBy(); String sortByStr = (String) context.get("sortBy"); if (sortByStr != null) { sortBy = CaseloadSortBy.valueOf(sortByStr); } Person specialist = personService.getPerson(specialistId); context.put(SPECIALIST_KEY, specialist); List<FacilityCaseloadView> caseload = getCaseload(specialistId, sortBy); setFileName(context, descriptor); try { Document document = new Document(PageSize.LETTER.rotate(), MARGIN, MARGIN, MARGIN, MARGIN); PdfWriter.getInstance(document, outputStream); document.open(); document.add(new Paragraph(getReportTitle() + " for " + specialist.getFirstAndLastName(), FONT)); //columns: name, facility id, address, phone, 1st director(s), status, type, capacity (<2) PdfPTable table = new PdfPTable(8); table.setWidths(new float[] { 23f, 25f, 11f, 13f, 5f, 9f, 7f, 7f }); table.setWidthPercentage(100); table.setSpacingBefore(FONT_SIZE); table.getDefaultCell().setPadding(TABLE_CELL_PADDING); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setBorderWidthBottom(.5f); table.setHeaderRows(1); table.addCell(new Phrase("Facility Name", HEADER_FONT)); table.addCell(new Phrase("Address", HEADER_FONT)); table.addCell(new Phrase("Phone", HEADER_FONT)); table.addCell(new Phrase("1st Director(s)", HEADER_FONT)); table.addCell(new Phrase("Type", HEADER_FONT)); table.addCell(new Phrase("Exp Dt", HEADER_FONT)); table.addCell(new Phrase("Adult Cap", HEADER_FONT)); table.addCell(new Phrase("Youth Cap", HEADER_FONT)); boolean hasInProcess = false; for (FacilityCaseloadView fcv : caseload) { if (fcv.getStatus() == FacilityStatus.REGULATED || fcv.getStatus() == FacilityStatus.IN_PROCESS) { StringBuilder name = new StringBuilder(); if (fcv.getStatus() == FacilityStatus.IN_PROCESS) { hasInProcess = true; name.append("* "); } name.append(fcv.getName()); table.addCell(new Phrase(name.toString(), FONT)); table.addCell(new Phrase(fcv.getLocationAddress().toString(), FONT)); table.addCell(new Phrase(fcv.getPrimaryPhone().getFormattedPhoneNumber(), FONT)); table.addCell(new Phrase(fcv.getDirectorNames(), FONT)); String typeAbbrev = null; /* if (fcv.getLicenseType() != null) { typeAbbrev = applicationService.getApplicationPropertyValue("facility.license.type." + fcv.getLicenseType().getId()+ ".abbrev"); } */ table.addCell(new Phrase(typeAbbrev != null ? typeAbbrev : "", FONT)); // table.addCell(new Phrase(fcv.getExpirationDate() != null ? DATE_FORMATTER.format(fcv.getExpirationDate()) : "", FONT)); table.addCell(new Phrase("", FONT)); // if (fcv.getAdultTotalSlots() == null) { table.addCell(new Phrase("")); // } else { // table.addCell(new Phrase(fcv.getAdultTotalSlots().toString(), FONT)); // } // if (fcv.getYouthTotalSlots() == null) { table.addCell(new Phrase("")); // } else { // table.addCell(new Phrase(fcv.getYouthTotalSlots().toString(), FONT)); // } } } document.add(table); if (hasInProcess) { document.add(new Paragraph( "* - Facility is in the process of becoming a regulated child care facility.", FONT)); } document.close(); } catch (DocumentException de) { throw new TemplateException(de); } }