使用虚拟打印机时如何检查打印是否完成?
我正在使用虚拟打印机在 C# 程序中将 Word 文档打印为图像文件。到目前为止,一切都很顺利,除了我不知道打印过程何时完成,以便我可以读取生成的图像的内容。 这是我的代码:
using System;
using Microsoft.Office.Interop.Word;
using Word=Microsoft.Office.Interop.Word;
var app = new ApplicationClass();
object filename = "C:\\ad.doc";
var missing = Type.Missing;
var doc = app.Documents.Open(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
var oldPrinter = app.ActivePrinter;
app.ActivePrinter = "Name of printer";
object outputFileName = "c:\\ad.tif";
object trueValue = true;
object falseValue = false;
doc.PrintOut(ref trueValue, ref falseValue, ref missing, ref outputFileName, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref trueValue, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing);
app.ActivePrinter=oldPrinter ;
doc.Close(ref missing, ref missing, ref missing);
app.Quit(ref missing, ref missing, ref missing);
那么我如何确定打印处理已完成,以便我可以继续并获取图像内容?
I am using a virtual printer to print a word document into an image file in a C# program. So far everything is going fine except that I don't know when the printing process is finished so I can read the content of the generated image.
Here's my code :
using System;
using Microsoft.Office.Interop.Word;
using Word=Microsoft.Office.Interop.Word;
var app = new ApplicationClass();
object filename = "C:\\ad.doc";
var missing = Type.Missing;
var doc = app.Documents.Open(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
var oldPrinter = app.ActivePrinter;
app.ActivePrinter = "Name of printer";
object outputFileName = "c:\\ad.tif";
object trueValue = true;
object falseValue = false;
doc.PrintOut(ref trueValue, ref falseValue, ref missing, ref outputFileName, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref trueValue, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing);
app.ActivePrinter=oldPrinter ;
doc.Close(ref missing, ref missing, ref missing);
app.Quit(ref missing, ref missing, ref missing);
Then how can I be sure that the print processing is finished so I can continue and get the image content?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,我发现检查 Word 中的打印状态的唯一方法是以下两种方法之一。
直至打印完成。
循环中或循环中的 APPLICATION.BACKGROUNDPRINTINGSTATUS 属性
后台工作线程不断,直到变成0(不再
打印)或者你遇到了看门狗超时
类似这样的事情......
不完美,但它有效。
请注意,这只会告诉您何时完成从 word 的假脱机。如果您谈论的是了解文档何时实际完成在打印机上打印,那就是另一个问题了。您将需要打印作业ID,并且必须查询打印机后台处理程序的内容,但我无法帮助您。
Unfortunately, about the only way I've found to check for printing status in word is one of two things.
till the printing is complete.
APPLICATION.BACKGROUNDPRINTINGSTATUS property in a loop or on a
background worker thread continuously until it becomes 0 (no longer
printing) or you hit a watchdog timeout
Something like this....
Not perfect, but it works.
Note that this will only tell you when its finished spooling from word. If you're talking about knowing when the document is actually completed PRINTING on the printer, that's a whole other issue. You'll need the print jobID and have to query the printer spooler stuff, which I couldn't help you on.