How to Print using Acrobat Reader X by Command Line Arguments



  • In this post I will cover how to print a PDF document with Acrobat Reader X using Command Line Arguments in Visual Studio 2010.

    Using C# - WPF

    Common Declarations:

    public string PrintPdf(string FilePath)
    {
        //The name of the Printer we are going to use
        //This name is taken from App.Config for after deployment edit
        string printerName = ConfigurationManager.AppSettings["PrinterName"];
        //Path to Acrobat Reader X 
        //This path is taken from App.Config for after deployment edit
        String pathToExecutable = ConfigurationManager.AppSettings["AcrobatExePath"];
        //Now we pass the arguments For Printing to the ProcessStartInfo Constructor
        //We are using the Parameter /t <filename> <printername> <drivername> <portname> 
        //To Print the file the specified printer
        ProcessStartInfo myProcessStartInfo= new ProcessStartInfo(pathToExecutable, @"/t """ + FilePath     + @""" xps """+ printerName + @"""");
        //Open the process and set the StartInfo to myProcessStartInfo
        Process myProcess = new Process();
        myProcess.StartInfo = myProcessStartInfo;
        myProcess.StartInfo.UseShellExecute = false;
        myProcess.StartInfo.CreateNoWindow = true;
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        myProcess.Start();
        System.Threading.Thread.Sleep(2000);
    }

    Now if we want to use the Microsoft XPS Document Writer and don't want user interaction we should do the following: 

    public string PrintPdf(string FilePath)
    {
        //Set the Output File Path
        string outputFilePath = FilePath.Replace(".pdf", ".xps");
        //The name of the Printer we are going to use
        //This name is taken from App.Config for after deployment edit
        string printerName ="Microsoft XPS Document Writer";
        //Path to Acrobat Reader X 
        //This path is taken from App.Config for after deployment edit
        String pathToExecutable = ConfigurationManager.AppSettings["AcrobatExePath"];
        //Now we pass the arguments For Printing to the ProcessStartInfo Constructor
        //We are using the Parameter /t <filename> <printername> <drivername> <portname> 
        //To Print the file the specified printer
        ProcessStartInfo myProcessStartInfo= new ProcessStartInfo(pathToExecutable, @"/t """ + FilePath
        + @""" """ + printerName+ @""" /t """ + outputFilePath + @"""");
        //Open the process and set the StartInfo to myProcessStartInfo
        Process myProcess = new Process();
        myProcess.StartInfo = myProcessStartInfo;
        myProcess.StartInfo.UseShellExecute = false;
        myProcess.StartInfo.CreateNoWindow = true;
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        myProcess.Start();
        System.Threading.Thread.Sleep(2000);
    }

    This Method will print an XPS document using Microsoft XPS Document Writer without user interaction at all.
     
    I got some references from here:

    http://stackoverflow.com/questions/619158/adobe-reader-command-line-reference

    http://bytes.com/topic/c-sharp/answers/256956-printing-pdf-process-start-without-user-prompt



  • Comments



Add a Comment