通过.net打印不同类型的文件 [英] print different type of file through .net

查看:55
本文介绍了通过.net打印不同类型的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Windows应用程序,该应用程序需要用户选择文件夹,此文件夹将检索所有文件并打印到我的打印机.在此文件夹中,多种类型的文件,如word文件,excel文件,PDF文件,文本文件等.如何通过.net进行访问.请给出可用的示例或简要说明.

I am create a windows application which need to user select the folder and this folder retrieve all file and print to my printer. In this folder many type of file such as word file, excel file, PDF file, text file etc. how are possible through in .net. please give example is available or brief idea.

推荐答案

使用以下代码(它将打印那些已在系统中使用相关应用程序注册的文件):

Use the following code ( it will print those files which have been registered on the system with their respected application):

FolderBrowserDialog fbd = new FolderBrowserDialog();
if(fbd.ShowDialog() == DialogResult.OK)
{
    foreach (var fn in Directory.GetFiles(fbd.SelectedPath)) 
    {
       var pi = new ProcessStartInfo(fn);
       pi.Verb = "Print";
 
       Process.Start(pi);
    }
}


嗯,文本文件应该很容易.

无论如何,您都需要在System.Drawing.Printing [
或者,您将不得不使用中央集线器"解决方案,例如使用开源PostScript转换器"GhostScript".

如果在CodeProject中搜索,您肯定会找到可以帮助您从.NET打印某些格式的文章,例如:[
^ ].

另一个选择可能是第三.诸如Aspose之类的公司的第三方组件专门研究这些类型的解决方案.

而且,谁知道,也许有人会在这里做出回应,并说明如何使用Windows Script Host或其他方法进行此操作.
Well, text files should be easy.

In any case you are going to need to explore the PrintDocument Class in System.Drawing.Printing[^].

But, do you mean ... if you have a folder with one PDF file, one Excel File, and one MS Word file ... you want each of those documents printed exactly as if they were being printed from Acrobat, Excel, and Word ?

If that''s what you mean, I don''t think you will be able to do this for a broad range of applications. To do this you will have to "automate" those applications: launch them, send them the appropriate "messages" to tell them to print, and how to set-up the printer configuration.

Or, you will have to go with a "central hub" solution such as using ''GhostScript'' the open-source PostScript converter.

If you search in CodeProject, you will certainly find articles that will help you print certain formats from .NET, for example:[^].

Another alternative may be 3rd. party components from companies, like Aspose, that specialize in these types of solutions.

And, who knows, maybe someone will respond here and show how to use Windows Script Host or something else to take this on.


这篇关于通过.net打印不同类型的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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