public PdfImage NewImage(Bitmap bitmap) { PdfImage pi; try { pi = new PdfImage(this.GetNextId, bitmap); this.AddPdfObject(pi); if (pi.Transparent) { pi.mask.ID = this.GetNextId; this.AddPdfObject(pi.mask); } } catch { throw new Exception("Error getting Bitmap"); } return(pi); }
public PdfImage NewImage(string file) { PdfImage pi; try { pi = new PdfImage(this.GetNextId, file); this.AddPdfObject(pi); if (pi.Transparent) { pi.mask.ID = this.GetNextId; this.AddPdfObject(pi.mask); } } catch { throw new Exception("Error opening the Image File"); } return(pi); }
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()); }
/// <summary> /// adds a Pdf Element into this PdfPage. /// </summary> /// <param name="PdfImage"></param> /// <param name="posx"></param> /// <param name="posy"></param> public void Add(PdfImage PdfImage, double posx, double posy, double width, double height) { this.PagePdfObjects.Add(PdfImage); this.PagePdfObjects.Add(new PdfImageContent(PdfDocument.GetNextId, "I" + PdfImage.ID, PdfImage.ID, PdfImage.Width, PdfImage.Height, posx, this.PdfDocument.PH - posy, width, height)); }