locked
C# - How to BULK Print PDF files in SilentMode. RRS feed

  • Question

  •  

    Hello Experts/Professionals,

     

       I am newbie to C#.  I have developed a simple C# application to bulk print PDF files using the "Process" class. (Please see the code sample below). 

     

       With this method, the printing process does works fine, but each time a pdf file is printed, an instance of ACROBAT READER 7.0 window gets opened asthough i have set the "CreateNoWindow" = true and also  tried WindowStyle = Hidden in "Process StartInfo"??

     

      I have tried ExitMainWindow() and also WaitForExit() functions to exit the acrobat reader after each pdf file print.  But this does't really ALWAYS closes the PDF window (Example, If the PDF file that is printed is Very Big in Size).

     

       So, my question is "Using C# - is there a way where I can do bulk printing of pdf files in Silent Mode (without displaying the Acrobat Reader Window), provided only ACROBAT READER 7.0 installed and NOT the FULL VERSION OF ADOBE ACROBAT in Client's Machine"?

     

       I am using Visual Studio .NET 2003, Windows XP (or) Windows 2000 and have got AcrobatReader7.0 installed (But NOT the Full Acrobat Standard/Professional Version).

     

    CODE SNIPPET :

    ============

     

    System.Diagnostics.Process P = new Process();


    P.StartInfo.FileName = filename; // FileName(.pdf) to print.    

    P.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //Hide the window.   

     

    //!! Since the file name involves a nonexecutable file(.pdf file), including a verb to specify what action to take on the file. //The action in our case is to "Print" a file in a selected printer.
                        
     //!! Print the document in the printer selected in the PrintDialog !!//
     P.StartInfo.Verb = "PrintTo";      

     P.StartInfo.Arguments = printDialog1.PrinterSettings.PrinterName.ToString();
     P.StartInfo.CreateNoWindow = true; //!! Don't create a Window.           

    //!! Start the process !!//      

    P.Start();         

    //!! P.WaitForExit(4000);     

    P.CloseMainWindow();

     

    Please NOTE : I have managed to find a way to print PDF files in SILENT MODE using ACROBAT COMPONENT/TYPE LIBRARY. But it seems like that code does NEED FULL PROFESSIONAL VERSION OF INSTALLED in the Target PC (where my application executes). But I would like to bulk print pdf's with only ACROBAT READER 7.0 installed.

     

     So please any suggestions will be highly appreciated.

     

    Thanks in advance.

    Mamtha.

    Friday, August 17, 2007 2:55 PM

Answers

  • That is a function of the Adobe Acrobat and you may need to either find a command line switch that disables that operation after a print, or use a PDF library to do the actual printing instead of running a command from process.

    Start by looking into the PDF Forms parser on Code project to get you started. Here is a list of open source pdf software for C# that might help you.

    Note since Adbobe products are well Adobe, Microsoft does not support their products. It would be best to post questions related to Adobe to the Adobe Online Forums.
    Sunday, August 19, 2007 6:13 PM

