c# - Ghostscript.NET.dll 打印 pdf 到指定打印机

标签 c# vb.net winforms ghostscript ghostscript.net

如何使用 ghostscript api 打印 pdf。 我试过谷歌但仍然没有得到适当的解决方案。请帮助我如何完成这项任务。

最佳答案

这应该适合您(通过使用 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);
            }
        }
    }
}

关于c# - Ghostscript.NET.dll 打印 pdf 到指定打印机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28300385/

相关文章:

c# - 将大量项目添加到 ListView

c# - 如何在列表中添加时间跨度值

c# - silverlight/wpf 中的交点

vb.net - 为用户错误抛出异常?或者更好地设计自定义错误消息框架?

c# - 将非托管/非托管成员添加到托管类

vb.net - 模块 comctl32.ocx 无法在 Windows 10 家庭版中加载

mysql - 带有 mysql 的 Visual Basic 组合框

winforms - 将输入变量从 PowerShell 表单传递到 cmdlet 参数会导致空白数据

C# SQLite : Do I need to deploy System. Data.SQLite.xml?

c# - DESERIALIZE 上的 InvalidoperationException