Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ghostscript.NET.dll print pdf to specified printer

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

like image 890
Raju Padhara Avatar asked Feb 03 '15 13:02

Raju Padhara


1 Answers

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

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);
            }
        }
    }
}
like image 185
HABJAN Avatar answered Nov 15 '22 03:11

HABJAN