Thread: ASP.NET/Print PDF in ASP.NET

Print PDF in ASP.NET
variant 1

Adobe Acrobat Reader Does the Dirty Work
Adobe's free Acrobat Reader can be used to do the printing for you!  This has an admittedly less sophisticated feel, but it does get the job done.

The feature we will use in Adobe Acrobat Reader is undocumented and unsupported but widely discussed on the Internet.  It is a commandline switch that only works reliably in Version 4 of the Adobe Acrobat Reader.  

The syntax is:

C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe /t "myexampledocument.pdf" "My Windows Printer Name"

The /t option is an undocumented feature that causes the document to be printed with no prompting dialogs or user input required.

You can install Adobe Acrobat Reader 4.0 from here (The whole version archive is here).  Once installed, you can execute the above command from the command line with your own PDF document and printer name to see it automatically print.

using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;

private static void RunExecutable(string executable, string arguments)
   ProcessStartInfo starter = new ProcessStartInfo(executable, arguments);
   starter.CreateNoWindow = true;
   starter.RedirectStandardOutput = true;
   starter.UseShellExecute = false;
   Process process = new Process();
   process.StartInfo = starter;
   StringBuilder buffer = new StringBuilder();
   using (StreamReader reader = process.StandardOutput)
    string line = reader.ReadLine();
    while (line != null)
     line = reader.ReadLine();
   if (process.ExitCode != 0)
    throw new Exception(string.Format(@"""{0}"" exited with ExitCode {1}. Output: {2}",
executable, process.ExitCode, buffer.ToString());  
You can print your PDF by incorporating the above code into your project and using it as follows:

string pathToExecutable = "c:\...\acrord32.exe";
RunExecutable(pathToExecutable, @"/t ""mytest.pdf"" ""My Windows PrinterName""");

variant 2
1. in your project add reference to COM 'Acrobat Control for ActiveX' -
now you should have AxPdfLib namespace
2. AxPdfLib.AxPdf axPdf = new AxPdfLib.AxPdf();
3. axPdf.LoadFile("my.pdf");
4. axPdf.printAll();


Process pr = new Process();
pr.StartInfo.Verb = "Print";
pr.StartInfo.FileName = "Sample.xls";