我正在尝试将pdf文件发送到打印机
Process p = new Process( );
p.StartInfo = new ProcessStartInfo( )
{
CreateNoWindow = true,
Verb = "Print",
FileName = pdfFilePath
WindowStyle := ProcessWindowsStyle.Hidden;
UseShellExecute := true;
};
p.Start( );
但我不断收到"没有应用程序与此操作的指定文件相关联"。
我正在使用Edge打开pdf文件(我还尝试将IE和Chrome设置为默认.pdf应用程序(,并且没有安装pdf阅读器。我的问题是是否可以仅使用默认的Windows工具将pdf文件直接发送到打印机 - 而无需安装Acrobat阅读器等?
检查这个库尖顶.PDF
https://www.nuget.org/packages/Spire.PDF/
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Sample.pdf");
//Set the printer
pdf.PrintSettings.PrinterName = "HP LasterJet P1007";
//Only print the second and fourth page
pdf.PrintSettings.SelectSomePages(new int[] { 2,4 });
//Print the pages from 1 to 15
pdf.PrintSettings.SelectPageRange(1,15);
pdf.Print();
以下是使用 GemBox.PDF 的替代方法,该方法也不需要安装 Adobe Acrobat:
using (PdfDocument document = PdfDocument.Load(pdfFilePath))
document.Print();
以上将使用默认打印机和打印选项打印您的 PDF。
但是,如果需要,您可以指定目标打印机和选项,如下所示:
using (var document = PdfDocument.Load(pdfFilePath))
{
var printer = "your printer's name";
var printOptions = new PrintOptions()
{
FromPage = 2,
ToPage = 4
};
document.Print(printer, printOptions);
}
您可以在此处找到更多打印示例。
你可以 Ghostscript 它是开源的,有一个 NuGet 可以与此程序一起使用此库
此NuGet只是一个与Ghostscript库接口的库,需要在客户端上安装Ghostscript或将库添加到项目中才能正常工作
https://www.nuget.org/packages/Ghostscript.NET
例:
using (GhostscriptProcessor processor = new
GhostscriptProcessor())
{
List<string> arg = new List<string>() {
"-empty",
"-dPrinted",
"-dBATCH",
"-dNOPAUSE",
"-dNOSAFER",
"-dNumCopies=1",
"-sDEVICE=mswinpr2",
"-sOutputFile=%printer%" + printerName,
"-f",
inputFile};
processor.StartProcessing(arg.ToArray(), null);
}