Ejemplo n.º 1
0
        private void cmdPrintBitmap_Click(object sender, RoutedEventArgs e)
        {
            PrintDocument document = new PrintDocument();

            document.PrintPage += document_PrintPage;

            // The PrintBitmap() method always uses bitmap printing.
            document.PrintBitmap("My Document - Bitmap Version");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The print to printer.
        /// </summary>
        /// <param name="canvas1">
        /// The canvas 1.
        /// </param>
        /// <param name="canvas2">
        /// The canvas 2.
        /// </param>
        /// <param name="canvas3">
        /// The canvas 3.
        /// </param>
        /// <param name="canvas4">
        /// The canvas 4.
        /// </param>
        /// <returns>
        /// The <see cref="BitmapSource"/>.
        /// </returns>
        public static BitmapSource PrintToPrinter(Canvas canvas1, Canvas canvas2, Canvas canvas3, Canvas canvas4)
        {
            var wb =
                new WriteableBitmap(
                    (int)Math.Round(canvas1.ActualWidth, 0) + (int)Math.Round(canvas2.ActualWidth, 0),
                    (int)Math.Round(canvas1.ActualHeight, 0) + (int)Math.Round(canvas3.ActualHeight, 0));

            wb.Render(canvas1, null);
            wb.Render(canvas2, new TranslateTransform {
                X = canvas1.ActualWidth, Y = 0
            });
            wb.Render(canvas3, new TranslateTransform {
                X = 0, Y = canvas1.ActualHeight
            });
            wb.Render(canvas4, new TranslateTransform {
                X = canvas1.ActualWidth, Y = canvas2.ActualHeight
            });
            wb.Invalidate();

            var doc = new PrintDocument();

            doc.PrintPage += (s, e) =>
            {
                e.HasMorePages = false;
                var b = new Border {
                    BorderThickness = new Thickness(0)
                };
                b.Padding = new Thickness(96.0 / 2.54);

                var img = new Image {
                    Source = wb, Stretch = Stretch.Uniform
                };
                b.Child      = img;
                b.Width      = e.PrintableArea.Width;
                b.Height     = e.PrintableArea.Height;
                e.PageVisual = b;
            };
            doc.PrintBitmap("Print Canvases");

            return(wb);
        }