Ashutosh Mund

Ashutosh Mund

  • 901
  • 876
  • 203.8k

Printing PDF Document using C#

Dec 27 2016 9:33 AM
Hi,
 
I am facing an issue while printing number of PDF having multiple pages.
Using AcroRd32.exe to open the PDF and send print one by one.
The issue is for a larger PDF document in a batch, for a 9 page document it does not print after 3 page or 5 page. Also we have observed that no two acrord32.exe is open same time, so how can we deal with when many users are printing same time.
Here is the code :
public void PrintPDF(string tempPath, string PrinterName)
{
const string flagNoSplashScreen = "/s";
const string flagOpenMinimized = "/h";
var flagPrintFileToPrinter = string.Format("/t \"{0}\" \"{1}\"", tempPath, PrinterName);
var args = string.Format("{0} {1} {2}", flagNoSplashScreen, flagOpenMinimized, flagPrintFileToPrinter);

try

{
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = "D:\Adobe\Reader 11.0\Reader\AcroRd32.exe";
p.StartInfo.RedirectStandardError = true;
p.StartInfo.Arguments = args;
p.Start();
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (!p.WaitForExit(5000))
{
if (!p.HasExited)
{
p.Kill();
}
}
p.EnableRaisingEvents = true;
p.CloseMainWindow();
p.Close();
}
catch (Exception ex)
{

//

}

}
 
 

Answers (2)