2011-11-01 119 views
4

我有打印word文档的代码。 在示例文档中有一个用户修改了边距的picure部分。用可打印区域外边距打印word文档

当我执行我收到以下消息的代码:

部1的余量设定可打印区域之外。

处理文档后,它开始后台处理,并抛出这个PROMT enter image description here 如何打开通知对话框关闭?

到目前为止我的代码:

 Process printJob = new Process(); 
     printJob.StartInfo.Verb = "PrintTo"; 
     printJob.StartInfo.Arguments = printerName; 
     printJob.StartInfo.ErrorDialog = false; 
     printJob.StartInfo.CreateNoWindow = true; 
     printJob.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
     printJob.StartInfo.FileName = path; 
     printJob.StartInfo.UseShellExecute = true; 
     printJob.StartInfo.Verb = "print"; 
     printJob.Start(); 

当变量path>是文件名路径

回答

6

http://word.mvps.org/faqs/macrosvba/OutsidePrintableArea.htm

根据这一点,你需要关闭后台打印,然后关闭Application.DisplayAlerts。

编辑

你不会能够与Process做到这一点。 “打印”动词使用/ x/dde来指示Word打印:

/x从操作shell(例如,在Word中打印)启动Word的新实例。这个Word实例只响应一个DDE请求,并忽略所有其他DDE请求和多实例。如果您在操作环境(例如,Windows)中启动Word的新实例,建议您使用/ w开关,该开关将启动一个功能完整的实例。

消息打压,你将需要做的互操作,而不是:

  1. 增加提及的Microsoft.Office.Interop.Word
  2. 做一个Print(string path)方法:
Application wordApp = new Application(); 
wordApp.Visible = false; 

//object missing = Type.Missing; 

wordApp.Documents.Open(path); //for VS 2008 and earlier - just give missing for all the args 

wordApp.DisplayAlerts = WdAlertLevel.wdAlertsNone; 
wordApp.ActiveDocument.PrintOut(false); //as before - missing for remaining args, if using VS 2008 and earlier 

wordApp.Quit(WdSaveOptions.wdDoNotSaveChanges); //ditto 
+0

我不明白这将如何帮助我,因为我没有应用程序,但控制台。 – cpoDesign

+0

看我的编辑。当您的要求非常简单时,流程打印很好。 – sq33G

+0

,这是我一直想念的东西。你知道如何强制它打印双面? – cpoDesign