简体   繁体   中英

Printing a page without the Print dialog box?

I have this ASP.NET page which I would like to print. What I am doing right now is using OnClientClick and from there calling a function PrintThePage() which does nothing but make a call to Window.Print() . When I do this, the user is presented with the Print dialog box, where she can select the printer (and set its properties and what not) and then print the page.

The problem is I want to print the page without showing the print dialog box, using the default printer. Here's what I've tried:

protected void Page_Load(object sender, EventArgs e)
{
    System.Drawing.Printing.PrinterSettings ps =
        new System.Drawing.Printing.PrinterSettings();

    ps.PrintFileName = Path.GetFileName(Request.Url.LocalPath);

    System.Drawing.Printing.PrintDocument pd =
        new System.Drawing.Printing.PrintDocument();

    pd.PrinterSettings = ps;
    pd.Print();
}

My default printer is OneNote (Microsoft send to One Note). The problem: While the page does print, only a blank page is produced.

I first tried to set my default printer to doPdf . When that did not work, I then attempted to use my real HP printer. But I still received the same result. The page isn't showing the print dialog box...that problem is gone. But the problem is why is the page not printing? Why I am getting a blank/null/nada page? Is there a problem in my code? Or is it the fault of my printer? Again, one problem is gone; I am no longer getting the Print Dialog Box . I'm just not getting a printed page, just a blank page.

Can anyone tell me what's happening? What can I do to achieve my goal? (I hope I have made myself clear enough!).

I think you have confused client side printing with printing on the server.

You can print on the client side with Java, how some coupon printers work. However, this is frowned upon. The client should always have a choice of how they want it printed.

The calls on Page_Load would be done on the server-side printers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM