While I cannot answer your question specifically, I found that I could not do this because Adobe changed Reader, I think in version 9 or 10, so that you could not suppress the print dialog, and the window itself continued in any case, and since my users had different versions of Reader, I couldn’t get anything to work consistently. If you want to try looking at the Reader API anyway, you need to add a link to the correct COM library and go from there. Painful.
In the end, I completely dropped Adobe by running the GhostScript PDF file. The following is a helper class that I created to do this job. gsExePath should be something like C:\Program Files\gs\gs8.71\bin\gswin32c.exe .
public class GSInterface { public string GhostScriptExePath { get; private set; } public GSInterface(string gsExePath) { this.GhostScriptExePath = gsExePath; } public virtual void CallGhostScript(string[] args) { var p = new Process(); p.StartInfo.FileName = this.GhostScriptExePath; p.StartInfo.Arguments = string.Join(" ", args); p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; p.Start(); p.WaitForExit(); } public void Print(string filename, string printerName) { this.CallGhostScript(new string[] { "-q", "-sDEVICE=mswinpr2", "-sPAPERSIZE=a4", "-dNOPAUSE", "-dNoCancel", "-dBATCH", "-dDuplex", string.Format(@"-sOutputFile=""\\spool\{0}""", printerName), string.Format(@"""{0}""", filename) }); } }
The following should be printed on the default Windows printer:
var printerName = new System.Drawing.Printing.PrinterSettings().PrinterName; var gs = new GSInterface(gsExePath); gs.Print(filename, printername);
source share