如何在 C# 中连接到打印驱动程序?

发布于 2024-12-12 03:21:00 字数 207 浏览 0 评论 0原文

我的任务是将 .pdf、.doc、.jpg、.xls、.txt、.bmp 文件类型转换为 .png 格式。我找到了一个可以做到这一点的打印驱动程序。

但如何连接到 .net 中的打印机驱动程序?这将是一个服务器端组件。我需要使用此打印驱动程序将文档打印到文件夹中。

我想知道如何才能做到这一点。

谢谢

I have an task of converting bunch of formats like .pdf, .doc, .jpg, .xls, .txt, .bmp file types into .png format. I found a print driver that does that.

But how do I connect to that printer driver in .net? This will a server side component. I need to print documents into a folder using this print driver.

I am wondering how that can be done.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笑着哭最痛 2024-12-19 03:21:00

根据您更新的评论,听起来您似乎正在寻求将各种图像和文档类型转换为单一常见图像类型。采用您提到的几种可能的源格式之一并将其转换为位图格式(例如 .PNG)的过程称为渲染或光栅化。您想要采用一种输入格式,将其渲染为位图表示形式,然后将其写入 .PNG 格式的文件。虽然当然可以使用打印驱动程序来执行此操作,但为此,您通常会依赖已安装的应用程序,该应用程序允许您将源文档传递给它以打印到驱动程序。为此,您希望能够以这种方式处理的每种源文件类型都需要安装一个应用程序,该应用程序可以从 shell 执行操作并执行您请求的操作。例如,如果您想使用 .DOC 文件执行此操作,则需要安装 Microsoft Word,因为它可以正确响应 PRINT shell 命令。但是,基于 shell 的方法的局限性在于它始终会打印到 DEFAULT 系统打印机。因此,您的驱动程序需要设置为您要运行进程的机器的默认打印机。因此,您需要查看您希望能够处理的每种源类型是否都有已安装或可安装的应用程序,该应用程序将允许您使用 shell 和 PRINT 操作动词来打印它们。

参考 URL:

Windows Shell 动词和文件关联

创建快捷菜单处理程序

此技术的问题在于并非所有应用程序都正确或根本不响应 PRINT 动词。这通常适用于所有主要的 Microsoft 应用程序,但在进一步使用此技术之前,您应该测试您想要支持的任何其他文档类型。

这还引发了其他问题,这些问题甚至还没有开始解决,例如如何处理多种页面格式。您列出了一些简单的图像类型,可以直接转换为 PNG 文件。但是你想如何将多页Word文档文件渲染成PNG格式呢?您是否只打算制作一张非常大的 PNG,并将所有页面依次排列?或者您打算为每个相应的源文档页面准备一个 PNG 文件?打印驱动程序方法可能无法让您对此进行太多控制。

根据其中一些细节以及您在流程中需要多少控制和可靠性,您可能需要考虑采用完全不同的流程路线。也许您应该考虑使用可以读取您想要支持的源文件格式并直接渲染它们的工具/库,然后您可以保存到 PNG 文件中。我过去使用过的一个库似乎很适合并允许您对转换(渲染/光栅化)过程进行高度控制,它是 LeadTools。这是一个相当昂贵的产品,但我的经验是它确实可靠地支持多种格式。

LeadTools PDF 和文档阅读器 SDK

可能还有其他一些您可以使用可用的开源工具来支持此类功能,但我不熟悉任何可以向您指出任何特定内容的工具。但希望这可以帮助您提供一些信息,以了解如何组合一个可能更可靠的过程,并为您提供更好的控制,而不是试图强制打印机驱动程序做一些您可能不太能够可靠地工作的事情。

