如何通过IIS中托管的应用程序打印到网络打印机 [英] How to print to network printer through application hosted in IIS

查看:202
本文介绍了如何通过IIS中托管的应用程序打印到网络打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有通过IIS中托管的应用程序将pdf(从流生成)打印到网络打印机的方案。我尝试使用PrintDocument.Print(),我遇到的问题是:1。文档排队到大小为0字节的打印作业队列。 2.文档正在排队到打印作业队列,其所有者名称为machine_name。
这是我尝试使用PdfiumViewer(从bytearray生成PrintDocument)和System.Drawing.Printing.PrintDocument的代码:

I have scenario of printing pdf (generated from stream) to network printer through application hosted in IIS. I tried with PrintDocument.Print() and problem I'm facing is: 1. Document is getting queued to the print job queue with size 0 bytes. 2. Document is getting queued to the print job queue with owner name as machine_name. Here is the code which i tried using PdfiumViewer (to generate PrintDocument from bytearray) and System.Drawing.Printing.PrintDocument:

 public void SendPdfToPrinter(byte[] byteArray, string fileName, string printerNetworkPath)
    {
        using (Stream fileStream = new MemoryStream(byteArray)) //byte array for the file content
        {

            var printerSettings = new System.Drawing.Printing.PrinterSettings
            {
                PrinterName = printerNetworkPath, //this is the printer full name. i.e. \\10.10.0.12\ABC-XEROX-01
                PrintFileName = fileName, //file name. i.e. abc.pdf
                PrintRange = System.Drawing.Printing.PrintRange.AllPages,
            };
            printerSettings.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);

            // Now print the PDF document
            using (PdfiumViewer.PdfDocument document = PdfiumViewer.PdfDocument.Load(fileStream))
            {
                using (System.Drawing.Printing.PrintDocument printDocument = document.CreatePrintDocument())
                {
                    printDocument.DocumentName = fileName;
                    printDocument.PrinterSettings = printerSettings;
                    printDocument.PrintController = new System.Drawing.Printing.StandardPrintController();
                    printDocument.Print();
                }
            }


推荐答案

另一个可能&简单的解决方案是将您的应用程序池标识配置给具有访问/允许在网络打印机中打印的自定义/域用户。

Another possible & easy solution is to configure your Application Pool Identity to a custom/domain user which has access/permission to print in network printers.

这篇关于如何通过IIS中托管的应用程序打印到网络打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