打印任何类型的文档.doc,.docx,.pdf,.xslx,.png等.C# [英] Print any type of document .doc, .docx, .pdf, .xslx, .png etc. C#

查看:147
本文介绍了打印任何类型的文档.doc,.docx,.pdf,.xslx,.png等.C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,要求在服务器端打印任何类型的文档到提供的打印机。 1.我的应用程序托管在IIS服务器上。 2.从客户端,即从UI请求开始打印到Web API。 3.由于应用程序托管在IIS .net ProcessStart选项不起作用。也不允许更改应用程序池标识及其权限,以便放弃这个想法。



请提供/建议我提到的方案的替代解决方案。



我尝试了什么:



我试过.net system.Diagnostic进程类打印使用PrintTo动词的文件。

但是我的应用程序托管在IIS中,因此无法实现它。

In my project there is a requirement , to print any type of documents to provided printer on server side. 1. My application hosted on IIS server. 2. From client side i.e. from UI request initiate for printing to web API. 3. As application is hosted in IIS .net ProcessStart option not working. Also not allowed to change application pool identity and its rights so that this idea dropped.

Please provide/suggest me the alternative solution for mentioned scenario.

What I have tried:

I tried .net system.Diagnostic Process class to print files using PrintTo verb.
But my application is hosted in IIS so unable to achieve it.

推荐答案

当然从服务器端打印对于客户端涉及一个非常复杂的打印机选择(甚至服务器可以访问所有打印机),但我留给你(我甚至没有提到安装所有这些基于UI的工具的服务器有多么错误)...

右键单击资源管理器中的文件时,您 - 主要是 - 在打开旁边的某个位置获取打印/打印到选项...

资源管理器可以添加该菜单项基于存储在注册表中的每个扩展名(文件类型)的信息......

你可以做同样的事情...

例如,如果你有.txt(文本)文件,你可以去注册表并检索打印命令来打印该文件...

Of course printing from the server side for the client is involves a very complicated printer selection (even server can access all printers), but I leave that for you (And I not even mention how wrong is to have a server with all those UI based tools installed on)...
When you right click a file in Explorer you - mostly - get a Print/Print To option somewhere next to Open...
Explorer can add that menu item based on info stored in the registry for each and every extension (file type)...
You can do the same...
For instance if you have a .txt (text) file you can go to the registry and retrieve the print command to print that file...
string szExt = Registry.GetValue("HKEY_CLASSES_ROOT\\" + ext, string.Empty, null);
string szPrintTo = Registry.GetValue(string.Format(@"HKEY_CLASSES_ROOT\{0}\shell\Printto\command", szExt), string.Empty, null);



所有你需要做的就是更换参数(%1,%2)与您的文件和执行命令(使用过程)...


All you have to do is replace the parameters (%1, %2) with your files and execute the command (using Process)...


这根本不可行,在某些情况下,不可能这样做。



为了打印所有这些文件,你需要在服务器上安装可以读取和渲染你想要的那些文件格式的软件。支持。



其中一些扩展只能从Microsoft Office打印,不能从Web服务器或任何其他无人值守的进程(如Windows服务)使用。



没有打印任何文件类型的通用方法!您可以使用软件打印每种特定文件类型,也可以不打印。
This isn't going to be practical at all, and in some cases, impossible to do.

In order to print all of those files, you would need software installed on the server that can read and render every format of those files you want to support.

Some of those extensions will only print from Microsoft Office, which you can NOT use from a web server, or any other unattended process, like a Windows Service.

There is no generic method for printing any file type you want! You either have the software to print each specific file type or you don't print it.


这篇关于打印任何类型的文档.doc,.docx,.pdf,.xslx,.png等.C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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