Based on your updated comments, it sounds as if you are looking to convert a variety of images and document types to a single common image type. The process of taking one of the several possible source formats you mention and convert it to a bitmapped format such as .PNG is referred to as RENDERING or RASTERIZING. You want to take one of the input formats, render it to a bitmap representation, then write it to a file in .PNG format. While it certainly might be possible to do this using a print driver, to do so, you would typically be relying on an installed application that would allow you to pass the source document to it for printing to the driver. For this to work, each of the source file types you want to be able to handle this way needs to have an application installed which can take actions from the shell and do what you request. So for example if you want to do this with a .DOC file, you need Microsoft Word installed as it does properly respond to the PRINT shell command. However, the limitation with the shell based method is that it is always going to print to the DEFAULT system printer. So your driver would need to be setup as the default printer for the machine you are going to run your process on. Therefore you would need to see if each of the source types you want to be able to handle have an installed or installable application which will allow you to print them using the shell and the PRINT action verb.

Reference URLs:

Windows Shell Verbs and File Associations

Creating Shortcut Menu Handlers

The problem with this technique is not all applications respond to the PRINT verb correctly or at all. This usually works with all the major Microsoft applications, but you should test any other document types you want to support before going much further with this technique.

This also raises other questions that this doesn't even begin to address such as what to do about multiple page formats. You listed a few image types that are straight-forward and can be converted to PNG files pretty directly. But how do you want to render a multiple page Word document files into PNG format? Do you intend for only one very large PNG with all the pages one after another? Or do you intend for one PNG file per corresponding source document page? The print driver method might not give you very much control over that.

Depending on some of these details and just how much control and reliability you need in the process, you might want to consider a completely different route to your process. Maybe you should consider using tools/libraries that can read the source file formats you want to support and render them directly, after which you can save into your PNG files. One library I have used in the past that would seem to fit and allow you a high degree of control over the conversion (rendering/rasterization) process is LeadTools. It is a fairly pricey product, but my experience with it has been that it does support a wide variety of formats reliably.

LeadTools PDF and Document Readers SDK

There may be some other open source tools available that you could pull together to support this type of functionality, but I'm not familiar with any to point you to anything specific. But hopefully this helps give you some information to look at putting together a process that might be more reliable and give you greater control than trying to coerce a printer driver to do something you might not quite be able to make work reliably.

辞旧 2024-12-19 03:21:00

服务器端组件意味着没有人坐在它旁边(至少没有人试图使用该打印机)。如果是这种情况,那么打印驱动程序将无法工作 - 根据我的经验,将输出写入磁盘而不是设备的打印驱动程序总是要求用户选择保存文件的位置(显示“另存为”对话框)。

Server-side component implies something that doesn't have a human sitting at it (at least, not the human that is trying to use that printer). If this is the case then a print driver will not work - Print drivers that write their output to disk instead of a device always, in my experience, ask the user to select a place to save the file (present a Save As dialog).

独享拥抱 2024-12-19 03:21:00

详细说明一下 Boo 提到的内容:

根据您使用的打印机驱动程序,您也许可以告诉它保存文件的位置。

问题是通过使用打印机,它通常的工作原理是您可以从任何应用程序打印到 .png 文件。但应用程序本身必须知道如何打开和呈现(而不是与打印机对话)原始文件的内容。

要继续沿着这条路走,您必须确保您的服务器组件知道如何读取和呈现每种文件类型(.jpg、.pdf、.doc 等)的内容。

假设您的服务器组件知道如何呈现内容,下一步是使用 .NET Printing 命名空间将内容打印到 .png 打印机。

有关更多详细信息,请访问:http://msdn.microsoft.com/en-us /杂志/cc188767.aspx

To elaborate a little bit on what Boo mentioned :

Depending on the printer driver you are using, you may be able to tell it where to save your file.

The problem is by using a printer, how it normally works is that you can print from any application to a .png file. But the application itself has to know how to open and render (not talk to the printer) the content of the original file.

To continue down this path, you have to make sure your server component knows how to read and render content of each file type (.jpg, .pdf, .doc, etc.).

Assuming your server component knows how to render the content, the next step from here is to use the .NET Printing namespace to print your content to the .png printer.

For more details go to : http://msdn.microsoft.com/en-us/magazine/cc188767.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文