Reputation: 626
Hello I have my web application but I want to give the possibility to download and Printer-friendly image attached to a form, I have no idea how to do because I'm obviously new to C # and asp.net . As I can start ?
i try with onserverclick but i don´t have idea with i do to communicate with printer is my question How communicate with printers controllers to print a image?
I implemented the following and I get an error with the printer, but I do not get no window available printers.
protected void imprime_tiff(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pqr);
pd.Print();
}
void pqr(object o, PrintPageEventArgs e)
{
System.Drawing.Image i = System.Drawing.Image.FromFile("C:\\Users\\MaxImage\\Desktop\\firma6.png");
Point p = new Point(100, 100);
e.Graphics.DrawImage(i, p);
}
and in my html i put the next
<button name="printButton" id="printButton" type="button" class="btn btn- default" onserverclick=" imprime_tiff" runat="server" >
Imprime
</button>
Upvotes: 0
Views: 584
Reputation: 6959
You won't be able to interact directly with the printer from a web browser. PrintDocument
is only for WinForms applications and won't work with web applications.
The client browser needs to trigger the printing either manually (File > Print...) or through interaction with the page such as clicking on a button after which you can trigger the print dialog using JavaScript - https://developer.mozilla.org/en-US/docs/Web/API/Window/print
You can control the rendering of your page to make it "printer friendly" using a print style-sheet, there is a thorough write up here: http://www.smashingmagazine.com/2011/11/24/how-to-set-up-a-print-style-sheet/
Upvotes: 1