Print Images C#.Net

Print images c#.net

The Code below uses the PrintDocument object which you can place an image on to the printdocument and then print it.

using System.Drawing.Printing;
...
protected void btnPrint_Click(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += PrintPage;
pd.Print();
}

private void PrintPage(object o, PrintPageEventArgs e)
{
System.Drawing.Image img = System.Drawing.Image.FromFile("D:\\Foto.jpg");
Point loc = new Point(100, 100);
e.Graphics.DrawImage(img, loc);
}

Print Image to file using PrintDocument

XPS Document Writer prints in *.xps or *.oxps format.

You need to consider converting xps|oxps to .jpg

change the extesion of file to xps

PrintFileName = @"D:\f.xps"

Print Image One by one C#

This works for me doesn't throws exception, and print starts:

I saved to jpg files, not jpeg, first is this: Pencils

I think the problem is with your image files.

 var files = Directory.GetFiles(@"C:\temp\", "*.jpg");

foreach (var i in files)
{
var objPrintDoc = new PrintDocument();
objPrintDoc.PrintPage += (obj, eve) =>
{
System.Drawing.Image img = System.Drawing.Image.FromFile(i);
Point loc = new Point(100, 100);
eve.Graphics.DrawImage(img, loc);
};
objPrintDoc.Print();
}


Related Topics



Leave a reply



Submit