/** Creates a new instance of IncCell */ public IncCell(String tag, ChainedProperties props) { cell = new PdfPCell(); String value = props["colspan"]; if (value != null) cell.Colspan = int.Parse(value); value = props["align"]; if (tag.Equals("th")) cell.HorizontalAlignment = Element.ALIGN_CENTER; if (value != null) { if (Util.EqualsIgnoreCase(value, "center")) cell.HorizontalAlignment = Element.ALIGN_CENTER; else if (Util.EqualsIgnoreCase(value, "right")) cell.HorizontalAlignment = Element.ALIGN_RIGHT; else if (Util.EqualsIgnoreCase(value, "left")) cell.HorizontalAlignment = Element.ALIGN_LEFT; else if (Util.EqualsIgnoreCase(value, "justify")) cell.HorizontalAlignment = Element.ALIGN_JUSTIFIED; } value = props["valign"]; cell.VerticalAlignment = Element.ALIGN_MIDDLE; if (value != null) { if (Util.EqualsIgnoreCase(value, "top")) cell.VerticalAlignment = Element.ALIGN_TOP; else if (Util.EqualsIgnoreCase(value, "bottom")) cell.VerticalAlignment = Element.ALIGN_BOTTOM; } value = props["border"]; float border = 0; if (value != null) border = float.Parse(value, NumberFormatInfo.InvariantInfo); cell.BorderWidth = border; value = props["cellpadding"]; if (value != null) cell.Padding = float.Parse(value, NumberFormatInfo.InvariantInfo); cell.UseDescender = true; value = props["bgcolor"]; cell.BackgroundColor = Markup.DecodeColor(value); }
/** Constructs a copy of a <CODE>PdfPTable</CODE>. * @param table the <CODE>PdfPTable</CODE> to be copied */ public PdfPTable(PdfPTable table) { CopyFormat(table); for (int k = 0; k < currentRow.Length; ++k) { if (table.currentRow[k] == null) break; currentRow[k] = new PdfPCell(table.currentRow[k]); } for (int k = 0; k < table.rows.Count; ++k) { PdfPRow row = (PdfPRow)(table.rows[k]); if (row != null) row = new PdfPRow(row); rows.Add(row); } }
/** * Copies the format of the sourceTable without copying the content. * @param sourceTable */ protected internal void CopyFormat(PdfPTable sourceTable) { relativeWidths = new float[sourceTable.NumberOfColumns]; absoluteWidths = new float[sourceTable.NumberOfColumns]; Array.Copy(sourceTable.relativeWidths, 0, relativeWidths, 0, NumberOfColumns); Array.Copy(sourceTable.absoluteWidths, 0, absoluteWidths, 0, NumberOfColumns); totalWidth = sourceTable.totalWidth; totalHeight = sourceTable.totalHeight; currentRowIdx = 0; tableEvent = sourceTable.tableEvent; runDirection = sourceTable.runDirection; defaultCell = new PdfPCell(sourceTable.defaultCell); currentRow = new PdfPCell[sourceTable.currentRow.Length]; isColspan = sourceTable.isColspan; splitRows = sourceTable.splitRows; spacingAfter = sourceTable.spacingAfter; spacingBefore = sourceTable.spacingBefore; headerRows = sourceTable.headerRows; footerRows = sourceTable.footerRows; lockedWidth = sourceTable.lockedWidth; extendLastRow = sourceTable.extendLastRow; headersInEvent = sourceTable.headersInEvent; widthPercentage = sourceTable.widthPercentage; splitLate = sourceTable.splitLate; skipFirstHeader = sourceTable.skipFirstHeader; skipLastFooter = sourceTable.skipLastFooter; horizontalAlignment = sourceTable.horizontalAlignment; keepTogether = sourceTable.keepTogether; complete = sourceTable.complete; }
/** * Creates a PdfPCell with these attributes. * @param rowAttributes * @return a PdfPCell based on these attributes. */ public PdfPCell CreatePdfPCell(SimpleCell rowAttributes) { PdfPCell cell = new PdfPCell(); cell.Border = NO_BORDER; SimpleCell tmp = new SimpleCell(CELL); tmp.Spacing_left = spacing_left; tmp.Spacing_right = spacing_right; tmp.Spacing_top = spacing_top; tmp.Spacing_bottom = spacing_bottom; tmp.CloneNonPositionParameters(rowAttributes); tmp.SoftCloneNonPositionParameters(this); cell.CellEvent = tmp; cell.HorizontalAlignment = rowAttributes.horizontalAlignment; cell.VerticalAlignment = rowAttributes.verticalAlignment; cell.UseAscender = rowAttributes.useAscender; cell.UseBorderPadding = rowAttributes.useBorderPadding; cell.UseDescender = rowAttributes.useDescender; cell.Colspan = colspan; if (horizontalAlignment != Element.ALIGN_UNDEFINED) cell.HorizontalAlignment = horizontalAlignment; if (verticalAlignment != Element.ALIGN_UNDEFINED) cell.VerticalAlignment = verticalAlignment; if (useAscender) cell.UseAscender = useAscender; if (useBorderPadding) cell.UseBorderPadding = useBorderPadding; if (useDescender) cell.UseDescender = useDescender; float p; float sp_left = spacing_left; if (float.IsNaN(sp_left)) sp_left = 0f; float sp_right = spacing_right; if (float.IsNaN(sp_right)) sp_right = 0f; float sp_top = spacing_top; if (float.IsNaN(sp_top)) sp_top = 0f; float sp_bottom = spacing_bottom; if (float.IsNaN(sp_bottom)) sp_bottom = 0f; p = padding_left; if (float.IsNaN(p)) p = 0f; cell.PaddingLeft = p + sp_left; p = padding_right; if (float.IsNaN(p)) p = 0f; cell.PaddingRight = p + sp_right; p = padding_top; if (float.IsNaN(p)) p = 0f; cell.PaddingTop = p + sp_top; p = padding_bottom; if (float.IsNaN(p)) p = 0f; cell.PaddingBottom = p + sp_bottom; foreach (IElement element in content) { cell.AddElement(element); } return cell; }
/** * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[]) */ public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { float sp_left = spacing_left; if (float.IsNaN(sp_left)) sp_left = 0f; float sp_right = spacing_right; if (float.IsNaN(sp_right)) sp_right = 0f; float sp_top = spacing_top; if (float.IsNaN(sp_top)) sp_top = 0f; float sp_bottom = spacing_bottom; if (float.IsNaN(sp_bottom)) sp_bottom = 0f; Rectangle rect = new Rectangle(position.GetLeft(sp_left), position.GetBottom(sp_bottom), position.GetRight(sp_right), position.GetTop(sp_top)); rect.CloneNonPositionParameters(this); canvases[PdfPTable.BACKGROUNDCANVAS].Rectangle(rect); rect.BackgroundColor = null; canvases[PdfPTable.LINECANVAS].Rectangle(rect); }
/** * Makes a copy of an existing row. * * @param row */ public PdfPRow(PdfPRow row) { maxHeight = row.maxHeight; calculated = row.calculated; cells = new PdfPCell[row.cells.Length]; for (int k = 0; k < cells.Length; ++k) { if (row.cells[k] != null) cells[k] = new PdfPCell(row.cells[k]); } widths = new float[cells.Length]; Array.Copy(row.widths, 0, widths, 0, cells.Length); InitExtraHeights(); }
/** * Adds an element. Elements supported are <CODE>Paragraph</CODE>, * <CODE>List</CODE>, <CODE>PdfPTable</CODE>, <CODE>Image</CODE> and * <CODE>Graphic</CODE>. * <p> * It removes all the text placed with <CODE>addText()</CODE>. * @param element the <CODE>Element</CODE> */ public void AddElement(IElement element) { if (element == null) return; if (element is Image) { Image img = (Image)element; PdfPTable t = new PdfPTable(1); float w = img.WidthPercentage; if (w == 0) { t.TotalWidth = img.ScaledWidth; t.LockedWidth = true; } else t.WidthPercentage = w; t.SpacingAfter = img.SpacingAfter; t.SpacingBefore = img.SpacingBefore; switch (img.Alignment) { case Image.LEFT_ALIGN: t.HorizontalAlignment = Element.ALIGN_LEFT; break; case Image.RIGHT_ALIGN: t.HorizontalAlignment = Element.ALIGN_RIGHT; break; default: t.HorizontalAlignment = Element.ALIGN_CENTER; break; } PdfPCell c = new PdfPCell(img, true); c.Padding = 0; c.Border = img.Border; c.BorderColor = img.BorderColor; c.BorderWidth = img.BorderWidth; c.BackgroundColor = img.BackgroundColor; t.AddCell(c); element = t; } if (element.Type == Element.CHUNK) { element = new Paragraph((Chunk)element); } else if (element.Type == Element.PHRASE) { element = new Paragraph((Phrase)element); } if (element is SimpleTable) { try { element = ((SimpleTable)element).CreatePdfPTable(); } catch (DocumentException) { throw new ArgumentException("Element not allowed."); } } else if (element.Type != Element.PARAGRAPH && element.Type != Element.LIST && element.Type != Element.PTABLE && element.Type != Element.YMARK) throw new ArgumentException("Element not allowed."); if (!composite) { composite = true; compositeElements = new ArrayList(); bidiLine = null; waitPhrase = null; } compositeElements.Add(element); }
/** Constructs a deep copy of a <CODE>PdfPCell</CODE>. * @param cell the <CODE>PdfPCell</CODE> to duplicate */ public PdfPCell(PdfPCell cell) : base(cell.llx, cell.lly, cell.urx, cell.ury) { CloneNonPositionParameters(cell); verticalAlignment = cell.verticalAlignment; paddingLeft = cell.paddingLeft; paddingRight = cell.paddingRight; paddingTop = cell.paddingTop; paddingBottom = cell.paddingBottom; phrase = cell.phrase; fixedHeight = cell.fixedHeight; minimumHeight = cell.minimumHeight; noWrap = cell.noWrap; colspan = cell.colspan; rowspan = cell.rowspan; if (cell.table != null) table = new PdfPTable(cell.table); image = Image.GetInstance(cell.image); cellEvent = cell.cellEvent; useDescender = cell.useDescender; column = ColumnText.Duplicate(cell.column); useBorderPadding = cell.useBorderPadding; rotation = cell.rotation; }
/** * Imports the Cell properties into the RtfCell * * @param cell The PdfPCell to import * @since 2.1.3 */ private void ImportCell(PdfPCell cell) { this.content = new ArrayList(); if (cell == null) { this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, this.parentRow.GetParentTable().GetBorders()); return; } // padding this.cellPadding = (int) this.parentRow.GetParentTable().GetCellPadding(); this.cellPaddingBottom = cell.PaddingBottom; this.cellPaddingTop = cell.PaddingTop; this.cellPaddingRight = cell.PaddingRight; this.cellPaddingLeft = cell.PaddingLeft; // BORDERS this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, cell.Border, cell.BorderWidth, cell.BorderColor); // border colors this.border = cell.Border; this.borderColor = cell.BorderColor; this.borderColorBottom = cell.BorderColorBottom; this.borderColorTop = cell.BorderColorTop; this.borderColorLeft = cell.BorderColorLeft; this.borderColorRight = cell.BorderColorRight; // border widths this.borderWidth = cell.BorderWidth; this.borderWidthBottom = cell.BorderWidthBottom; this.borderWidthTop = cell.BorderWidthTop; this.borderWidthLeft = cell.BorderWidthLeft; this.borderWidthRight = cell.BorderWidthRight; this.colspan = cell.Colspan; this.rowspan = 1; //cell.GetRowspan(); // if (cell.GetRowspan() > 1) { // this.mergeType = MERGE_VERT_PARENT; // } this.verticalAlignment = cell.VerticalAlignment; if (cell.BackgroundColor == null) { this.backgroundColor = new RtfColor(this.document, 255, 255, 255); } else { this.backgroundColor = new RtfColor(this.document, cell.BackgroundColor); } // does it have column composite info? ArrayList compositeElements = cell.CompositeElements; if (compositeElements != null) { // does it have column info? Paragraph container = null; foreach (IElement element in compositeElements) { try { // should we wrap it in a paragraph if (!(element is Paragraph) && !(element is Legacy.Text.List)) { if (container != null) { container.Add(element); } else { container = new Paragraph(); container.Alignment = cell.HorizontalAlignment; container.Add(element); } } else { IRtfBasicElement[] rtfElements = null; if (container != null) { rtfElements = this.document.GetMapper().MapElement(container); for (int i = 0; i < rtfElements.Length; i++) { rtfElements[i].SetInTable(true); this.content.Add(rtfElements[i]); } container = null; } // if horizontal alignment is undefined overwrite // with that of enclosing cell if (element is Paragraph && ((Paragraph) element).Alignment == Element.ALIGN_UNDEFINED) { ((Paragraph) element).Alignment = cell.HorizontalAlignment; } rtfElements = this.document.GetMapper().MapElement(element); for (int i = 0; i < rtfElements.Length; i++) { rtfElements[i].SetInTable(true); this.content.Add(rtfElements[i]); } } } catch (DocumentException) { } } if (container != null) { try { IRtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(container); for (int i = 0; i < rtfElements.Length; i++) { rtfElements[i].SetInTable(true); this.content.Add(rtfElements[i]); } } catch (DocumentException) { } } } // does it have image info? Image img = cell.Image; if (img != null) { try { IRtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(img); for (int i = 0; i < rtfElements.Length; i++) { rtfElements[i].SetInTable(true); this.content.Add(rtfElements[i]); } } catch (DocumentException) { } } // does it have phrase info? Phrase phrase = cell.Phrase; if (phrase != null) { try { IRtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(phrase); for (int i = 0; i < rtfElements.Length; i++) { rtfElements[i].SetInTable(true); this.content.Add(rtfElements[i]); } } catch (DocumentException) { } } // does it have table info? PdfPTable table = cell.Table; if (table != null) { this.Add(table); // try { // RtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(table); // for (int i = 0; i < rtfElements.length; i++) { // rtfElements[i].SetInTable(true); // this.content.Add(rtfElements[i]); // } // } catch (DocumentException e) { // // TODO Auto-generated catch block // e.PrintStackTrace(); // } } }
/** * Constructs a RtfCell based on a Cell. * * @param doc The RtfDocument this RtfCell belongs to * @param row The RtfRow this RtfCell lies in * @param cell The PdfPCell to base this RtfCell on * @since 2.1.3 */ protected internal RtfCell(RtfDocument doc, RtfRow row, PdfPCell cell) { this.document = doc; this.parentRow = row; ImportCell(cell); }
public void AddCol(PdfPCell cell) { if (cols == null) cols = new ArrayList(); cols.Add(cell); }
/** * Constructs a new PdfPRow with the cells in the array that was passed * as a parameter. * * @param cells */ public PdfPRow(PdfPCell[] cells) { this.cells = cells; widths = new float[cells.Length]; InitExtraHeights(); }
/** * Writes the border and background of one cell in the row. * * @param xPos The x-coordinate where the table starts on the canvas * @param yPos The y-coordinate where the table starts on the canvas * @param currentMaxHeight The height of the cell to be drawn. * @param cell * @param canvases * @since 2.1.6 extra parameter currentMaxHeight */ public void WriteBorderAndBackground(float xPos, float yPos, float currentMaxHeight, PdfPCell cell, PdfContentByte[] canvases) { Color background = cell.BackgroundColor; if (background != null || cell.HasBorders()) { // Add xPos resp. yPos to the cell's coordinates for absolute coordinates float right = cell.Right + xPos; float top = cell.Top + yPos; float left = cell.Left + xPos; float bottom = top - currentMaxHeight; if (background != null) { PdfContentByte backgr = canvases[PdfPTable.BACKGROUNDCANVAS]; backgr.SetColorFill(background); backgr.Rectangle(left, bottom, right - left, top - bottom); backgr.Fill(); } if (cell.HasBorders()) { Rectangle newRect = new Rectangle(left, bottom, right, top); // Clone non-position parameters except for the background color newRect.CloneNonPositionParameters(cell); newRect.BackgroundColor = null; // Write the borders on the line canvas PdfContentByte lineCanvas = canvases[PdfPTable.LINECANVAS]; lineCanvas.Rectangle(newRect); } } }
/** * Splits a row to newHeight. * The returned row is the remainder. It will return null if the newHeight * was so small that only an empty row would result. * * @param new_height the new height * @return the remainder row or null if the newHeight was so small that only * an empty row would result */ public PdfPRow SplitRow(PdfPTable table, int rowIndex, float new_height) { PdfPCell[] newCells = new PdfPCell[cells.Length]; float[] fixHs = new float[cells.Length]; float[] minHs = new float[cells.Length]; bool allEmpty = true; for (int k = 0; k < cells.Length; ++k) { float newHeight = new_height; PdfPCell cell = cells[k]; if (cell == null) { int index = rowIndex; if (table.RowSpanAbove(index, k)) { newHeight += table.GetRowHeight(index); while (table.RowSpanAbove(--index, k)) { newHeight += table.GetRowHeight(index); } PdfPRow row = table.GetRow(index); if (row != null && row.GetCells()[k] != null) { newCells[k] = new PdfPCell(row.GetCells()[k]); newCells[k].ConsumeHeight(newHeight); newCells[k].Rowspan = row.GetCells()[k].Rowspan - rowIndex + index; allEmpty = false; } } continue; } fixHs[k] = cell.FixedHeight; minHs[k] = cell.MinimumHeight; Image img = cell.Image; PdfPCell newCell = new PdfPCell(cell); if (img != null) { if (newHeight > cell.EffectivePaddingBottom + cell.EffectivePaddingTop + 2) { newCell.Phrase = null; allEmpty = false; } } else { float y; ColumnText ct = ColumnText.Duplicate(cell.Column); float left = cell.Left + cell.EffectivePaddingLeft; float bottom = cell.Top + cell.EffectivePaddingBottom - newHeight; float right = cell.Right - cell.EffectivePaddingRight; float top = cell.Top - cell.EffectivePaddingTop; switch (cell.Rotation) { case 90: case 270: y = SetColumn(ct, bottom, left, top, right); break; default: y = SetColumn(ct, left, bottom, cell.NoWrap ? RIGHT_LIMIT : right, top); break; } int status; status = ct.Go(true); bool thisEmpty = (ct.YLine == y); if (thisEmpty) { newCell.Column = ColumnText.Duplicate(cell.Column); ct.FilledWidth = 0; } else if ((status & ColumnText.NO_MORE_TEXT) == 0) { newCell.Column = ct; ct.FilledWidth = 0; } else newCell.Phrase = null; allEmpty = (allEmpty && thisEmpty); } newCells[k] = newCell; cell.FixedHeight = newHeight; } if (allEmpty) { for (int k = 0; k < cells.Length; ++k) { PdfPCell cell = cells[k]; if (cell == null) continue; if (fixHs[k] > 0) cell.FixedHeight = fixHs[k]; else cell.MinimumHeight = minHs[k]; } return null; } CalculateHeights(); PdfPRow split = new PdfPRow(newCells); split.widths = (float[]) widths.Clone(); split.CalculateHeights(); return split; }
/** * Adds a cell element. * * @param cell the cell element */ public void AddCell(PdfPCell cell) { rowCompleted = false; PdfPCell ncell = new PdfPCell(cell); int colspan = ncell.Colspan; colspan = Math.Max(colspan, 1); colspan = Math.Min(colspan, currentRow.Length - currentRowIdx); ncell.Colspan = colspan; if (colspan != 1) isColspan = true; int rdir = ncell.RunDirection; if (rdir == PdfWriter.RUN_DIRECTION_DEFAULT) ncell.RunDirection = runDirection; SkipColsWithRowspanAbove(); bool cellAdded = false; if (currentRowIdx < currentRow.Length) { currentRow[currentRowIdx] = ncell; currentRowIdx += colspan; cellAdded = true; } SkipColsWithRowspanAbove(); if (currentRowIdx >= currentRow.Length) { int numCols = NumberOfColumns; if (runDirection == PdfWriter.RUN_DIRECTION_RTL) { PdfPCell[] rtlRow = new PdfPCell[numCols]; int rev = currentRow.Length; for (int k = 0; k < currentRow.Length; ++k) { PdfPCell rcell = currentRow[k]; int cspan = rcell.Colspan; rev -= cspan; rtlRow[rev] = rcell; k += cspan - 1; } currentRow = rtlRow; } PdfPRow row = new PdfPRow(currentRow); if (totalWidth > 0) { row.SetWidths(absoluteWidths); totalHeight += row.MaxHeights; } rows.Add(row); currentRow = new PdfPCell[numCols]; currentRowIdx = 0; rowCompleted = true; } if (!cellAdded) { currentRow[currentRowIdx] = ncell; currentRowIdx += colspan; } }
/** Constructs a <CODE>PdfPCell</CODE> with a <CODE>PdfPtable</CODE>. * This constructor allows nested tables. * * @param table The <CODE>PdfPTable</CODE> * @param style The style to apply to the cell (you could use getDefaultCell()) * @since 2.1.0 */ public PdfPCell(PdfPTable table, PdfPCell style) : base(0, 0, 0, 0) { borderWidth = 0.5f; border = BOX; column.SetLeading(0, 1); this.table = table; table.WidthPercentage = 100; table.ExtendLastRow = true; column.AddElement(table); if (style != null) { CloneNonPositionParameters(style); verticalAlignment = style.verticalAlignment; paddingLeft = style.paddingLeft; paddingRight = style.paddingRight; paddingTop = style.paddingTop; paddingBottom = style.paddingBottom; colspan = style.colspan; rowspan = style.rowspan; cellEvent = style.cellEvent; useDescender = style.useDescender; useBorderPadding = style.useBorderPadding; rotation = style.rotation; } else { Padding = 0; } }
/** * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[]) */ public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { foreach (IPdfPCellEvent eventa in events) { eventa.CellLayout(cell, position, canvases); } }
/** * Creates a PdfPCell based on this Cell object. * @return a PdfPCell * @throws BadElementException */ public PdfPCell CreatePdfPCell() { if (rowspan > 1) throw new BadElementException("PdfPCells can't have a rowspan > 1"); if (IsTable()) return new PdfPCell(((Table)arrayList[0]).CreatePdfPTable()); PdfPCell cell = new PdfPCell(); cell.VerticalAlignment = verticalAlignment; cell.HorizontalAlignment = horizontalAlignment; cell.Colspan = colspan; cell.UseBorderPadding = useBorderPadding; cell.UseDescender = useDescender; cell.SetLeading(Leading, 0); cell.CloneNonPositionParameters(this); cell.NoWrap = noWrap; foreach (IElement i in Elements) { if (i.Type == Element.PHRASE || i.Type == Element.PARAGRAPH) { Paragraph p = new Paragraph((Phrase)i); p.Alignment = horizontalAlignment; cell.AddElement(p); } else cell.AddElement(i); } return cell; }
/** * Create a PdfPTable based on this Table object. * @return a PdfPTable object * @throws BadElementException */ public PdfPTable CreatePdfPTable() { if (!convert2pdfptable) { throw new BadElementException("No error, just an old style table"); } AutoFillEmptyCells = true; Complete(); PdfPTable pdfptable = new PdfPTable(widths); pdfptable.ElementComplete = complete; if (NotAddedYet) pdfptable.SkipFirstHeader = true; SimpleTable t_evt = new SimpleTable(); t_evt.CloneNonPositionParameters(this); t_evt.Cellspacing = cellspacing; pdfptable.TableEvent = t_evt; pdfptable.HeaderRows = lastHeaderRow + 1; pdfptable.SplitLate = cellsFitPage; pdfptable.KeepTogether = tableFitsPage; if (!float.IsNaN(offset)) { pdfptable.SpacingBefore = offset; } pdfptable.HorizontalAlignment = alignment; if (locked) { pdfptable.TotalWidth = width; pdfptable.LockedWidth = true; } else { pdfptable.WidthPercentage = width; } foreach (Row row in this) { IElement cell; PdfPCell pcell; for (int i = 0; i < row.Columns; i++) { if ((cell = (IElement)row.GetCell(i)) != null) { if (cell is Table) { pcell = new PdfPCell(((Table)cell).CreatePdfPTable()); } else if (cell is Cell) { pcell = ((Cell)cell).CreatePdfPCell(); pcell.Padding = cellpadding + cellspacing / 2f; SimpleCell c_evt = new SimpleCell(SimpleCell.CELL); c_evt.CloneNonPositionParameters((Cell)cell); c_evt.Spacing = cellspacing * 2f; pcell.CellEvent = c_evt; } else { pcell = new PdfPCell(); } pdfptable.AddCell(pcell); } } } return pdfptable; }
/** * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[]) */ public void CellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvases) { if (cellField == null || (fieldWriter == null && parent == null)) throw new ArgumentException("You have used the wrong constructor for this FieldPositioningEvents class."); cellField.Put(PdfName.RECT, new PdfRectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding))); if (parent == null) fieldWriter.AddAnnotation(cellField); else parent.AddKid(cellField); }
/** * Signals that an <CODE>Element</CODE> was added to the <CODE>Document</CODE>. * * @param element the element to add * @return <CODE>true</CODE> if the element was added, <CODE>false</CODE> if not. * @throws DocumentException when a document isn't open yet, or has been closed */ public override bool Add(IElement element) { if (writer != null && writer.IsPaused()) { return false; } switch (element.Type) { // Information (headers) case Element.HEADER: info.Addkey(((Meta)element).Name, ((Meta)element).Content); break; case Element.TITLE: info.AddTitle(((Meta)element).Content); break; case Element.SUBJECT: info.AddSubject(((Meta)element).Content); break; case Element.KEYWORDS: info.AddKeywords(((Meta)element).Content); break; case Element.AUTHOR: info.AddAuthor(((Meta)element).Content); break; case Element.CREATOR: info.AddCreator(((Meta)element).Content); break; case Element.PRODUCER: // you can not change the name of the producer info.AddProducer(); break; case Element.CREATIONDATE: // you can not set the creation date, only reset it info.AddCreationDate(); break; // content (text) case Element.CHUNK: { // if there isn't a current line available, we make one if (line == null) { CarriageReturn(); } // we cast the element to a chunk PdfChunk chunk = new PdfChunk((Chunk) element, anchorAction); // we try to add the chunk to the line, until we succeed { PdfChunk overflow; while ((overflow = line.Add(chunk)) != null) { CarriageReturn(); chunk = overflow; chunk.TrimFirstSpace(); } } pageEmpty = false; if (chunk.IsAttribute(Chunk.NEWPAGE)) { NewPage(); } break; } case Element.ANCHOR: { leadingCount++; Anchor anchor = (Anchor) element; String url = anchor.Reference; leading = anchor.Leading; if (url != null) { anchorAction = new PdfAction(url); } // we process the element element.Process(this); anchorAction = null; leadingCount--; break; } case Element.ANNOTATION: { if (line == null) { CarriageReturn(); } Annotation annot = (Annotation) element; Rectangle rect = new Rectangle(0, 0); if (line != null) rect = new Rectangle(annot.GetLlx(IndentRight - line.WidthLeft), annot.GetLly(IndentTop - currentHeight), annot.GetUrx(IndentRight - line.WidthLeft + 20), annot.GetUry(IndentTop - currentHeight - 20)); PdfAnnotation an = PdfAnnotationsImp.ConvertAnnotation(writer, annot, rect); annotationsImp.AddPlainAnnotation(an); pageEmpty = false; break; } case Element.PHRASE: { leadingCount++; // we cast the element to a phrase and set the leading of the document leading = ((Phrase) element).Leading; // we process the element element.Process(this); leadingCount--; break; } case Element.PARAGRAPH: { leadingCount++; // we cast the element to a paragraph Paragraph paragraph = (Paragraph) element; AddSpacing(paragraph.SpacingBefore, leading, paragraph.Font); // we adjust the parameters of the document alignment = paragraph.Alignment; leading = paragraph.TotalLeading; CarriageReturn(); // we don't want to make orphans/widows if (currentHeight + line.Height + leading > IndentTop - IndentBottom) { NewPage(); } indentation.indentLeft += paragraph.IndentationLeft; indentation.indentRight += paragraph.IndentationRight; CarriageReturn(); IPdfPageEvent pageEvent = writer.PageEvent; if (pageEvent != null && !isSectionTitle) pageEvent.OnParagraph(writer, this, IndentTop - currentHeight); // if a paragraph has to be kept together, we wrap it in a table object if (paragraph.KeepTogether) { CarriageReturn(); PdfPTable table = new PdfPTable(1); table.WidthPercentage = 100f; PdfPCell cell = new PdfPCell(); cell.AddElement(paragraph); cell.Border = Rectangle.NO_BORDER; cell.Padding = 0; table.AddCell(cell); indentation.indentLeft -= paragraph.IndentationLeft; indentation.indentRight -= paragraph.IndentationRight; this.Add(table); indentation.indentLeft += paragraph.IndentationLeft; indentation.indentRight += paragraph.IndentationRight; } else { line.SetExtraIndent(paragraph.FirstLineIndent); element.Process(this); CarriageReturn(); AddSpacing(paragraph.SpacingAfter, paragraph.TotalLeading, paragraph.Font); } if (pageEvent != null && !isSectionTitle) pageEvent.OnParagraphEnd(writer, this, IndentTop - currentHeight); alignment = Element.ALIGN_LEFT; indentation.indentLeft -= paragraph.IndentationLeft; indentation.indentRight -= paragraph.IndentationRight; CarriageReturn(); leadingCount--; break; } case Element.SECTION: case Element.CHAPTER: { // Chapters and Sections only differ in their constructor // so we cast both to a Section Section section = (Section) element; IPdfPageEvent pageEvent = writer.PageEvent; bool hasTitle = section.NotAddedYet && section.Title != null; // if the section is a chapter, we begin a new page if (section.TriggerNewPage) { NewPage(); } if (hasTitle) { float fith = IndentTop - currentHeight; int rotation = pageSize.Rotation; if (rotation == 90 || rotation == 180) fith = pageSize.Height - fith; PdfDestination destination = new PdfDestination(PdfDestination.FITH, fith); while (currentOutline.Level >= section.Depth) { currentOutline = currentOutline.Parent; } PdfOutline outline = new PdfOutline(currentOutline, destination, section.GetBookmarkTitle(), section.BookmarkOpen); currentOutline = outline; } // some values are set CarriageReturn(); indentation.sectionIndentLeft += section.IndentationLeft; indentation.sectionIndentRight += section.IndentationRight; if (section.NotAddedYet && pageEvent != null) if (element.Type == Element.CHAPTER) pageEvent.OnChapter(writer, this, IndentTop - currentHeight, section.Title); else pageEvent.OnSection(writer, this, IndentTop - currentHeight, section.Depth, section.Title); // the title of the section (if any has to be printed) if (hasTitle) { isSectionTitle = true; Add(section.Title); isSectionTitle = false; } indentation.sectionIndentLeft += section.Indentation; // we process the section element.Process(this); // some parameters are set back to normal again indentation.sectionIndentLeft -= (section.IndentationLeft + section.Indentation); indentation.sectionIndentRight -= section.IndentationRight; if (section.ElementComplete && pageEvent != null) if (element.Type == Element.CHAPTER) pageEvent.OnChapterEnd(writer, this, IndentTop - currentHeight); else pageEvent.OnSectionEnd(writer, this, IndentTop - currentHeight); break; } case Element.LIST: { // we cast the element to a List List list = (List) element; if (list.Alignindent) { list.NormalizeIndentation(); } // we adjust the document indentation.listIndentLeft += list.IndentationLeft; indentation.indentRight += list.IndentationRight; // we process the items in the list element.Process(this); // some parameters are set back to normal again indentation.listIndentLeft -= list.IndentationLeft; indentation.indentRight -= list.IndentationRight; CarriageReturn(); break; } case Element.LISTITEM: { leadingCount++; // we cast the element to a ListItem ListItem listItem = (ListItem) element; AddSpacing(listItem.SpacingBefore, leading, listItem.Font); // we adjust the document alignment = listItem.Alignment; indentation.listIndentLeft += listItem.IndentationLeft; indentation.indentRight += listItem.IndentationRight; leading = listItem.TotalLeading; CarriageReturn(); // we prepare the current line to be able to show us the listsymbol line.ListItem = listItem; // we process the item element.Process(this); AddSpacing(listItem.SpacingAfter, listItem.TotalLeading, listItem.Font); // if the last line is justified, it should be aligned to the left if (line.HasToBeJustified()) { line.ResetAlignment(); } // some parameters are set back to normal again CarriageReturn(); indentation.listIndentLeft -= listItem.IndentationLeft; indentation.indentRight -= listItem.IndentationRight; leadingCount--; break; } case Element.RECTANGLE: { Rectangle rectangle = (Rectangle) element; graphics.Rectangle(rectangle); pageEmpty = false; break; } case Element.PTABLE: { PdfPTable ptable = (PdfPTable)element; if (ptable.Size <= ptable.HeaderRows) break; //nothing to do // before every table, we add a new line and flush all lines EnsureNewLine(); FlushLines(); AddPTable(ptable); pageEmpty = false; NewLine(); break; } case Element.MULTI_COLUMN_TEXT: { EnsureNewLine(); FlushLines(); MultiColumnText multiText = (MultiColumnText) element; float height = multiText.Write(writer.DirectContent, this, IndentTop - currentHeight); currentHeight += height; text.MoveText(0, -1f* height); pageEmpty = false; break; } case Element.TABLE : { if (element is SimpleTable) { PdfPTable ptable = ((SimpleTable)element).CreatePdfPTable(); if (ptable.Size <= ptable.HeaderRows) break; //nothing to do // before every table, we add a new line and flush all lines EnsureNewLine(); FlushLines(); AddPTable(ptable); pageEmpty = false; break; } else if (element is Table) { try { PdfPTable ptable = ((Table)element).CreatePdfPTable(); if (ptable.Size <= ptable.HeaderRows) break; //nothing to do // before every table, we add a new line and flush all lines EnsureNewLine(); FlushLines(); AddPTable(ptable); pageEmpty = false; break; } catch (BadElementException) { // constructing the PdfTable // Before the table, add a blank line using offset or default leading float offset = ((Table)element).Offset; if (float.IsNaN(offset)) offset = leading; CarriageReturn(); lines.Add(new PdfLine(IndentLeft, IndentRight, alignment, offset)); currentHeight += offset; AddPdfTable((Table)element); } } else { return false; } break; } case Element.JPEG: case Element.JPEG2000: case Element.JBIG2: case Element.IMGRAW: case Element.IMGTEMPLATE: { //carriageReturn(); suggestion by Marc Campforts Add((Image) element); break; } case Element.YMARK: { IDrawInterface zh = (IDrawInterface)element; zh.Draw(graphics, IndentLeft, IndentBottom, IndentRight, IndentTop, IndentTop - currentHeight - (leadingCount > 0 ? leading : 0)); pageEmpty = false; break; } case Element.MARKED: { MarkedObject mo; if (element is MarkedSection) { mo = ((MarkedSection)element).Title; if (mo != null) { mo.Process(this); } } mo = (MarkedObject)element; mo.Process(this); break; } default: return false; } lastElementType = element.Type; return true; }