/// <summary> /// returns a specific cell of the row /// </summary> public PdfCell this[int column] { get { PdfCell pc = this.owner.Cell(this.index, column); if (pc == null) { throw new Exception("Column " + column + " does not exist"); } return(pc); } }
internal byte[] ToByteStream() { ByteBuffer byteBuffer = new ByteBuffer(); System.Text.StringBuilder sb = new StringBuilder(); for (int rowIndex = this.renderingIndex; (rowIndex < this.renderingIndex + this.renderingRows); rowIndex++) { for (int columnIndex = 0; columnIndex < this.columns; columnIndex++) { PdfCell pc = this.Cell(rowIndex, columnIndex); if (!pc.transparent) { sb.Append(pc.Area.InnerArea(1).ToRectangle(pc.backgroundColor, pc.backgroundColor).ToLineStream()); } } } byteBuffer.Append(sb.ToString()); byteBuffer.Append("BT\n"); Font actualFont = null; Color actualColor = Color.Black; byteBuffer.Append(Utility.ColorrgLine(Color.Black)); sb = new StringBuilder(); if (this.borderWidth > 0 && this.borderColor != Color.Transparent) { //sb.Append(new PdfRectangle(this.PdfDocument, new PdfArea(this.PdfDocument,0,0,1,1), this.borderColor, this.borderWidth).ToColorAndWidthStream()); sb.Append(new PdfRectangle(this.PdfDocument, this.TableArea, this.borderColor, this.borderWidth).ToLineStream()); //sb.Append(this.TableArea.ToRectangle(this.borderColor, this.borderWidth).ToRectangleStream()); } for (int rowIndex = this.renderingIndex; (rowIndex < this.renderingIndex + this.renderingRows); rowIndex++) { for (int columnIndex = 0; columnIndex < this.columns; columnIndex++) { PdfCell pc = this.Cell(rowIndex, columnIndex); if (pc.Content is byte[]) { byte[] d = (byte[])pc.Content; try { Bitmap image = (Bitmap)Bitmap.FromStream(new System.IO.MemoryStream(d)); PdfImage pdfImage = this.PdfDocument.NewImage(image); pdfImage.Width = 0.72 * image.Width; pdfImage.Height = 0.72 * image.Height; double xPos = pc.Area.PosX + 1; double yPos = pc.Area.PosY + (pc.Area.Height - pdfImage.Height) / 2; if (pc.horizontalAlignment == HorizontalAlignment.Center) { xPos = pc.Area.PosX + (pc.Area.Width - pdfImage.Width) / 2; } else if (pc.horizontalAlignment == HorizontalAlignment.Right) { xPos = pc.Area.PosX + pc.Area.Width - pdfImage.Width - 1; } Images[pdfImage] = new RectangleF((float)xPos, (float)yPos, image.Width, image.Height); } catch (Exception) { } } else { pc.PdfTextArea.textArea = pc.Area.InnerArea(pc.cellPadding * 2); if (pc.Font != actualFont) { byteBuffer.Append(String.Format("/{0} {1} Tf\n", pc.PdfTextArea.pdfFont.Alias, pc.Font.Size)); actualFont = pc.Font; } if (pc.foregroundColor != actualColor) { byteBuffer.Append(Utility.ColorrgLine(pc.foregroundColor)); actualColor = pc.foregroundColor; } byteBuffer.Append(pc.PdfTextArea.ToByteStream()); } if (borderWidth > 0 && this.borderColor != Color.Transparent) { if (rowIndex != this.renderingIndex) { sb.Append(pc.Area.UpperBound(this.borderColor, this.borderWidth).ToLineStream()); } if (columnIndex != 0) { sb.Append(pc.Area.LeftBound(this.borderColor, this.borderWidth).ToLineStream()); } } } } byteBuffer.Append("ET\n"); byteBuffer.Append(sb.ToString()); return(byteBuffer.ToByteArray()); }
internal PdfTablePage createTablePage() { int index = this.renderingIndex; double h = this.Rows[index].Height; double oh = 0; while ((h <= this.TableArea.height) && (index < this.rows)) { index++; oh = h; if (index < this.rows) { double rowHeight = this.Rows[index].Height; h += rowHeight; } } this.renderingRows = index - this.renderingIndex; this.TableArea.height = oh; PdfTablePage ptp = new PdfTablePage(renderingIndex, renderingIndex + renderingRows - 1, columns); //caculates areas double y = this.TableArea.posy; for (int rowIndex = this.renderingIndex; (rowIndex < this.renderingIndex + this.renderingRows); rowIndex++) { double x = this.TableArea.posx; double rowHeight = this.Rows[rowIndex].Height; for (int columnIndex = 0; columnIndex < this.columns; columnIndex++) { PdfCell pc = this.Cell(rowIndex, columnIndex); double width = pc.Width; pc.area = new PdfArea(this.PdfDocument, x, y, width, rowHeight); x += width; } y += rowHeight; } for (int rowIndex = this.renderingIndex; (rowIndex < this.renderingIndex + this.renderingRows); rowIndex++) { for (int columnIndex = 0; columnIndex < this.columns; columnIndex++) { PdfCell pc = this.Cell(rowIndex, columnIndex); ptp.cellAreas.Add(pc.row + "," + pc.column, pc.Area); } } ptp.byteStream = this.ToByteStream(); ptp.SetArea(); this.renderingIndex = index; this.renderingRows = 0; return(ptp); }