Click here to Skip to main content
13,559,193 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


12 bookmarked
Posted 14 Mar 2012
Licenced CPOL

Silent Print Using C#

, 14 Mar 2012
Rate this:
Please Sign up or sign in to vote.
Print you PDF silently using C#


Most developers when they try to send jobs to a printer, they use Acrobat Reader via command line by setting the required parameters.

The problem is, that leaves Acrobat open if your client won't accept the pop-up window.

In this article I'll show you how to avoid this issue by using two useful utilities.


In this solution, we'll use the suite of software Ghost Script developed by Artifex and Ghostgum (a graphical interface for GhostScript). Ghostscript is an interpreter for the PostScript page description language used by laser printers. In contrast, GSview allows you to preview and print your PDFs and other documents (.ps, .epi, and eps).

Using the code

To accomplish our task, we need to send the required paramaters to gsprint.exe under /GSView.


GSview requires Ghostscript. GSview is available for Windows, Linux, and OS/2.

private void Form1_Load(object sender, EventArgs e)
    ManagementObjectSearcher searcher;
    string Win32_Printer = "SELECT * FROM Win32_Printer";
    searcher = new ManagementObjectSearcher(Win32_Printer);
    foreach (ManagementObject mgmtobj in searcher.Get())
        comboBoxPrinterName.Items.Add(mgmtobj["Name"].ToString()); return;

private void buttonPrint_Click(object sender, EventArgs e)
    PrinterThread(comboBoxPrinterName.Text, textBoxDocumentPath.Text, true);

private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
    textBoxDocumentPath.Text = openFileDialog1.FileName;

private void textBoxDocumentPath_MouseDoubleClick(object sender, MouseEventArgs e)

public void PrinterThread(string printerName, string fileName, bool portrait)
     string gsArguments, gsLocation;
     ProcessStartInfo gsProcessInfo;
     Process gsProcess;
     if (portrait)
         gsArguments = string.Format("-noquery -portrait -printer \"{0}\" \"{1}\"",
             printerName, fileName);
         gsLocation = @"C:\Program Files\Ghostgum\gsview\gsprint.exe";
         gsArguments = string.Format("-noquery -landscape -printer \"{0}\" \"{1}\"",
              printerName, fileName);
         gsLocation = @"C:\Program Files\Ghostgum\gsview\gsprint.exe";
     gsProcessInfo = new ProcessStartInfo();
     gsProcessInfo.WindowStyle = ProcessWindowStyle.Hidden;
     gsProcessInfo.FileName = gsLocation;
     gsProcessInfo.Arguments = gsArguments;
     gsProcess = Process.Start(gsProcessInfo);


Many third party libraries still use Adobe Reader so here you get to do a clean job.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Morocco Morocco
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionApplication Does not exit Pin
Member 112730515-Nov-15 15:22
memberMember 112730515-Nov-15 15:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180515.1 | Last Updated 14 Mar 2012
Article Copyright 2012 by R.Tarik
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid