I am trying to print a single tiff file with multiple frames. However if I use javascript (window.print()) i get a print out of the entire webpage and not just the tiff image.
So I looked around StackOverflow and found some sample code. I was trying to implement it however the problem is the that the code works for an absolute image URL :- such as “C:\img.jpeg”
I am wondering if anyone can show me how to transform my imgFax.ImageUrl to an actual image name? (otherwise I get an error:- “Illegal character in path” <— in my System.Drawing.Image img = System.Drawing.Image.FromFile(imgFax.ImageUrl); code)
If anyone can show me some sample code that would be amazing! Thanks.
protected void PrintAll_Click(object sender, EventArgs e)
{
// number of frames
int number = _FaxPages.Count;
// for loop to iterate through each frame
for (int i = 0; i < number; i++)
{
// fax ID
string _FaxId = Page.Request["FaxId"];
//string _Frame = Page.Request["Frame"];
// current frame
_PageIndex = i;
// IMG URL
imgFax.ImageUrl = "ShowFax.ashx?n=" + _FaxId + "&f=" + _PageIndex + "&mw=750";
PrintDocument pd = new PrintDocument();
pd.PrintPage += PrintPage;
pd.Print();
}
}
private void PrintPage(object o, PrintPageEventArgs e)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(imgFax.ImageUrl);
Point loc = new Point(100, 100);
e.Graphics.DrawImage(img, loc);
}
I’m not sure whether you can at all do any printing in ASP via PrintDocument. This is all server-side code, while the printing is to be done at – and by the client’s browser. I think that you will have to do it via JavaScript, but to not print the entire page – you will have to create another page that will only present the contents to be printed, then redirect the user to that smaller page (for example in a popup window) and then auto-print it via javascript. I;m not 100% sure, but all banking sites I use seem to follow that, and this is quite common in general..
For example, here’s an article with this exact approach: http://www.dotnetcurry.com/ShowArticle.aspx?ID=92
just remember that your small ‘print-page’ should actually display the things you want to print 🙂
another nice link on printing images: http://forums.asp.net/post/3369436.aspx