Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I want to print an image through an IPI Thermal Printer.

What I have tried:

I used a canvas control to arrange the information that i want printed on the paper and i captured the canvas control and converted to an image source using the code below
C#
//get the canvas as image source
                Canvas ck = new Canvas();
                Rect rect = new Rect(canvas.RenderSize);
                RenderTargetBitmap rtb = new RenderTargetBitmap((int)canvas.RenderSize.Width * 2, (int)canvas.RenderSize.Height * 2, 96d, 96d, System.Windows.Media.PixelFormats.Default);
                rtb.Render(canvas);

                //endcode as PNG
                BitmapEncoder pngEncoder = new PngBitmapEncoder();
                pngEncoder.Frames.Add(BitmapFrame.Create(rtb));

                //save to memory stream
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                pngEncoder.Save(ms);

                var imageSource = new BitmapImage();
                imageSource.BeginInit();
                imageSource.StreamSource = ms;
                imageSource.EndInit();


i instantiated the printdialog and passed the image to it using the following code
C#
//print
                System.Windows.Controls.PrintDialog dlg = new System.Windows.Controls.PrintDialog();

                if (dlg.ShowDialog() == true)
                {
                    System.Windows.Size printSize = new
                    System.Windows.Size(dlg.PrintableAreaWidth, dlg.PrintableAreaHeight);

                    System.Windows.Controls.Image img = new System.Windows.Controls.Image();

                    img.Source = imageSource;
                    img.Stretch = Stretch.UniformToFill;
                    img.Margin = new Thickness(48);

                    dlg.PrintVisual(img, "Account Opening Details");
                }


this opens the printdialog box but does not start the printer after i click print. like the printer does not spool or run. I printed a test page on the printer and it worked. It printed fine. So i instantiated a print document like this
C#
PrintDocument dd = new PrintDocument();

but how do i pass the image to the print document before calling the
C#
dd.Print()
function?
Posted
Updated 11-Oct-17 0:32am

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900