I am looking to print using C#, Microsoft Visual Studio, asp.net.
The goal: I am trying to print all pages in a fax document.
Format: The fax document is received as a single .tiff file with multiple pages.
What needs to be done:- I need to iterate each page in the .tiff image and print them all.
// This function will iterate all pages, one at a time. //
protected void PrintAll_Click(object sender, EventArgs e)
{
// counts number of pages in the fax document.//
int number = _FaxPages.Count;
// for loop to iterate through each page. //
for (int i = 0; i < number; i++)
{
string _FaxId = Page.Request["FaxId"];
_PageIndex = i;
imgFax.ImageUrl = "ShowFax.ashx?n=" + _FaxId + "&f=" + _PageIndex + "&mw=750";
PrintAll.Attributes.Add("onclick", "return printing()");
}
}
and In my Java script I have:
function printing() { window.print(); }
Now the issues are:
-
The function only prints one page (the very last page of the tiff file)….and it prints the entire window and not just the embedded .tiff image in the entire web browser window.
Any Ideas of how to go about just printing the .tiff embedded image instead of the entire web browser window.
-
Although my for loop iterates through the pages. The print function is only called after the loop has iterated through all the pages and stopped on the final page (say page 6/6). And then it only prints that last page (along with the rest of the contents on the browser window). This is not what I want to happen… I dont want to print all the excess material on the browser window such as buttons, links etc… I just want the embedded .tiff image from the browser window.
Your current code will loop through all pages on the server side and update the image URL, before sending the page to the client. This means the
ImageUrlwill always be your last page only.For printing all the images, there are multiple solutions:
ShowFax.ashx, add an option to render all fax pages at once and put this in the image URL.Imageelement for each page to a parent container at runtime.printing()do a postback, increase the page index and the URL on the image and repeat the code.For printing only the image, hide the other elements with a CSS stylesheet and add a
media="print"like this: