sun*_*nny 7 .net c# windows-services asp.net-mvc-4
我的要求是从.net mvc框架中开发的Web应用程序将pdf中的发票直接打印到本地打印机.
我需要像Shipstation正在使用SHIPSTATION CONNECT那样做
它是否使用类似的过程
或使用WMI库远程共享打印机.
任何专家的想法都会帮助我和我的程序员构建解决方案.我不期待代码或勺子喂食,但想知道正确方向开始这个过程和方法.
在此先感谢您的帮助!
问候
小智 2
你可以编写从本地打印机打印的javascript函数,
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();
工作示例:
如果您想从服务器打印,您需要向服务器发送请求,例如:www.mysite.com/print.aspx?file=invoice.pdf
要通过服务器打印它,您有两种解决方案,第一个是调用其他进程来完成它,就像您在这个答案中看到的那样:
第二种是使用 PrintDocument 命名空间编写自己的实现,例如:
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();
            }
        }
    }
}
原文取自免费的第三方库
| 归档时间: | 
 | 
| 查看次数: | 26721 次 | 
| 最近记录: |