我需要打印pdf文件、standar打印、其他pdf文件、其他standar打印等等。但是,当我发送到打印机时,纸张是混合的。
我希望:
PDF
PrintPage
PDF
PrintPage
PDF
PrintPage但是,我得到(举个例子):
PDF
PDF
PrintPage
PrintPage
PrintPage
PDF我使用以下代码来完成此任务:
while( ... ) {
ProcessStartInfo starter = new ProcessStartInfo("path to acrobt32.exe", "/t mypdf001.pdf");
starter.CreateNoWindow = true;
starter.RedirectStandardOutput = true;
starter.UseShellExecute = false;
Process process = new Process();
process.StartInfo = starter;
process.Start();
PrintDocument pd = new PrintDocument();
pd.DocumentName = "Work";
pd.PrintPage += new PrintPageEventHandler(pd_PrintPageHandler);
pd.Print();
}任何帮助都将受到欢迎。谢谢。
发布于 2011-07-05 03:17:13
我不能从这个小例子中完全理解这个问题,但我猜pd.Print()方法是异步的。
您希望使打印同步。最好的方法是将代码包装在一个函数中,然后从pd_PrintPageHandler调用该函数,我假设在打印页面时会调用该函数。
一个简单的例子来说明我的意思,
function printPage(pdfFilePath)
{
ProcessStartInfo starter = new ProcessStartInfo("path to acrobt32.exe", pdfFilePath);
starter.CreateNoWindow = true;
starter.RedirectStandardOutput = true;
starter.UseShellExecute = false;
Process process = new Process();
process.StartInfo = starter;
process.Start();
PrintDocument pd = new PrintDocument();
pd.DocumentName = "Work";
pd.PrintPage += new PrintPageEventHandler(pd_PrintPageHandler);
pd.Print();
}在pd_PrintPageHandler方法中,使用下一个PDF文件调用此printPage函数。
发布于 2011-07-05 03:25:42
ProcessStartInfo异步运行。因此,您要启动1个或多个acrobat32 exes,每个exes都需要时间来加载和运行它们的打印功能。在此期间,您的PrintDocument类正在运行它自己的一组打印过程...所以所有的文档都以不可预测的顺序出现。
看看这个:Async process start and wait for it to finish
这个是:http://blogs.msdn.com/b/csharpfaq/archive/2004/06/01/146375.aspx
您需要启动acrobat,等待它完成。然后启动你的PrintDocument (不管它是什么)并等待它结束。冲洗,然后重复。
PrintDocument看起来也是异步的……由于事件处理程序调用,但这很难确定。
发布于 2011-07-05 03:26:43
由于您使用的是外部进程来打印PDF,因此等待该进程退出以保持打印操作同步可能会有所帮助。
也就是说,在调用异步:
process.Start();添加一个对process.WaitForExit();的调用,以保持程序正常运行。
您可能确实需要对PrintDocument执行相同的操作。在这种情况下,您应该能够只阻塞线程,直到触发OnEndPrint事件:example
https://stackoverflow.com/questions/6575217
复制相似问题