简体   繁体   English

在没有“打印”对话框的情况下打印页面?

[英]Printing a page without the Print dialog box?

I have this ASP.NET page which I would like to print. 我有这个ASP.NET页面,我想打印。 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() . 我现在正在使用OnClientClick然后从那里调用函数PrintThePage() ,该函数除了对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). 我的默认打印机是OneNote (Microsoft发送到OneNote )。 The problem: While the page does print, only a blank page is produced. 问题:虽然页面确实可以打印,但是仅产生空白页面。

I first tried to set my default printer to doPdf . 我首先尝试将默认打印机设置为doPdf When that did not work, I then attempted to use my real HP printer. 如果这样做不起作用,我便尝试使用真正的HP打印机。 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 . 我不再得到“ 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. 您可以使用Java在客户端进行打印,了解某些优惠券打印机的工作方式。 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. Page_Load上的调用将在服务器端打印机上完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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