/** 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; id = cell.id; role = cell.role; if (cell.accessibleAttributes != null) accessibleAttributes = new Dictionary<PdfName, PdfObject>(cell.accessibleAttributes); headers = cell.headers; }
/** * Add a page event to the forwarder. * @param event an event that has to be added to the forwarder. */ virtual public void AddCellEvent(IPdfPCellEvent eventa) { events.Add(eventa); }
public void Write(Stream stream) { press = new PressPreview(); // step 1 using (Document document = new Document(PageSize.A4.Rotate())) { // step 2 PdfWriter.GetInstance(document, stream); // step 3 document.Open(); // step 4 List<string> days = PojoFactory.GetDays(); foreach (string day in days) { document.Add(GetTable(day)); document.NewPage(); } } }
/** 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; } }
/* * end inner class */ // --------------------------------------------------------------------------- /** * Initializes the fonts and collections. */ public PdfCalendar() : base() { tableBackground = new TableBackground(); cellBackground = new CellBackground(); roundRectangle = new RoundRectangle(new int[] { 0xFF, 0x00, 0xFF, 0x00 }); whiteRectangle = new RoundRectangle(new int[] { 0x00, 0x00, 0x00, 0x00 }); }
/** * Writes a number of cells (not necessarily all cells). * * @param colStart The first column to be written. * Remember that the column index starts with 0. * @param colEnd The last column to be written. * Remember that the column index starts with 0. * If -1, all the columns to the end are written. * @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 reusable if set to false, the content in the cells is "consumed"; * if true, you can reuse the cells, the row, the parent table as many times you want. * @since 5.1.0 added the reusable parameter */ public void WriteCells(int colStart, int colEnd, float xPos, float yPos, PdfContentByte[] canvases, bool reusable) { if (!calculated) { CalculateHeights(); } if (colEnd < 0) { colEnd = cells.Length; } else { colEnd = Math.Min(colEnd, cells.Length); } if (colStart < 0) { colStart = 0; } if (colStart >= colEnd) { return; } int newStart; for (newStart = colStart; newStart >= 0; --newStart) { if (cells[newStart] != null) { break; } if (newStart > 0) { xPos -= widths[newStart - 1]; } } if (newStart < 0) { newStart = 0; } if (cells[newStart] != null) { xPos -= cells[newStart].Left; } if (IsTagged(canvases[PdfPTable.TEXTCANVAS])) { canvases[PdfPTable.TEXTCANVAS].OpenMCBlock(this); } for (int k = newStart; k < colEnd; ++k) { PdfPCell cell = cells[k]; if (cell == null) { continue; } if (IsTagged(canvases[PdfPTable.TEXTCANVAS])) { canvases[PdfPTable.TEXTCANVAS].OpenMCBlock(cell); } float currentMaxHeight = maxHeight + extraHeights[k]; WriteBorderAndBackground(xPos, yPos, currentMaxHeight, cell, canvases); Image img = cell.Image; float tly = cell.Top + yPos - cell.EffectivePaddingTop; if (cell.Height <= currentMaxHeight) { switch (cell.VerticalAlignment) { case Element.ALIGN_BOTTOM: tly = cell.Top + yPos - currentMaxHeight + cell.Height - cell.EffectivePaddingTop; break; case Element.ALIGN_MIDDLE: tly = cell.Top + yPos + (cell.Height - currentMaxHeight) / 2 - cell.EffectivePaddingTop; break; default: break; } } if (img != null) { if (cell.Rotation != 0) { img = Image.GetInstance(img); img.Rotation = img.GetImageRotation() + (float)(cell.Rotation * Math.PI / 180.0); } bool vf = false; if (cell.Height > currentMaxHeight) { if (!img.ScaleToFitLineWhenOverflow) { continue; } img.ScalePercent(100); float scale = (currentMaxHeight - cell.EffectivePaddingTop - cell .EffectivePaddingBottom) / img.ScaledHeight; img.ScalePercent(scale * 100); vf = true; } float left = cell.Left + xPos + cell.EffectivePaddingLeft; if (vf) { switch (cell.HorizontalAlignment) { case Element.ALIGN_CENTER: left = xPos + (cell.Left + cell.EffectivePaddingLeft + cell.Right - cell.EffectivePaddingRight - img .ScaledWidth) / 2; break; case Element.ALIGN_RIGHT: left = xPos + cell.Right - cell.EffectivePaddingRight - img.ScaledWidth; break; default: break; } tly = cell.Top + yPos - cell.EffectivePaddingTop; } img.SetAbsolutePosition(left, tly - img.ScaledHeight); if (IsTagged(canvases[PdfPTable.TEXTCANVAS])) { canvases[PdfPTable.TEXTCANVAS].OpenMCBlock(img); } canvases[PdfPTable.TEXTCANVAS].AddImage(img); if (IsTagged(canvases[PdfPTable.TEXTCANVAS])) { canvases[PdfPTable.TEXTCANVAS].CloseMCBlock(img); } } else { // rotation sponsored by Connection GmbH if (cell.Rotation == 90 || cell.Rotation == 270) { float netWidth = currentMaxHeight - cell.EffectivePaddingTop - cell.EffectivePaddingBottom; float netHeight = cell.Width - cell.EffectivePaddingLeft - cell.EffectivePaddingRight; ColumnText ct = ColumnText.Duplicate(cell.Column); ct.Canvases = canvases; ct.SetSimpleColumn(0, 0, netWidth + 0.001f, -netHeight); ct.Go(true); float calcHeight = -ct.YLine; if (netWidth <= 0 || netHeight <= 0) { calcHeight = 0; } if (calcHeight > 0) { if (cell.UseDescender) { calcHeight -= ct.Descender; } if (reusable) { ct = ColumnText.Duplicate(cell.Column); } else { ct = cell.Column; } ct.Canvases = canvases; ct.SetSimpleColumn(-0.003f, -0.001f, netWidth + 0.003f, calcHeight); float pivotX; float pivotY; if (cell.Rotation == 90) { pivotY = cell.Top + yPos - currentMaxHeight + cell.EffectivePaddingBottom; switch (cell.VerticalAlignment) { case Element.ALIGN_BOTTOM: pivotX = cell.Left + xPos + cell.Width - cell.EffectivePaddingRight; break; case Element.ALIGN_MIDDLE: pivotX = cell.Left + xPos + (cell.Width + cell.EffectivePaddingLeft - cell.EffectivePaddingRight + calcHeight) / 2; break; default: //top pivotX = cell.Left + xPos + cell.EffectivePaddingLeft + calcHeight; break; } SaveAndRotateCanvases(canvases, 0, 1, -1, 0, pivotX, pivotY); } else { pivotY = cell.Top + yPos - cell.EffectivePaddingTop; switch (cell.VerticalAlignment) { case Element.ALIGN_BOTTOM: pivotX = cell.Left + xPos + cell.EffectivePaddingLeft; break; case Element.ALIGN_MIDDLE: pivotX = cell.Left + xPos + (cell.Width + cell.EffectivePaddingLeft - cell.EffectivePaddingRight - calcHeight) / 2; break; default: //top pivotX = cell.Left + xPos + cell.Width - cell.EffectivePaddingRight - calcHeight; break; } SaveAndRotateCanvases(canvases, 0, -1, 1, 0, pivotX, pivotY); } try { ct.Go(); } finally { RestoreCanvases(canvases); } } } else { float fixedHeight = cell.FixedHeight; float rightLimit = cell.Right + xPos - cell.EffectivePaddingRight; float leftLimit = cell.Left + xPos + cell.EffectivePaddingLeft; if (cell.NoWrap) { switch (cell.HorizontalAlignment) { case Element.ALIGN_CENTER: rightLimit += 10000; leftLimit -= 10000; break; case Element.ALIGN_RIGHT: if (cell.Rotation == 180) { rightLimit += RIGHT_LIMIT; } else { leftLimit -= RIGHT_LIMIT; } break; default: if (cell.Rotation == 180) { leftLimit -= RIGHT_LIMIT; } else { rightLimit += RIGHT_LIMIT; } break; } } ColumnText ct; if (reusable) { ct = ColumnText.Duplicate(cell.Column); } else { ct = cell.Column; } ct.Canvases = canvases; float bry = tly - (currentMaxHeight - cell.EffectivePaddingTop - cell.EffectivePaddingBottom); if (fixedHeight > 0) { if (cell.Height > currentMaxHeight) { tly = cell.Top + yPos - cell.EffectivePaddingTop; bry = cell.Top + yPos - currentMaxHeight + cell.EffectivePaddingBottom; } } if ((tly > bry || ct.ZeroHeightElement()) && leftLimit < rightLimit) { ct.SetSimpleColumn(leftLimit, bry - 0.001f, rightLimit, tly); if (cell.Rotation == 180) { float shx = leftLimit + rightLimit; float shy = yPos + yPos - currentMaxHeight + cell.EffectivePaddingBottom - cell.EffectivePaddingTop; SaveAndRotateCanvases(canvases, -1, 0, 0, -1, shx, shy); } try { ct.Go(); } finally { if (cell.Rotation == 180) { RestoreCanvases(canvases); } } } } } IPdfPCellEvent evt = cell.CellEvent; if (evt != null) { Rectangle rect = new Rectangle(cell.Left + xPos, cell.Top + yPos - currentMaxHeight, cell.Right + xPos, cell.Top + yPos); evt.CellLayout(cell, rect, canvases); } if (IsTagged(canvases[PdfPTable.TEXTCANVAS])) { canvases[PdfPTable.TEXTCANVAS].CloseMCBlock(cell); } } if (IsTagged(canvases[PdfPTable.TEXTCANVAS])) { canvases[PdfPTable.TEXTCANVAS].CloseMCBlock(this); } }
/** 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; 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; }
private void AddCellToTable(string text, BaseColor color, float size, float height, int rowSpan = 1, IPdfPCellEvent cellEvent = null) { var font = new Font ( BaseFont.CreateFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, false), size, Font.NORMAL, color ); var cell = new PdfPCell { Phrase = new Phrase(text, font), FixedHeight = height, HorizontalAlignment = PdfPCell.ALIGN_CENTER, VerticalAlignment = PdfPCell.ALIGN_MIDDLE, Rowspan = rowSpan, BackgroundColor = BaseColor.WHITE, CellEvent = cellEvent }; Table.AddCell(cell); }