Word.Interop 打印到 pcl 文件。
我正在开发一个自动生成传真的应用程序。 系统使用 word interop 用值填充模板 .doc 文件(工作正常),但是当需要将结果文件打印到 pcl 时,我遇到了问题。
因此,我们已经设置了一台 HP Laserjet 打印机来打印 .pcl 文件。
Dim appWord As New Word.Application
Dim doc As New Word.Document
appWord.ActivePrinter = PCL_PRINTER
doc = appWord.Documents.Open(APPLICATION_DIR & "LTL_" & n.Language & ".doc")
...(用值填充文件)
outFile = APPLICATION_DIR & "Faxout\DROPDIR\" & n.Order & ".pcl"
doc.PrintOut(True, True, , outFile, , , , , , , True)
'cleanup...
问题是当 doc.PrintOut 行运行时,word 会抱怨,弹出一条消息:
我尝试了各种组合,但错误消息仍然存在。偶尔,这个东西确实可以工作并生成一个可用的 pcl 文件,但 98% 的情况下,错误消息会弹出,整个过程就会停止。
我们在同一服务器上有其他应用程序,它们执行几乎完全相同的操作,除了它们从 Excel 而不是 Word 打印,并且它们工作时不会抛出错误。
有人可以帮忙吗?
I'm working on an application which automatically generates faxes.
The system uses word interop to fill a template .doc file with values (which works fine), but when it comes to be time to print the resulting file to pcl, I'm having issues.
So, we've got a HP Laserjet printer set up which prints .pcl files.
Dim appWord As New Word.Application
Dim doc As New Word.Document
appWord.ActivePrinter = PCL_PRINTER
doc = appWord.Documents.Open(APPLICATION_DIR & "LTL_" & n.Language & ".doc")
... (Fill the file with values)
outFile = APPLICATION_DIR & "Faxout\DROPDIR\" & n.Order & ".pcl"
doc.PrintOut(True, True, , outFile, , , , , , , True)
'cleanup...
Problem is that when the doc.PrintOut line runs, word complains, popping up a message:
I've tried all sorts of combinations of things, but the error message persists. Very occasionally, the thing actually works and generates a usable pcl file, but 98% of the time, the error message pops up and the whole process grinds to a halt.
We have other applications on the same server which do almost exactly the same thing, except they print from excel instead of word, and they work without throwing the error.
Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不知道这是否有帮助,但是您的计算机上有防病毒软件吗?如果是这样,您是否尝试禁用它?有时,病毒扫描程序在后台访问文件、阻止访问或删除临时文件时会出现问题。
Don't know if this helps, but do you have an antivirus software on that machine? If so, did you try to disable it? There are sometimes issues with virus scanners accessing files in background, blocking access or deletion of temporary files.
我刚刚想通了。显然,您必须在尝试写入文件之前创建该文件。
例如:
我之前尝试过创建文件,但没有意识到 Create 返回了一个文件流,需要在 word 打印出来之前关闭该文件流。
有没有什么方法可以在 vb.net 中创建一个文件,而不会在带有文件流对象的文件上创建锁定?这个版本可以工作,但最好稍微清理一下代码。
I just figured it out. Apparently you have to create the file before you attempt to write to it.
eg:
I'd tried creating the file earlier, but didn't realize that Create returned a filestream which needed to be closed before word would print out to it.
Is there any way to create a file in vb.net that doesn't create a lock on a file with a filestream object? This version works, but it'd be nice to clean up the code a bit.