10

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

sunny
  • 101
  • 1
  • 1
  • 3
  • i have tried to search in stack for the solution and didn't find any solution near this.There are some examples for java but i need experts views for c# to achieve this. – sunny Jun 27 '15 at 19:33
  • where the printer connected? to the server or the client? – Proxytype Jun 27 '15 at 19:35
  • printer connected to client side locally.But once print button pressed from web application that prints from local printer. – sunny Jun 27 '15 at 19:37
  • you can only print by using the browser... – Proxytype Jun 27 '15 at 19:38
  • i know browser based printing.That needs extra step to print like press button print or on something.But if you see link for shipstation they bypassed that extra step and send direct print to printer client side .What they ask users is to install CONNECT SOFTWARE in local machine.That shares the local printer with web application. – sunny Jun 27 '15 at 19:40

2 Answers2

2

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

Community
  • 1
  • 1
Proxytype
  • 712
  • 7
  • 18
  • appreciate you effort.It didn't worked like we want.Our requirement to print PDF file direct to local printer without opening the file in browser or in hidden pane.It should behave like desktop print as achieved by shiptation.You can see here http://help.shipstation.com/customer/portal/articles/1818589 – sunny Jun 27 '15 at 19:53
  • we searched on stackoverflow thoroughly before posting this and sample provided by your we have already tried . – sunny Jun 27 '15 at 19:54
  • In your example one has to click print button to finally print.We don't need that extra step.Just need to by pass that as done by shipstation.Need to behave like desktop print. – sunny Jun 27 '15 at 20:02
  • PrintDocument is the solution you need https://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument(v=vs.110).aspx – Proxytype Jun 27 '15 at 20:11
  • thanks for both approach .i will get this tested by my programmer and get back to you how it worked on monday i will post my answer on this. – sunny Jun 27 '15 at 20:13
  • hi proxytype plz see this if this http://stackoverflow.com/questions/16359411/c-sharp-enumerating-network-printers-on-remote-machine – sunny Jun 27 '15 at 21:12
  • connect the printer remotely using windows interface and just write the name of the printer to the printDocument... doc.PrinterName – Proxytype Jun 27 '15 at 21:32
  • @Proxytype can you please provide an example of connect the printer remotely using windows interface – prasad maganti Jul 29 '20 at 07:10
  • @sunny i'm also looking for the same solution. how you achieved this – prasad maganti Jul 29 '20 at 07:11
  • @prasadmaganti, you need to connect the printer to server, by using api requesting the server you can send the document to the server printer. – Proxytype Jul 30 '20 at 08:05
  • @Proxytype if possible please provide sample code or documentation for better understanding – prasad maganti Aug 10 '20 at 07:34
2

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.

Saurabh D
  • 275
  • 5
  • 16
  • Google Cloud Print is on deathrow. https://support.google.com/chrome/a/answer/9633006 – Leor Jul 07 '20 at 07:33