List of usage examples for com.lowagie.text Element ALIGN_RIGHT
int ALIGN_RIGHT
To view the source code for com.lowagie.text Element ALIGN_RIGHT.
Click Source Link
From source file:fr.aliasource.webmail.server.export.ConversationPdfEventHandler.java
License:GNU General Public License
/** * @see com.lowagie.text.pdf.PdfPageEventHelper#onOpenDocument(com.lowagie.text.pdf.PdfWriter, * com.lowagie.text.Document)//from ww w.j av a 2 s . co m */ public void onOpenDocument(PdfWriter writer, Document document) { try { headerImage = Image.getInstance(getLogoUrl()); table = new PdfPTable(new float[] { 1f, 2f }); Phrase p = new Phrase(); Chunk ck = new Chunk(cr.getTitle(), new Font(Font.HELVETICA, 16, Font.BOLD)); p.add(ck); p.add(Chunk.NEWLINE); ck = new Chunk(ConversationExporter.formatName(account), new Font(Font.HELVETICA, 12, Font.BOLDITALIC)); p.add(ck); p.add(Chunk.NEWLINE); ck = new Chunk(cm.length + " messages", new Font(Font.HELVETICA, 10)); p.add(ck); table.getDefaultCell().setBorder(0); table.addCell(new Phrase(new Chunk(headerImage, 0, 0))); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(p); // initialization of the template tpl = writer.getDirectContent().createTemplate(100, 100); tpl.setBoundingBox(new Rectangle(-20, -20, 100, 100)); // initialization of the font helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false); } catch (Exception e) { throw new ExceptionConverter(e); } }
From source file:fr.opensagres.odfdom.converter.pdf.internal.StyleEngineForIText.java
License:Open Source License
@Override public void visit(StyleParagraphPropertiesElement ele) { StyleParagraphProperties paragraphProperties = currentStyle.getParagraphProperties(); if (paragraphProperties == null) { paragraphProperties = new StyleParagraphProperties(); currentStyle.setParagraphProperties(paragraphProperties); }/*w w w .j a v a 2 s .com*/ // background-color String backgroundColor = ele.getFoBackgroundColorAttribute(); if (StringUtils.isNotEmpty(backgroundColor)) { paragraphProperties.setBackgroundColor(ColorRegistry.getInstance().getColor(backgroundColor)); } // border String border = ele.getFoBorderAttribute(); if (StringUtils.isNotEmpty(border)) { paragraphProperties.setBorder(new StyleBorder(border, BorderType.ALL)); } // border-bottom String borderBottom = ele.getFoBorderBottomAttribute(); if (StringUtils.isNotEmpty(borderBottom)) { paragraphProperties.setBorderBottom(new StyleBorder(borderBottom, BorderType.BOTTOM)); } // border-left String borderLeft = ele.getFoBorderLeftAttribute(); if (StringUtils.isNotEmpty(borderLeft)) { paragraphProperties.setBorderLeft(new StyleBorder(borderLeft, BorderType.LEFT)); } // border-bottom String borderRight = ele.getFoBorderRightAttribute(); if (StringUtils.isNotEmpty(borderRight)) { paragraphProperties.setBorderRight(new StyleBorder(borderRight, BorderType.RIGHT)); } // border-top String borderTop = ele.getFoBorderTopAttribute(); if (StringUtils.isNotEmpty(borderTop)) { paragraphProperties.setBorderTop(new StyleBorder(borderTop, BorderType.TOP)); } // join-border Boolean joinBorder = ele.getStyleJoinBorderAttribute(); if (joinBorder != null) { paragraphProperties.setJoinBorder(joinBorder); } // line-height String lineHeight = ele.getFoLineHeightAttribute(); if (StringUtils.isNotEmpty(lineHeight)) { paragraphProperties.setLineHeight(new StyleLineHeight(ODFUtils.getDimensionAsPoint(lineHeight), ODFUtils.hasPercentUnit(lineHeight))); } // margin String margin = ele.getFoMarginAttribute(); if (StringUtils.isNotEmpty(margin)) { paragraphProperties.setMargin(ODFUtils.getDimensionAsPoint(margin)); } // margin-bottom String marginBottom = ele.getFoMarginBottomAttribute(); if (StringUtils.isNotEmpty(marginBottom)) { paragraphProperties.setMarginBottom(ODFUtils.getDimensionAsPoint(marginBottom)); } // margin-left String marginLeft = ele.getFoMarginLeftAttribute(); if (StringUtils.isNotEmpty(marginLeft)) { paragraphProperties.setMarginLeft(ODFUtils.getDimensionAsPoint(marginLeft)); } // margin-right String marginRight = ele.getFoMarginRightAttribute(); if (StringUtils.isNotEmpty(marginRight)) { paragraphProperties.setMarginRight(ODFUtils.getDimensionAsPoint(marginRight)); } // margin-top String marginTop = ele.getFoMarginTopAttribute(); if (StringUtils.isNotEmpty(marginTop)) { paragraphProperties.setMarginTop(ODFUtils.getDimensionAsPoint(marginTop)); } // padding String padding = ele.getFoPaddingAttribute(); if (StringUtils.isNotEmpty(padding)) { paragraphProperties.setPadding(ODFUtils.getDimensionAsPoint(padding)); } // padding-bottom String paddingBottom = ele.getFoPaddingBottomAttribute(); if (StringUtils.isNotEmpty(paddingBottom)) { paragraphProperties.setPaddingBottom(ODFUtils.getDimensionAsPoint(paddingBottom)); } // padding-left String paddingLeft = ele.getFoPaddingLeftAttribute(); if (StringUtils.isNotEmpty(paddingLeft)) { paragraphProperties.setPaddingLeft(ODFUtils.getDimensionAsPoint(paddingLeft)); } // padding-right String paddingRight = ele.getFoPaddingRightAttribute(); if (StringUtils.isNotEmpty(paddingRight)) { paragraphProperties.setPaddingRight(ODFUtils.getDimensionAsPoint(paddingRight)); } // padding-top String paddingTop = ele.getFoPaddingTopAttribute(); if (StringUtils.isNotEmpty(paddingTop)) { paragraphProperties.setPaddingTop(ODFUtils.getDimensionAsPoint(paddingTop)); } // text-align String textAlign = ele.getFoTextAlignAttribute(); if (StringUtils.isNotEmpty(textAlign)) { int alignment = Element.ALIGN_UNDEFINED; if (FoTextAlignAttribute.Value.START.toString().equals(textAlign)) { alignment = Element.ALIGN_LEFT; } else if (FoTextAlignAttribute.Value.END.toString().equals(textAlign)) { alignment = Element.ALIGN_RIGHT; } else if (FoTextAlignAttribute.Value.LEFT.toString().equals(textAlign)) { alignment = Element.ALIGN_LEFT; } else if (FoTextAlignAttribute.Value.RIGHT.toString().equals(textAlign)) { alignment = Element.ALIGN_RIGHT; } else if (FoTextAlignAttribute.Value.CENTER.toString().equals(textAlign)) { alignment = Element.ALIGN_CENTER; } else if (FoTextAlignAttribute.Value.JUSTIFY.toString().equals(textAlign)) { alignment = Element.ALIGN_JUSTIFIED; } paragraphProperties.setAlignment(alignment); } // auto-text-indent Boolean autoTextIndent = ele.getStyleAutoTextIndentAttribute(); if (autoTextIndent != null) { paragraphProperties.setAutoTextIndent(autoTextIndent); } // text-indent String textIndent = ele.getFoTextIndentAttribute(); if (StringUtils.isNotEmpty(textIndent)) { paragraphProperties.setTextIndent(ODFUtils.getDimensionAsPoint(textIndent)); } // keep-together String keepTogether = ele.getFoKeepTogetherAttribute(); if (StringUtils.isNotEmpty(keepTogether)) { if (FoKeepTogetherAttribute.Value.ALWAYS.toString().equals(keepTogether)) { paragraphProperties.setKeepTogether(Boolean.TRUE); } else { paragraphProperties.setKeepTogether(Boolean.FALSE); } } // fo:break-before String breakBefore = ele.getFoBreakBeforeAttribute(); if (StringUtils.isNotEmpty(breakBefore)) { if (FoBreakBeforeAttribute.Value.PAGE.toString().equals(breakBefore)) { paragraphProperties.setBreakBefore(StyleBreak.createWithPageBreak()); } else if (FoBreakBeforeAttribute.Value.COLUMN.toString().equals(breakBefore)) { paragraphProperties.setBreakBefore(StyleBreak.createWithColumnBreak()); } else { paragraphProperties.setBreakBefore(StyleBreak.createWithNoBreak()); } } super.visit(ele); }
From source file:fr.opensagres.odfdom.converter.pdf.internal.StyleEngineForIText.java
License:Open Source License
@Override public void visit(StyleTabStopElement ele) { if (currentTabStopPropertiesList == null) { return;/* w ww . ja v a 2 s . c o m*/ } StyleTabStopProperties tabStopProperties = new StyleTabStopProperties(); currentTabStopPropertiesList.add(tabStopProperties); // leader-text String leaderText = ele.getStyleLeaderTextAttribute(); if (StringUtils.isNotEmpty(leaderText)) { tabStopProperties.setLeaderText(leaderText); } // position String position = ele.getStylePositionAttribute(); if (StringUtils.isNotEmpty(position)) { tabStopProperties.setPosition(ODFUtils.getDimensionAsPoint(position)); } // type String type = ele.getStyleTypeAttribute(); if (StringUtils.isNotEmpty(type)) { if (StyleTypeAttribute.Value.LEFT.toString().equals(type)) { tabStopProperties.setType(Element.ALIGN_LEFT); } else if (StyleTypeAttribute.Value.RIGHT.toString().equals(type)) { tabStopProperties.setType(Element.ALIGN_RIGHT); } else { tabStopProperties.setType(Element.ALIGN_CENTER); } } super.visit(ele); }
From source file:fr.opensagres.odfdom.converter.pdf.internal.StyleEngineForIText.java
License:Open Source License
@Override public void visit(StyleTablePropertiesElement ele) { StyleTableProperties tableProperties = new StyleTableProperties(); currentStyle.setTableProperties(tableProperties); // background-color String backgroundColor = ele.getFoBackgroundColorAttribute(); if (StringUtils.isNotEmpty(backgroundColor)) { tableProperties.setBackgroundColor(ColorRegistry.getInstance().getColor(backgroundColor)); }/*from ww w . j a v a2 s.c o m*/ // width String width = ele.getStyleWidthAttribute(); if (StringUtils.isNotEmpty(width)) { tableProperties.setWidth(ODFUtils.getDimensionAsPoint(width)); } // align String align = ele.getTableAlignAttribute(); if (StringUtils.isNotEmpty(align)) { if (TableAlignAttribute.Value.LEFT.toString().equals(align)) { tableProperties.setAlignment(Element.ALIGN_LEFT); } else if (TableAlignAttribute.Value.RIGHT.toString().equals(align)) { tableProperties.setAlignment(Element.ALIGN_RIGHT); } else { tableProperties.setAlignment(Element.ALIGN_CENTER); } } // margin String margin = ele.getFoMarginAttribute(); if (StringUtils.isNotEmpty(margin)) { tableProperties.setMargin(ODFUtils.getDimensionAsPoint(margin)); } // margin-bottom String marginBottom = ele.getFoMarginBottomAttribute(); if (StringUtils.isNotEmpty(marginBottom)) { tableProperties.setMarginBottom(ODFUtils.getDimensionAsPoint(marginBottom)); } // margin-left String marginLeft = ele.getFoMarginLeftAttribute(); if (StringUtils.isNotEmpty(marginLeft)) { tableProperties.setMarginLeft(ODFUtils.getDimensionAsPoint(marginLeft)); } // margin-right String marginRight = ele.getFoMarginRightAttribute(); if (StringUtils.isNotEmpty(marginRight)) { tableProperties.setMarginRight(ODFUtils.getDimensionAsPoint(marginRight)); } // margin-top String marginTop = ele.getFoMarginTopAttribute(); if (StringUtils.isNotEmpty(marginTop)) { tableProperties.setMarginTop(ODFUtils.getDimensionAsPoint(marginTop)); } // may-break-between-rows Boolean mayBreakBetweenRows = ele.getStyleMayBreakBetweenRowsAttribute(); if (mayBreakBetweenRows != null) { tableProperties.setMayBreakBetweenRows(mayBreakBetweenRows); } super.visit(ele); }
From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.FastPdfMapper.java
License:Open Source License
@Override protected IITextContainer startVisitParagraph(CTP paragraph, ListItemContext itemContext, IITextContainer pdfParentContainer) throws Exception { // create PDF paragraph StylableParagraph pdfParagraph = pdfDocument.createParagraph(pdfParentContainer); CTTbl parentTable = super.getParentTable(); // indentation left Float indentationLeft = stylesDocument.getIndentationLeft(paragraph, parentTable); if (indentationLeft != null) { pdfParagraph.setIndentationLeft(indentationLeft); }/* w w w . j a v a 2s .co m*/ // indentation right Float indentationRight = stylesDocument.getIndentationRight(paragraph, parentTable); if (indentationRight != null) { pdfParagraph.setIndentationRight(indentationRight); } // indentation first line Float indentationFirstLine = stylesDocument.getIndentationFirstLine(paragraph, parentTable); if (indentationFirstLine != null) { pdfParagraph.setFirstLineIndent(indentationFirstLine); } // indentation hanging (remove first line) Float indentationHanging = stylesDocument.getIndentationHanging(paragraph, parentTable); if (indentationHanging != null) { pdfParagraph.setFirstLineIndent(-indentationHanging); } // // spacing before Float spacingBefore = stylesDocument.getSpacingBefore(paragraph, parentTable); if (spacingBefore != null) { pdfParagraph.setSpacingBefore(spacingBefore); } // spacing after // one more pargraph, spacing after should be applied. Float spacingAfter = stylesDocument.getSpacingAfter(paragraph, parentTable); if (spacingAfter != null) { pdfParagraph.setSpacingAfter(spacingAfter); } ParagraphLineSpacing lineSpacing = stylesDocument.getParagraphSpacing(paragraph, parentTable); if (lineSpacing != null) { if (lineSpacing.getLeading() != null && lineSpacing.getMultipleLeading() != null) { pdfParagraph.setLeading(lineSpacing.getLeading(), lineSpacing.getMultipleLeading()); } else { if (lineSpacing.getLeading() != null) { pdfParagraph.setLeading(lineSpacing.getLeading()); } if (lineSpacing.getMultipleLeading() != null) { pdfParagraph.setMultipliedLeading(lineSpacing.getMultipleLeading()); } } } // text-align ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(paragraph, parentTable); if (alignment != null) { switch (alignment) { case LEFT: pdfParagraph.setAlignment(Element.ALIGN_LEFT); break; case RIGHT: pdfParagraph.setAlignment(Element.ALIGN_RIGHT); break; case CENTER: pdfParagraph.setAlignment(Element.ALIGN_CENTER); break; case BOTH: pdfParagraph.setAlignment(Element.ALIGN_JUSTIFIED); break; default: break; } } return pdfParagraph; }
From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.FastPdfMapper.java
License:Open Source License
private StylableTable createPDFTable(CTTbl table, float[] colWidths, IITextContainer pdfParentContainer) throws DocumentException { // 2) Compute tableWith TableWidth tableWidth = stylesDocument.getTableWidth(table); StylableTable pdfPTable = pdfDocument.createTable(pdfParentContainer, colWidths.length); pdfPTable.setTotalWidth(colWidths);/*from w w w . java2 s .c o m*/ if (tableWidth != null && tableWidth.width > 0) { if (tableWidth.percentUnit) { pdfPTable.setWidthPercentage(tableWidth.width); } else { pdfPTable.setTotalWidth(tableWidth.width); } } pdfPTable.setLockedWidth(true); // Table alignment ParagraphAlignment alignment = stylesDocument.getTableAlignment(table); if (alignment != null) { switch (alignment) { case LEFT: pdfPTable.setHorizontalAlignment(Element.ALIGN_LEFT); break; case RIGHT: pdfPTable.setHorizontalAlignment(Element.ALIGN_RIGHT); break; case CENTER: pdfPTable.setHorizontalAlignment(Element.ALIGN_CENTER); break; case BOTH: pdfPTable.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); break; default: break; } } // Table indentation Float indentation = stylesDocument.getTableIndentation(table); if (indentation != null) { pdfPTable.setPaddingLeft(indentation); } return pdfPTable; }
From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.java
License:Open Source License
@Override protected IITextContainer startVisitParagraph(XWPFParagraph docxParagraph, ListItemContext itemContext, IITextContainer pdfParentContainer) throws Exception { this.currentRunX = null; // create PDF paragraph StylableParagraph pdfParagraph = pdfDocument.createParagraph(pdfParentContainer); // indentation left Float indentationLeft = stylesDocument.getIndentationLeft(docxParagraph); if (indentationLeft != null) { pdfParagraph.setIndentationLeft(indentationLeft); }/*from www . jav a2 s . com*/ // indentation right Float indentationRight = stylesDocument.getIndentationRight(docxParagraph); if (indentationRight != null) { pdfParagraph.setIndentationRight(indentationRight); } // indentation first line Float indentationFirstLine = stylesDocument.getIndentationFirstLine(docxParagraph); if (indentationFirstLine != null) { pdfParagraph.setFirstLineIndent(indentationFirstLine); } // indentation hanging (remove first line) Float indentationHanging = stylesDocument.getIndentationHanging(docxParagraph); if (indentationHanging != null) { pdfParagraph.setFirstLineIndent(-indentationHanging); } // // spacing before Float spacingBefore = stylesDocument.getSpacingBefore(docxParagraph); if (spacingBefore != null) { pdfParagraph.setSpacingBefore(spacingBefore); } // spacing after Float spacingAfter = stylesDocument.getSpacingAfter(docxParagraph); if (spacingAfter != null) { pdfParagraph.setSpacingAfter(spacingAfter); } ParagraphLineSpacing lineSpacing = stylesDocument.getParagraphSpacing(docxParagraph); if (lineSpacing != null) { if (lineSpacing.getLeading() != null && lineSpacing.getMultipleLeading() != null) { pdfParagraph.setLeading(lineSpacing.getLeading(), lineSpacing.getMultipleLeading()); } else { if (lineSpacing.getLeading() != null) { pdfParagraph.setLeading(lineSpacing.getLeading()); } if (lineSpacing.getMultipleLeading() != null) { pdfParagraph.setMultipliedLeading(lineSpacing.getMultipleLeading()); } } } // text-align ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(docxParagraph); if (alignment != null) { switch (alignment) { case LEFT: pdfParagraph.setAlignment(Element.ALIGN_LEFT); break; case RIGHT: pdfParagraph.setAlignment(Element.ALIGN_RIGHT); break; case CENTER: pdfParagraph.setAlignment(Element.ALIGN_CENTER); break; case BOTH: pdfParagraph.setAlignment(Element.ALIGN_JUSTIFIED); break; default: break; } } // background-color Color backgroundColor = stylesDocument.getBackgroundColor(docxParagraph); if (backgroundColor != null) { pdfParagraph.setBackgroundColor(Converter.toAwtColor(backgroundColor)); } // border CTBorder borderTop = stylesDocument.getBorderTop(docxParagraph); pdfParagraph.setBorder(borderTop, Rectangle.TOP); CTBorder borderBottom = stylesDocument.getBorderBottom(docxParagraph); pdfParagraph.setBorder(borderBottom, Rectangle.BOTTOM); CTBorder borderLeft = stylesDocument.getBorderLeft(docxParagraph); pdfParagraph.setBorder(borderLeft, Rectangle.LEFT); CTBorder borderRight = stylesDocument.getBorderRight(docxParagraph); pdfParagraph.setBorder(borderRight, Rectangle.RIGHT); if (itemContext != null) { CTLvl lvl = itemContext.getLvl(); CTPPr lvlPPr = lvl.getPPr(); if (lvlPPr != null) { if (ParagraphIndentationLeftValueProvider.INSTANCE .getValue(docxParagraph.getCTP().getPPr()) == null) { // search the indentation from the level properties only if // paragraph has not override it // see // https://code.google.com/p/xdocreport/issues/detail?id=239 Float indLeft = ParagraphIndentationLeftValueProvider.INSTANCE.getValue(lvlPPr); if (indLeft != null) { pdfParagraph.setIndentationLeft(indLeft); } } if (ParagraphIndentationHangingValueProvider.INSTANCE .getValue(docxParagraph.getCTP().getPPr()) == null) { // search the hanging from the level properties only if // paragraph has not override it // see // https://code.google.com/p/xdocreport/issues/detail?id=239 Float hanging = stylesDocument.getIndentationHanging(lvlPPr); if (hanging != null) { pdfParagraph.setFirstLineIndent(-hanging); } } } CTRPr lvlRPr = lvl.getRPr(); if (lvlRPr != null) { // Font family String listItemFontFamily = stylesDocument.getFontFamilyAscii(lvlRPr); // Get font size Float listItemFontSize = stylesDocument.getFontSize(lvlRPr); // Get font style int listItemFontStyle = Font.NORMAL; Boolean bold = stylesDocument.getFontStyleBold(lvlRPr); if (bold != null && bold) { listItemFontStyle |= Font.BOLD; } Boolean italic = stylesDocument.getFontStyleItalic(lvlRPr); if (italic != null && italic) { listItemFontStyle |= Font.ITALIC; } Boolean strike = stylesDocument.getFontStyleStrike(lvlRPr); if (strike != null && strike) { listItemFontStyle |= Font.STRIKETHRU; } // Font color Color listItemFontColor = stylesDocument.getFontColor(lvlRPr); pdfParagraph.setListItemFontFamily(listItemFontFamily); pdfParagraph.setListItemFontSize(listItemFontSize); pdfParagraph.setListItemFontStyle(listItemFontStyle); pdfParagraph.setListItemFontColor(Converter.toAwtColor(listItemFontColor)); } pdfParagraph.setListItemText(itemContext.getText()); } return pdfParagraph; }
From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.java
License:Open Source License
private StylableTable createPDFTable(XWPFTable table, float[] colWidths, IITextContainer pdfParentContainer) throws DocumentException { // 2) Compute tableWith TableWidth tableWidth = stylesDocument.getTableWidth(table); StylableTable pdfPTable = pdfDocument.createTable(pdfParentContainer, colWidths.length); pdfPTable.setTotalWidth(colWidths);/*from w ww .j av a 2s .c om*/ if (tableWidth != null && tableWidth.width > 0) { if (tableWidth.percentUnit) { pdfPTable.setWidthPercentage(tableWidth.width); } else { pdfPTable.setTotalWidth(tableWidth.width); } } pdfPTable.setLockedWidth(true); // Table alignment ParagraphAlignment alignment = stylesDocument.getTableAlignment(table); if (alignment != null) { switch (alignment) { case LEFT: pdfPTable.setHorizontalAlignment(Element.ALIGN_LEFT); break; case RIGHT: pdfPTable.setHorizontalAlignment(Element.ALIGN_RIGHT); break; case CENTER: pdfPTable.setHorizontalAlignment(Element.ALIGN_CENTER); break; case BOTH: pdfPTable.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); break; default: break; } } // Table indentation Float indentation = stylesDocument.getTableIndentation(table); if (indentation != null) { pdfPTable.setPaddingLeft(indentation); } return pdfPTable; }
From source file:fr.opensagres.xdocreport.itext.extension.SimpleTable.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 ww . java 2s. c o m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("SimpleTable.pdf")); document.open(); PdfPTable table = new PdfPTable(2); PdfPCell cell; Paragraph p = new Paragraph("Text Text Text "); table.addCell("cell"); table.addCell(p); table.addCell("cell"); cell = new PdfPCell(p); p = new Paragraph("Text Text Text "); //Chunk c = new Chunk( "zzzzzzzzzz" ); //cell.setPadding( 0f ); //cell.getColumn().setAdjustFirstLine( false ); // make a room for borders //cell.setUseBorderPadding( false ); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(Color.red); cell.addElement(p); cell.setUseAscender(true); //cell.addElement(c ); // cell.setPaddingTop( 0f ); // cell.setPaddingLeft( 20f ); table.addCell(cell); //table.addCell( "cell" ); document.add(table); } catch (Exception de) { de.printStackTrace(); } document.close(); }
From source file:gov.utah.dts.det.ccl.documents.reporting.reports.InspectionsConductedReport.java
@Override public void render(Map<String, Object> context, OutputStream outputStream, FileDescriptor fileDescriptor) throws TemplateException { FindingCategoryType fCat = getFindingCategory(context); PickListValue insType = getInspectionType(context); List<Object[]> results = getResults(context); ReportTable<Integer> reportTable = new ReportTable<Integer>(); for (Object[] res : results) { String row = (String) res[1]; String column = (String) res[0]; Integer val = ((BigDecimal) res[2]).intValue(); reportTable.addRow(row);//from w ww . jav a2s. co m reportTable.addColumn(column); reportTable.addTableDataItem(row, column, val); } setFileName(context, fileDescriptor); Document document = new Document(PAGE_SIZE, 36, 36, 36, 36); try { PdfWriter.getInstance(document, outputStream); document.open(); StringBuilder sb = new StringBuilder(); if (insType != null) { sb.append(insType.getValue()); sb.append(" "); } sb.append("Inspections Conducted"); if (fCat != null) { sb.append(" With "); sb.append(fCat.getDisplayName()); sb.append(" Findings"); } Paragraph heading = new Paragraph(sb.toString()); heading.setAlignment(Element.ALIGN_CENTER); document.add(heading); Date startDate = (Date) context.get(DATE_RANGE_START_KEY); Date endDate = (Date) context.get(DATE_RANGE_END_KEY); clearStringBuilder(sb); if (startDate.compareTo(endDate) == 0) { sb.append("On "); sb.append(DATE_FORMATTER.format(startDate)); } else { sb.append(DATE_FORMATTER.format(startDate)); sb.append(" - "); sb.append(DATE_FORMATTER.format(endDate)); } Paragraph date = new Paragraph(sb.toString(), FONT); date.setAlignment(Element.ALIGN_RIGHT); document.add(date); PdfPTable table = new PdfPTable(reportTable.getColumns().size() + 2); table.setHeaderRows(1); table.setSpacingBefore(FONT_SIZE); table.setWidthPercentage(100f); setDefaultCellAttributes(table.getDefaultCell()); table.addCell(""); for (Iterator<String> itr = reportTable.getColumns().iterator(); itr.hasNext();) { table.addCell(getHeaderCell(itr.next())); } table.addCell(getHeaderCell("Total")); int[] colTotals = new int[reportTable.getColumns().size() + 1]; for (Iterator<String> rowItr = reportTable.getRows().iterator(); rowItr.hasNext();) { String row = rowItr.next(); table.addCell(getHeaderCell(row)); int total = 0; int idx = 0; for (Iterator<String> colItr = reportTable.getColumns().iterator(); colItr.hasNext();) { String column = colItr.next(); Integer value = reportTable.getTableDataItem(row, column); if (value == null) { table.addCell(getNumberCell("0")); } else { total += value; colTotals[idx] = colTotals[idx] + value; table.addCell(getNumberCell(value.toString())); } idx++; } table.addCell(getHeaderCell(Integer.toString(total))); colTotals[colTotals.length - 1] = colTotals[colTotals.length - 1] + total; idx++; } table.addCell(getHeaderCell("Total")); for (int i = 0; i < colTotals.length; i++) { table.addCell(getHeaderCell(Integer.toString(colTotals[i]))); } document.add(table); } catch (DocumentException de) { throw new TemplateException(de); } document.close(); }