sunny
sunny

Reputation: 121

Print Direct from Web application to local printer

My Requirement is to print invoices in pdf direct to local printer from web application developed in .net mvc framework.

I need to do exact like shipstation is doing with SHIPSTATION CONNECT

SHIPSTATION CONNECT

Does it use process like

REMOTE PRINTER SHARING CODEPROJECT

or using WMI library to share printer remotely.

Any expert thought will help me and my programmer to build the solution.I am not expecting code or spoon feeding but like to know the process and way to start on this in right direction.

Thanks in advance for the help!

regards

Upvotes: 12

Views: 45244

Answers (2)

Saurabh D
Saurabh D

Reputation: 275

check printnode.com might be of some help.Seems like doing same thing what you want.The service is not free chargeable or alternatively you can build same using google cloud print.

Upvotes: 2

Proxytype
Proxytype

Reputation: 722

you can write javascript function that print from local printer,

w=window.open();
w.document.open();
w.document.write("<html><head></head><body>");
w.document.write("HI");
w.document.write("</body></html>");
w.document.close();
w.print();
w.close();

working example:

http://jsfiddle.net/xwgq5ap4/

if you want to print from the server you need to send a request for the server for example : www.mysite.com/print.aspx?file=invoice.pdf

to print it by the server you have 2 solutions the first is calling to other process to accomplish it like you can see in this answer:

Print Pdf in C#

the second is write your own implementation using PrintDocument namespace for example:

namespace PrintPDF
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile("sample.pdf");

            //Use the default printer to print all the pages
            //doc.PrintDocument.Print();

            //Set the printer and select the pages you want to print

            PrintDialog dialogPrint = new PrintDialog();
            dialogPrint.AllowPrintToFile = true;
            dialogPrint.AllowSomePages = true;
            dialogPrint.PrinterSettings.MinimumPage = 1;
            dialogPrint.PrinterSettings.MaximumPage = doc.Pages.Count;
            dialogPrint.PrinterSettings.FromPage = 1;
            dialogPrint.PrinterSettings.ToPage = doc.Pages.Count;

            if (dialogPrint.ShowDialog() == DialogResult.OK)
            {
                doc.PrintFromPage = dialogPrint.PrinterSettings.FromPage;
                doc.PrintToPage = dialogPrint.PrinterSettings.ToPage;
                doc.PrinterName = dialogPrint.PrinterSettings.PrinterName;

                PrintDocument printDoc = doc.PrintDocument;
                dialogPrint.Document = printDoc;
                printDoc.Print();
            }

        }
    }
}

original taken from free 3rd party library

Upvotes: 2

Related Questions