打印文档进入状态后台打印的打印后台处理程序,但不使用rawprint nuget软件包C#打印文档

时间:2018-10-04 11:28:20

标签: c# printing nuget-package

我正在使用rawprint nuget软件包C#实现没有打印对话框的打印文档

当我使用打印对话框打印word文档时,它会成功添加到状态为“正在打印”的打印队列中 打印文档。

当我使用rawprint nuget软件包C#使用“ PrinterName”和FilePath打印PDF文档时,它将以状态“ Printing”添加到打印队列,但没有从打印机中打印出来。

下面给出了我的代码示例

public void printPDF(string printerName)
        {
            // Absolute path to your PDF to print (with filename)
            string combinedPdf = new UrlHelper(System.Web.HttpContext.Current.Request.RequestContext).Content("~/temp/") + "conbined_5248422286163515789.pdf";
            // The name of the PDF that will be printed (just to be shown in the print queue)
            string Filepath = System.Web.HttpContext.Current.Server.MapPath(combinedPdf);
            if (System.IO.File.Exists(Filepath))
            {
                string Filename = "conbined_5248422286163515789.pdf";
                // The name of the printer that you want to use
                // Note: Check step 1 from the B alternative to see how to list
                // the names of all the available printers with C#
                string PrinterName = printerName;

                // Create an instance of the Printer
                IPrinter printer = new Printer();

                // Print the file
                printer.PrintRawFile(PrinterName, Filepath, Filename);
            }
        }

请帮助并提出建议。

1 个答案:

答案 0 :(得分:0)

string Filepath = @"\\YOURSERVER\PATH\Path\" + Label1.Text + "-" + label2.Text + ".pdf";
string Filename = label1.Text + "-" + Label2.Text + ".pdf";
string PrinterName = @"\\server01\Print-11"; //Adress of the Printer with name!

// Create an instance of the Printer

IPrinter printer = new Printer();

// Print the file:
printer.PrintRawFile(PrinterName, Filepath, Filename);