vb.net Ghostscript.NET.dll 打印 pdf 到指定打印机

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28300385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 18:46:15  来源:igfitidea点击:

Ghostscript.NET.dll print pdf to specified printer

c#vb.netwinformsghostscriptghostscript.net

提问by Raju Padhara

How to print pdf using ghostscript api. I tried google but still not getting proper solution. Please help me how i do this task.

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

回答by HABJAN

This should work for you (by using Ghostscript.NETwrapper):

这应该对你有用(通过使用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);
            }
        }
    }
}