我正在使用虚拟打印机将Word文档打印到C#程序中的图像文件中。到目前为止一切都很顺利,除了我不知道什么时候打印过程完成所以我可以读取生成的图像的内容。 这是我的代码:
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);
然后,我如何确定打印处理已完成,以便我可以继续并获取图像内容?
答案 0 :(得分:2)
不幸的是,我发现检查单词打印状态的唯一方法是两件事之一。
像这样......
Do Until _Doc.Application.BackgroundPrintingStatus = 0
System.Windows.Forms.Application.DoEvents()
System.Threading.Thread.Sleep(750)
Loop
不完美,但有效。
请注意,这只会告诉您何时从word完成假脱机。如果您正在谈论知道文档何时在打印机上实际完成打印,那就是另一个问题。你需要打印jobID并且必须查询打印机假脱机程序的东西,我无法帮助你。