public Form1() { InitializeComponent(); Chapter chapter = new Chapter(); doc.Childs.Add(chapter); TextBlock mainBlock = new TextBlock(); chapter.Childs.Add(mainBlock); ImageElement image = new ImageElement(); MemoryStream mem = new MemoryStream(); Properties.Resources.moto.Save(mem, System.Drawing.Imaging.ImageFormat.Png); image.SourceStream = mem; image.Width = 200; image.Height = 200; mainBlock.Childs.Add(image); TextBlock titleBlock = new TextBlock(); titleBlock.Content = "Hello,World"; titleBlock.VerticalContentAlignment = VerticalAlignment.Bottom; mainBlock.Childs.Add(titleBlock); LineBreak brk = new LineBreak(); chapter.Childs.Add(brk); TextBlock breakedBlock = new TextBlock(); breakedBlock.Content = "Sotto Hello,World"; chapter.Childs.Add(breakedBlock); context = new DefaultPrintingContext(doc); printPreviewControl1.Document = context.PrintDocument; }
public override void PrintImageElement(ImageElement imageElement) { if (dontDrawNow || imageElement.SourceStream == Stream.Null) return; using (Bitmap bitmap = new Bitmap(imageElement.SourceStream)) { if (imageElement.Width == 0) imageElement.Width = bitmap.Width; if (imageElement.Height == 0) imageElement.Height = bitmap.Height; RectangleF bounds = new RectangleF(this.CurrentX, this.CurrentY, imageElement.Width, imageElement.Height); printArgs.Graphics.DrawImage(bitmap, bounds); imageElement.Bounds = this.Rectangle2Rect(bounds); // this.currentY = bounds.Bottom; this.currentX = bounds.Right; } }