以编程方式打印PDF文档 [英] Programmatically print PDF documents

查看:224
本文介绍了以编程方式打印PDF文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在一个项目中,必须将PDF报告打印到特定打印机.

我尝试了几种方法(包括MigraDoc和其他方法),但到目前为止我唯一能找到的简单解决方案是打开带有正确参数的Adobe Acrobat Reader副本,以使其打印.

此解决方案有2个问题:
1.它需要一台专用服务器,因为每次打印报告时Adobe都会弹出,即使参数指定应保持最小化. (这是一个常见问题)
2.每10个文档中几乎随机地打印一次,而没有将正确的文档名称传递给打印机,导致文档名称为"本地下层文档",并且由于我密切关注线轴为了向用户提供有关报告打印的反馈,我无法识别假脱机中的文档或将其与正确的报告匹配.

有人在打印PDF方面有经验吗?有更好的解决方案吗?

Hi
I''m working on a project in which I have to print PDF reports to specific printers.

I''ve tried a few approaches (including MigraDoc and others) but the only simple solution I could find so far, was opening a copy of Adobe Acrobat Reader with the correct parameters, causing it to print.

This solution has 2 problems:
1. It needs a dedicated server since Adobe pops-up every time a report is printed, even though the parameters specify that it should remain minimized. (This is a common problem)
2. More-or-less-randomly one in every 10 documents print without passing the correct document name to the printer, resulting in a document name of "Local Downlevel Document" and since I closely watch the spool in order to give feedback to the user regarding the printing of the report, I cannot identify the document in the spool or match it to the correct report.

Anyone here with experience in printing PDF''s? Are there better solutions?

推荐答案

您可以尝试一些选项.由于只需要打印文档,因此只需要一种查看器.在codeproject上有一个示例用于此目的:

未安装Acrobat Reader的PDF查看器控件 [
There are some options you could try. Since you only need to print the documents you only need a kind of viewer. There is an example here on codeproject for this:

PDF Viewer Control Without Acrobat Reader Installed[^]

Good luck!


好.看起来我发现了我的问题.因此,为了完整性起见,以及让下一个可怜的人遇到这个本地下级文档"问题,请阅读:

如果我的假设是正确的,则似乎Windows (在我的情况下是Windows 7) 创建新的Print-Job时,默认文档名称始终为本地下级文档".

然后,Windows立即将文档名称"更新为正确的名称(通常是文件名,但因应用程序而异).

现在,如果您正在使用WMI查询来获取打印作业信息,则可能是随机发生的,您在创建Printjob之后立即对它进行了轮询,但是在其名称更正之前,当您获得该名称时,便会进行轮询错误的文档名称.

所以我的解决方法很简单,对于每个WMI查询迭代,我不仅刷新每个作业的状态,而且刷新文档的名称 (自从我最初没有这么做)完全以为文档名称永远不会更改) .

问题已解决.
Ok. Looks like I''ve found my problem. So for completeness sake and for the next poor soul to come across this "Local Downlevel Document" problem please read this:

If I''m correct in my assumptions, it seems that when Windows (Windows 7 in my case) creates a new Print-Job, the default Document Name is always "Local Downlevel Document".

Windows then immediately updates the Document Name to the correct name (usually the filename, but it will vary from app to app).

Now, if you are using a WMI Query to get the print job info, it may happen at random that you poll a Printjob right after it was created, but just before it''s name was corrected, and THAT"S when you get the wrong document name.

So my fix was simple, for each WMI query iteration, I do not only refresh each job''s status, but also it''s document name (which I didn''t do at first since I justly assumed that the document name will never change).

Problem Solved.


这篇关于以编程方式打印PDF文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