如何使用ghostscript api打印pdf。 我试过谷歌,但仍然没有得到适当的解决方案。请帮我完成这项任务。
答案 0 :(得分:5)
这应该对您有用(使用Ghostscript.NET包装器):
using System;
using System.Collections.Generic;
using Ghostscript.NET.Processor;
namespace Ghostscript.NET.Samples
{
public class SendToPrinterSample : ISample
{
public void Start()
{
// YOU NEED TO HAVE ADMINISTRATOR RIGHTS TO RUN THIS CODE
string printerName = "YourPrinterName";
string inputFile = @"E:\__test_data\test.pdf";
using (GhostscriptProcessor processor = new GhostscriptProcessor())
{
List<string> switches = new List<string>();
switches.Add("-empty");
switches.Add("-dPrinted");
switches.Add("-dBATCH");
switches.Add("-dNOPAUSE");
switches.Add("-dNOSAFER");
switches.Add("-dNumCopies=1");
switches.Add("-sDEVICE=mswinpr2");
switches.Add("-sOutputFile=%printer%" + printerName);
switches.Add("-f");
switches.Add(inputFile);
processor.StartProcessing(switches.ToArray(), null);
}
}
}
}