0

我希望我的 Web 应用程序在出现后自动打印 w 弹出页面,而不要求客户端选择要选择的打印机。

如何使用 java-script 或 ajax 在 ASP.Net 中处理静默打印,或者什么是最适合这种情况的解决方案?

4

3 回答 3

0

您不能这样做是有充分理由的,例如:

  • 用户应该始终能够选择他们想要使用的打印机。

  • 用户应该始终能够选择是否打印某些内容(想象一下垃圾邮件会不断从您的打印机中飞出)

于 2012-11-06T10:39:25.133 回答
0

一些第三方控件可用于此(在 WPF 中)。请检查这在 asp.net 中是否也有用。

http://www.textcontrol.com/en_US/support/documentation/dotnet/n_wpf_printing.printing.htm

于 2012-11-06T10:42:50.353 回答
0
//OnTouchPrint.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing.Printing;
using System.IO;
using System.Drawing;

namespace TokenPrint
{
    public partial class Try : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }

        }

         private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
           {

                Graphics g = e.Graphics;
                SolidBrush Brush = new SolidBrush(Color.Black);
                string printText = TextBox1.Text;
                g.DrawString(printText, new Font("arial", 12), Brush, 10, 10);

            }


        protected void Press_Click(object sender, EventArgs e)
        {
            try
            {
                string Time = DateTime.Now.ToString("yymmddHHMM");
                System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();
                ps.PrintToFile = true;
               // ps.PrintFileName = "D:\\PRINT\\Print_"+Time+".oxps"; /* you can save file here */
                System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
                pd.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
                System.Drawing.Printing.StandardPrintController printControl = new System.Drawing.Printing.StandardPrintController();
                pd.PrintController = printControl;
                pd.DefaultPageSettings.Landscape = true;
                pd.PrinterSettings = ps;
                pd.Print();
                TextBox1.Text = "";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Printed Successfully.Check: Drive D')", true);


            }
            catch (Exception ex)
            {

            }


        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("Try.aspx");
        }
    }
}

//OnTouchPrint.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OnTouchPrint.aspx.cs" Inherits="TokenPrint.Try" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>


</head>
<body>
    <form id="form1" runat="server">


    <asp:TextBox ID="TextBox1" runat="server" Width="235px" Height="142px" 
        TextMode="MultiLine"></asp:TextBox>


    <br />
    <br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
        ControlToValidate="TextBox1" ErrorMessage="Empty message can not be printed!" 
        ValidationGroup="vgp1"></asp:RequiredFieldValidator>
    <br />
    <br />
    <asp:Button ID="Press" runat="server" Text="Press" onclick="Press_Click" 
        ValidationGroup="vgp1" />


    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Refresh" 
        ValidationGroup="vgp2" />
&nbsp;&nbsp;&nbsp;


    </form>
</body>
</html>
于 2014-08-22T13:09:14.040 回答