Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing a picture from a Console Application

I am trying to find how to print a picture (as in on paper) in C#. I'm trying to keep it very simple. So no use of WinForms and just using Console output.

I looked for an answer myself, but couldn't make sense of any of the results.

like image 877
Ashe Erickson Avatar asked Jan 28 '11 02:01

Ashe Erickson


People also ask

How do I print from console application?

Writing in Console App In C# you can write or print to console using Console. WriteLine() or Console. Write(), basically both methods are used to print output of console.

How do I add an image in console application?

Console applications are used primarily for text only applications. There is no way to display an image. You could launch another application which does display the image. This other application would most likely need to support a command line option to pass an image to it.

What does print as image mean?

Print PDF as an image Printing a PDF file as an image bypasses that processing by sending the printer a simple image of the document instead. This process can cause images and fonts to look slightly rougher, especially at the edges. However, you can specify the resolution in dots per inch (dpi) to suit your needs.

How do you make a console application?

Open Visual Studio, and choose Create a new project in the Start window. In the Create a new project window, select All languages, and then choose C# from the dropdown list. Choose Windows from the All platforms list, and choose Console from the All project types list.


2 Answers

You necessarily don't need a WinForm application to do printing. JUst use PrintDocument and DrawImage class and you can do somthing like this:

PrintDocument pd = new PrintDocument();
pd.PrintPage += (thesender, ev) => {
        ev.Graphics.DrawImage(Image.FromFile("Your Image Path"), 
        //This is to keep image in margins of the Page.
        new PointF(ev.MarginBounds.Left,ev.MarginBounds.Top));
    };
pd.Print();

Hope that Helps. (I have used Lambada and Anonymous Delegate to handle the Event, I f you dont understand that please tell i will post the normal version)

like image 167
Shekhar_Pro Avatar answered Oct 17 '22 21:10

Shekhar_Pro


Isn't it as simple as sending the byte stream of the picture to a C# printing library? just like how you would print any other document, like a PDF say, which is actually a collection of images. And the settings of say alignment, layout, B/W or color will then be printer-specific.

like image 1
evandrix Avatar answered Oct 17 '22 22:10

evandrix