5

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

HABJAN
  • 9,212
  • 3
  • 35
  • 59
Raju Padhara
  • 687
  • 1
  • 7
  • 20
  • 1
    You didn't Google enough. http://stackoverflow.com/questions/21462247/printing-pdf-using-ghostscript-net-dpi-printing-issue | You can use this converter if you need to: http://codeconverter.sharpdevelop.net/SnippetConverter.aspx – Visual Vincent Feb 03 '15 at 13:50
  • 1
    https://ghostscriptnet.codeplex.com/discussions/574516 | https://ghostscriptnet.codeplex.com/discussions/470946 – Visual Vincent Feb 03 '15 at 13:59
  • @Visual Vincent all above example is convert pdf to image. I want to direct print pdf to printer. – Raju Padhara Feb 03 '15 at 14:46

1 Answers1

6

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);
            }
        }
    }
}
HABJAN
  • 9,212
  • 3
  • 35
  • 59
  • I tried with below suggested link code with out ghost script installation. I tried with gsdll32.dll assembly binary and GhostscriptVersionInfo. [link](https://ghostscriptnet.codeplex.com/discussions/465418) Please help me how to work with native dll and managed assembly. – Raju Padhara Feb 03 '15 at 18:15
  • when printer removed it processor.StartProcessing(switches.ToArray(), null); method stuck – Jigar Joshi Feb 22 '18 at 17:10