All replies

  • That is a function of the Adobe Acrobat and you may need to either find a command line switch that disables that operation after a print, or use a PDF library to do the actual printing instead of running a command from process.

    Start by looking into the PDF Forms parser on Code project to get you started. Here is a list of open source pdf software for C# that might help you.

    Note since Adbobe products are well Adobe, Microsoft does not support their products. It would be best to post questions related to Adobe to the Adobe Online Forums.
    Sunday, August 19, 2007 6:13 PM
  • One option that you have is to reuse the Process that you have created. Simply reset yourProcess.StartInfo.FileName to the next file and call Start on the Process instance. This will allow you to queue up multiple files for printing using the original Adobe process. Good luck!

    Monday, November 19, 2007 9:48 PM
  •  

    hi,

    i have taken 'process' and printed the PDF file..

    it is going to print now but another problem was...

    the PDF file is opening when we send that file to print...

    we must hide that file and also i need another help..

    how we can get number of print copies....

    can any one help

     

    following is the code

     

    Process process = new Process();

    process.StartInfo.FileName = @"C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe";

    string strFileName = PDFFileUpload.PostedFile.FileName;

    string filename = strFileName;

    process.StartInfo.Arguments = "/p /h \"" + filename + "\" \"" + drpPrinter.SelectedIndex + " \""; //"/t " + @"C:\test.pdf" // "HP LaserJet 1022n"; // "/t " + @"c:\SSN.pdf"; //"\"" + @"c:\SSN.pdf" + "\"" + " \"" + "HP LaserJet 1022n" + "\""; // "\t " + @"C:\SSN.pdf" + " HP LaserJet 1022n";

    process.StartInfo.CreateNoWindow = true;

    process.StartInfo.RedirectStandardOutput = true;

    process.StartInfo.UseShellExecute = false;

    process.Start();

    process.CloseMainWindow();

     

    now i want to close the process
    Tuesday, November 27, 2007 10:27 AM
  •  Can we use Process to print a file with multiple pages?

    For instance, I have an excel file that I am printing (code below), the file has 2 pages, but only 1 gets printed.

    Also, I added code to change the page orientation to landscape but it doesnt seem to take that..always prints potrait.

    Thanks!
    -------------

    printjob.StartInfo.FileName = targetFile;

    printjob.StartInfo.Verb = "Print";

    printjob.StartInfo.CreateNoWindow = true;

    printjob.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

    PrinterSettings setting = new PrinterSettings();

    setting.DefaultPageSettings.Landscape = true;

    printjob.Start();

    Friday, September 5, 2008 4:38 PM
  • Hello,
        I have a question about print pdf, Could you help me?
        
        CODE SNIPPET :
            if (this.printDialog1.ShowDialog() == DialogResult.OK)
                {
                    Process p = new Process();
                    ProcessStartInfo info = new ProcessStartInfo();
                    info.FileName = @"C:\c.pdf";
                    info.Verb = "Print";
                    info.Arguments = this.printDialog1.PrinterSettings.PrinterName;
                    info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                    p.StartInfo = info;
                    p.Start();
                }    

    now, Though i set the property Arguments to the was selected printername, it used the default printer also. Can you help me?
    secondly, what's different between info.Verb = "Print" and "PrintTo"?

    Thanks.

    冰碟
    Tuesday, March 17, 2009 11:20 AM
  • I use the follwing code, but still it is printing to default printer, can any one help me how to set the selected printer for pdf file printing?

    PrintDialog

     

    pd = new PrintDialog();

    pd.PrinterSettings =

    new PrinterSettings();

     

    if (DialogResult.OK == pd.ShowDialog(this))

    {

     

    //Print the file to the printer.

     

    //PrintDocument pdc;

     

    Process objP = new Process();

    objP.StartInfo.FileName = strFilePath;

    // FileName(.pdf) to print.

     

    //objP.StartInfo = new ProcessStartInfo(strFilePath);

    objP.StartInfo.WindowStyle =

    ProcessWindowStyle.Hidden; //Hide the window.

     

    //!! Since the file name involves a nonexecutable file(.pdf file), including a verb to specify what action to take on the file.

     

    //The action in our case is to "Print" a file in a selected printer.

     

    //!! Print the document in the printer selected in the PrintDialog !!//

    objP.StartInfo.Verb =

    "print";

    objP.StartInfo.Arguments =

    "/p /h \"" + strFilePath + "\" \"" + pd.PrinterSettings.PrinterName + " \"";//pd.PrinterSettings.PrinterName;

     

    //objP.StartInfo.UseShellExecute = true;

    objP.StartInfo.CreateNoWindow =

    true;//!! Don't create a Window.

    objP.Start();

    //!! Start the process !!//

    objP.CloseMainWindow();
    }

    Thanks
    Krishna

    Thursday, July 2, 2009 8:00 AM
  • Hi,

    I have smae problem for setting the selected printer to the process.
    If you got the answer please reply me

    i use the following:

    PrintDialog

     

    pd = new PrintDialog();

    pd.PrinterSettings =

    new PrinterSettings();

     

    if (DialogResult.OK == pd.ShowDialog(this))

    {

     

    //Print the file to the printer.

     

    //PrintDocument pdc;

     

    Process objP = new Process();

    objP.StartInfo.FileName = strFilePath;

    // FileName(.pdf) to print.

     

    //objP.StartInfo = new ProcessStartInfo(strFilePath);

    objP.StartInfo.WindowStyle =

    ProcessWindowStyle.Hidden; //Hide the window.

     

    //!! Since the file name involves a nonexecutable file(.pdf file), including a verb to specify what action to take on the file.

     

    //The action in our case is to "Print" a file in a selected printer.

     

    //!! Print the document in the printer selected in the PrintDialog !!//

    objP.StartInfo.Verb =

    "print";

    objP.StartInfo.Arguments =

    "/p /h \"" + strFilePath + "\" \"" + pd.PrinterSettings.PrinterName + " \"";//pd.PrinterSettings.PrinterName;

     

    //objP.StartInfo.UseShellExecute = true;

    objP.StartInfo.CreateNoWindow =

    true;//!! Don't create a Window.

    objP.Start();

    //!! Start the process !!//

    objP.CloseMainWindow();

    }

    Thanks
    Thursday, July 2, 2009 8:05 AM
  • Looks like you should change the VERB you are using... instead of following line of code...
     

    objP.StartInfo.Verb =

    "print";

    Use this one...

     

    objP.StartInfo.Verb =

    "printto"

    ;

     

    Wednesday, July 8, 2009 5:48 PM
  • for (int index = 0; index < ds_Temp.Tables[0].Rows.Count; index++)

     

    DirectoryInfo dir =

     

    new DirectoryInfo(DocPath +  ds_Temp.Tables[0].Rows[index]["Dwg"]);

     

    FileInfo[] files = dir.GetFiles();

     

    new Process();

     

    string filename = DocPath + ds_Temp.Tables[0].Rows[index]["Dwg"] + "\\" + DocName;

     

    new ProcessStartInfo(filename);

     

     

    p.StartInfo.Verb =

    "print";

    p.StartInfo.CreateNoWindow =

     

    true;

     

    ProcessWindowStyle.Hidden;

     

    true;

     

    Process[] procs = Process.GetProcessesByName("Acrobat");

     

    foreach (Process proc in procs)

     

       if (!p.HasExited)

     

    }

       {

          proc.Kill();

          proc.WaitForExit();

        }

    }

    p.Close();

    {

     

     

    p.Start();

    p.WaitForExit(3000); // wait 3 second for process exit

     

    p.StartInfo.UseShellExecute =

    p.StartInfo.WindowStyle = System.Diagnostics.

    p.StartInfo.Arguments = dialog.PrinterSettings.PrinterName;

    p.StartInfo =

     

    DocName = files[0].Name;

    Process p =

     

     

    {

     

    Tuesday, September 1, 2009 4:01 AM
  • This process doesnt work with every acorbat version.

    Bether is wait for adobe window to be "Adobe Reader" than close main window.

    otherwise if your pdf is printing longer than 3 second, print job will be canceled.

    There is one Command line tool for pdf printing BatchPDFPrinting ,  we are using it with c# and it works great.

     

     

     

    Sunday, September 5, 2010 7:18 PM
  • here is an article how to open and show and silent print pdf in Windows and Mac OSX with examples (using native commands):
    http://www.onyrix.com/2012/04/adobe-air-pdf-silent-print-with-acrobat-reader/

    bye
    d

    Note that this examples also works for C# or JAVA or whatever, because it uses simple commandline commands

    Thursday, July 19, 2012 1:46 PM
  • Hello MamthaR,

    Did you get an answer to your question? I am also facing the same issue.

    Thanks in advance

    Rohit


    rohitp

    Thursday, January 23, 2014 4:48 AM