none
Silent Printing in asp.net without opening Print Property Dialog box using C# RRS feed

  • Question

  • In our company, we have a conference to be conducted. At least 5000 Visitors would come and we are in need to print id card for each visitor. We have 100 laptops at the conference hall. I know that using windows application we can achieve silent printing without opening print property dialog box with a single button click using System.Drawing.Printing.PrintDocument class.

    This option would require us to install windows app in 100 laptops and it will be time consuming. I need to have a asp.net app and in button click I should get the default printer and print the pages content without opening print dialog box. Is that possible ? Please share code samples and your thoughts. Thanks.

    Friday, October 21, 2011 1:43 AM

Answers

  • Although it may not within your command to setup these changes, you may offer a printer connected to web server on VPN at the conference hall if that's the only place you need the access. Have id number printed on the corner, so when someone prints, you can display a message telling them to collect in the counter with the id code. You may charge printing fees per copies too.

    Depending on your need you may expand this to 10 network printers connect through VPN, and you choose printer to send print command to by modulus of dividing the IP address by 10. Now you get the idea and can scale the solution depending on how many laptops and printers you want to serve.

    Monday, October 24, 2011 7:25 AM
    Answerer

All replies

  • Actually, there's nothing wrong in using System.Drawing.Printing.PrintDocument class in your ASP.NET application to print to a printer connected on the same network of your web server, as long as you remember to give your worker account (Most likely NetworkServices in standard windows server, but you may want to see what username the w3wp.exe is running on) the right to print in the Security setting of your printer.

    EDIT: If the volume is large and you expect it to print for a long time, create a new thread to print it in asynchronous way, or better yet, create a Windows Service to do the printing and have your ASP.NET application just send the signal to read a job queue (your call on whether to use database or pipe) through System.ServiceProcess.ServiceController.GetServices()

    Friday, October 21, 2011 3:25 AM
    Answerer
  • Thanks.. Will try this. This will work only when printer is attached to web server's network. In our case, laptops will be in conference hall and we connect to our web site over internet. Web Server is at the datacenter and so, printer attached to web server in data center only can print. If i need to print the documents using the printer attached to a laptop, in this case i cant find the printer name attached to client machines. Only when Print Properties dialog box opens, we can select printer and can print.

    I do understand, that if we can get the default printer name attached to Client machines and print the documents without the user permission(without opening print properties dialog) , then bad advertising companies out there will do the same thing and will print their advertisements in printer attached to users computers without the users consent.... So from server side code, this is not a doable at least that is what i know. I got few Javascripts and am trying that out... Will let everyone know how it goes... Thanks.

    Friday, October 21, 2011 5:04 PM
  • Hello,

    Simply create that single page and host it with IIS in 1 laptop. Get a wireless router and point all laptops to that 1 pseudo server via http://MyServerLaptopName/Default.aspx

    Hook the server laptop to the printer.

    Problem solved.

    Adam


    Already reported as abusive
    Friday, October 21, 2011 5:42 PM
  • Thanks cheong and Adam for your suggestion and help.

     

    Hi satheeshrajesh,

    Welcome to MSDN Forum.

    In addition, there is a simple way to print a file (document file or image) using Process.Start method in .NET.
        
        
    private void Button1_Click(object sender, System.EventArgs e) {
            ProcessStartInfo psi 
    = new ProcessStartInfo();
            
    psi.UseShellExecute = true;
            
    psi.Verb "print";
            
    psi.WindowStyle ProcessWindowStyle.Hidden;
            
    // psi.Arguments = PrintDialog1.PrinterSettings.PrinterName.ToString()
            
    psi.FileName "C:\\MyFile.doc";
            
    Process.Start(psi);
        
    }

    We can iterate and check all printers installed on a machine.

    foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)

    {

       MessageBox.Show(printer);

    }

    Reference: http://www.dotnetcurry.com/ShowArticle.aspx?ID=148

     

    By the way, there is the dedicated ASP.Net Forum http://forums.asp.net for more efficient support to ASP.NET questions.


    Martin Xie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, October 24, 2011 7:01 AM
    Moderator
  • Although it may not within your command to setup these changes, you may offer a printer connected to web server on VPN at the conference hall if that's the only place you need the access. Have id number printed on the corner, so when someone prints, you can display a message telling them to collect in the counter with the id code. You may charge printing fees per copies too.

    Depending on your need you may expand this to 10 network printers connect through VPN, and you choose printer to send print command to by modulus of dividing the IP address by 10. Now you get the idea and can scale the solution depending on how many laptops and printers you want to serve.

    Monday, October 24, 2011 7:25 AM
    Answerer
  • Sorry to bump an old thread, but this is still one of the first results when looking for a solution... 

    If you don't mind using a client-side solution (e.g. use the web browser directly) some do exist... 

    For generic solutions (PDFs and raw content)

    • PrintNode
    • QZ Tray

    For vendor-specific solutions:

    • Dymo JavaScript API
    • Epson ePOS-Device
    • Zebra Link-OS

    All of these libraries aim to print without a dialog.

    Full disclaimer, I'm the author of QZ Tray.



    • Edited by tresf0 Friday, November 15, 2019 5:59 AM
    Friday, November 15, 2019 5:56 AM