使用 Adobe Acrobat 静默打印 PDF
我在尝试使用 adobe acrobat 在 C# 中以静默方式打印 pdf 时遇到 2 个问题。我正在使用 Process.Start() 打印 pdf。
第一个问题是,如果不指定可执行文件的完整路径,我将无法启动 Adobe Acrobat。我认为当您安装它时它不会将其添加到您的路径中。 是否有一种简单的方法可以在不指定完整路径名的情况下在计算机上启动最新版本的 acrobat? 我担心客户端会进行更新并破坏我启动此版本的代码。我还担心他们在具有不同版本 Windows 的计算机上安装此程序(64 位环境与 32 位环境中的安装路径不同)。
我的第二个问题是,每当我启动 acrobat 并打印它时,acrobat 窗口仍然打开。我认为我使用的命令行参数会抑制所有这些,但显然不会。
我尝试使用以下语法从命令行启动 adobe acrobat:
C:\Program Files (x86)\Adobe\Reader 10.0\Reader>AcroRd32.exe /t "Label.pdf" "HP4000" " HP LaserJet 4100 Series PCL6" "out.pdf"
打印效果很好,但 acrobat 窗口仍然处于打开状态。 除了以编程方式终止进程之外,还有其他解决方案吗?
I'm having 2 issues when trying to print a pdf silently in C# using adobe acrobat. I'm printing the pdfs using Process.Start().
The first issue is that I cannot launch Adobe Acrobat without specifying the full path to the executable. I assume it doesn't add it to your path when you install it. Is there an easy way to launch the newest version of acrobat on a machine without specifying full path names? I'm worried that the client is going to do an update and break my code that launches this. I'm also concerned with them installing this on machines with different versions of windows (install paths are different in 64 bit environment vs. 32 bit).
My second problem is the fact that whenever I launch acrobat and print it still leaves the acrobat window open. I thought that the command line parameters I was using would suppress all of this but apparently not.
I'm trying to launch adobe acrobat from the command line with the following syntax:
C:\Program Files (x86)\Adobe\Reader 10.0\Reader>AcroRd32.exe /t "Label.pdf" "HP4000" "HP LaserJet 4100 Series PCL6" "out.pdf"
It prints out fine but it still leaves the acrobat window up. Is there any other solution besides going out and killing the process programmatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
我最终放弃了 Adobe Acrobat,并使用 FoxIt Reader (免费 pdf 阅读器) ) 进行 pdf 打印。这是我用来通过 FoxIt 在 C# 中进行打印的代码:
上面的代码打印到默认打印机,但您可以使用命令行参数来指定文件和打印机。您可以使用以下语法:
Foxit Reader.exe -t "pdf filename" "printer name"
更新:
显然早期版本的 acrobat 也没有上述问题。如果您使用更旧的版本(4.x 或类似版本),则不会出现此问题。
有些打印机也支持本机 pdf 打印,因此可以将原始 pdf 数据发送到打印机并进行打印。请参阅https://support.microsoft.com/en-us/kb/322091 用于将原始数据发送到打印机。
更新 2
在我们软件的更高版本中,我们最终使用了付费产品:
http://www.pdfprinting.net/
I ended up bailing on Adobe Acrobat here and going with FoxIt Reader (Free pdf reader) to do my pdf printing. This is the code I'm using to print via FoxIt in C#:
The above code prints to the default printer but there are command line parameters you can use to specify file and printer. You can use the following syntax:
Foxit Reader.exe -t "pdf filename" "printer name"
Update:
Apparently earlier versions of acrobat do not have the problem outlined above either. If you use a much older version (4.x or something similar) it does not exhibit this problem.
Some printers do support native pdf printing as well so it's possible to send the raw pdf data to the printer and it might print it. See https://support.microsoft.com/en-us/kb/322091 for sending raw data to the printer.
Update 2
In later versions of our software we ended up using a paid product:
http://www.pdfprinting.net/
Nick 的答案对我来说看起来不错,所以我将其翻译成 c#。有用!
}
Nick's answer looked good to me, so I translated it to c#. It works!
}
我尝试过 Adobe Reader 和 Foxit,但没有成功。两者的当前版本都非常喜欢弹出窗口并让进程保持运行。最终使用了 Sumatra PDF,它非常不引人注目。这是我使用的代码。打印完成后,没有任何窗口和进程的痕迹很好地退出。
I've tried both Adobe Reader and Foxit without luck. The current versions of both are very fond of popping up windows and leaving processes running. Ended up using Sumatra PDF which is very unobtrusive. Here's the code I use. Not a trace of any windows and process exits nicely when it's done printing.
以下内容在 Acrobat Reader 8.1.3 和 Acrobat Pro 11.0.06 中进行了测试,并确认了以下功能:
The following is tested in both Acrobat Reader 8.1.3 and Acrobat Pro 11.0.06, and the following functionality is confirmed:
问题 1
您也许可以通过注册表解决问题。在
HKEY_CLASSES_ROOT\.pdf\PersistentHandler\(Default)
中,您应该找到一个 CLSID,该 CLSID 指向在两个位置之一找到的值。同一密钥的 CLSID 文件夹,或者(对于 64 位系统)在Wow6432Node\CLSID
中向下一步,然后在该 CLSID 的密钥中。在该键中,您可以查找
LocalServer32
并找到指向当前 exe 路径的默认字符串值。我并不是 100% 同意这一点,但似乎是有道理的(尽管您必须在多个环境中进行验证,以确认实际上找到了您正在寻找的进程)。
(以下是有关涉及的注册表项 关于 PersistentHandlers)
问题 2
可能使用 CreateNoWindow<进程启动信息的 /a>。
(不过只是猜测,但我确信一点测试将证明它有效/无效)
Problem 1
You may be able to work your way around the registry. In
HKEY_CLASSES_ROOT\.pdf\PersistentHandler\(Default)
you should find a CLSID that points to a value found in one of two places. Either the CLSID folder of the same key, or (for 64 bit systems) one step down inWow6432Node\CLSID
then in that CLSID's key.Within that key you can look for
LocalServer32
and find the default string value pointing to the current exe path.I'm not 100% on any of this, but seems plausible (though you're going to have to verify on multiple environments to confirm that in-fact locates the process you're looking for).
(Here are the docs on registry keys involved regarding PersistentHandlers)
Problem 2
Probably using the CreateNoWindow of the Process StartInfo.
(only a guess however, but I'm sure a little testing will prove it to work/not work)
如果您使用 Acrobat reader 4.0,您可以执行以下操作:
“C:\Program Files\Adobe\Acrobat 4.0\Reader\Acrord32.exe”/t /s“U:\PDF_MS\SM003067K08.pdf”Planning_H2
但如果 PDF 文件是在较新版本的 Acrobat 中创建的,则会打开一个不可见的窗口
If you use Acrobat reader 4.0 you can do things like this:
"C:\Program Files\Adobe\Acrobat 4.0\Reader\Acrord32.exe" /t /s "U:\PDF_MS\SM003067K08.pdf" Planning_H2
BUT if the PDF file has been created in a newer version of Acrobat an invisible window opens
得到了另一个解决方案..它是 stackOverflow 中其他片段的组合。当我调用 CloseMainWindow,然后调用 Kill .. adobe 关闭时
got another solution .. its combination of other snippets from stackOverflow. When I call CloseMainWindow, and then call Kill .. adobe closes down
对于问题 2
使用 /h 参数将在最小化窗口中打开 Acrobat 或 Adobe Reader。
例子:
C:\Program Files (x86)\Adobe\Reader 10.0\Reader>AcroRd32.exe **/h** /t "Label.pdf" "HP4000" "HP LaserJet 4100 Series PCL6" "out.pdf"
相关文档:https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/Acrobat_SDK_developer_faq.pdf#page=24
For Problem 2
Using /h param will open the Acrobat or Adobe Reader in minimized window.
Example:
C:\Program Files (x86)\Adobe\Reader 10.0\Reader>AcroRd32.exe **/h** /t "Label.pdf" "HP4000" "HP LaserJet 4100 Series PCL6" "out.pdf"
Related Documentation: https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/Acrobat_SDK_developer_faq.pdf#page=24
您可以使用免费 PDFium 库以静默方式打印任何 PDF,无需在系统上安装 Foxit 或 Adobe Acrobat。很多帖子中提到的任何其他非免费图书馆都是纯粹的骗局。只需使用 NuGET 将 PDFium 免费库添加到您的项目中,这里是您在静态方法中所需的所有代码:
任何问题只需评论这篇文章,我很高兴为您提供帮助
You can silent print any PDF with the free library PDFium, with no need of having Foxit or Adobe Acrobat installed on your system, on a silent way. Any other not free library mentioned in a lot of posts is pure scam. Just add the PDFium free library to your project by using NuGET and here is all the code you need in an static method:
Any issues just comment this post, I'm glad to help you with this
您已经尝试过与 Acrobat Reader 不同的东西,所以我的建议是忘记 GUI 应用程序并使用第 3 方命令行工具,例如 RawFilePrinter.exe
下载最新版本:https://bigdotsoftware.pl/rawfileprinter
You have already tried something different than Acrobat Reader, so my advice is forget about GUI apps and use 3rd party command line tool like RawFilePrinter.exe
Latest version to download: https://bigdotsoftware.pl/rawfileprinter
https://texwiki.texjp.org/?Adobe%20Acrobat%20Reader
https://texwiki.texjp.org/?Adobe%20Acrobat%20Reader