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
Entity Framework Many to Many Through Containing Object
How to Get a Count of the Total Number of Digits in a Number
C#: Triggering an Event When an Object Is Added to a Queue
Problems Using Entity Framework 6 and SQLite
How to Generate a Unique Token Which Expires After 24 Hours
Wcf Gives an Unsecured or Incorrectly Secured Fault Error
An Expression Tree May Not Contain a Call or Invocation That Uses Optional Arguments
Create Web Service Proxy in Visual Studio from a Wsdl File
Resharper Conventions for Names of Event Handlers
How to Make a Wizard with ASP.NET MVC
Using Moq to Determine If a Method Is Called
Translate Perl Regular Expressions to .Net
Can Structs Contain Fields of Reference Types
Check If All Items Are the Same in a List
Vb.Net Equivalent to C# Var Keyword
System.Net.Webexception: the Remote Name Could Not Be Resolved: