如何以编程方式打印各种文件类型 [英] How to print various file types programmatically

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

问题描述

我写这一些测试,并产生了许多不同的报告的应用程序。这些可能是标签的任意组合,PDF为最终客户,PDF维修部门,XML文件等。



根据报告类型,我需要将文件发送到任一文件系统或到多个不同的打印机(A4,标签等)中的一个。理想情况下,应该没有弹出窗口 - 只是直纸



我怎么能一个文件(PDF,XML)发送到打印机?我原以为,对XML /文本我可以只File.Copy以趋化因子,但似乎并没有工作。对于PDF我猜,我可以打电话的Acrobat的一些参数,使要打印的PDF。



我使用的打印机映射到趋化因子。有没有更好的办法做到这一点,并存储在应用程序中的定义是什么?即标签去MyLabelPrinter和A4 PDF文件得到了MyA4Printer。



有没有人这样做呢?


解决方案

 的ProcessStartInfo信息=新的ProcessStartInfo([路径文件]); 
info.Verb =PrintTo;
info.Arguments =\[打印机名称] \;
info.CreateNoWindow = TRUE;
info.WindowStyle = ProcessWindowStyle.Hidden;
的Process.Start(信息);


I am writing an app which performs some tests and produces a number of different reports. These may be any combination of Labels, PDF for end customer, PDF for repair department, XML file etc.

Depending on the report type, I need to send the file to either the file system or to one of a number of different printers (A4, label etc). Ideally there should be no popup windows - just straight to paper.

How can I send a file (PDF, XML) to a printer? I had thought that for XML/Text I could just File.Copy to LPTn but that doesn't seem to work. For PDF I'm guessing that I could call Acrobat with some parameters which cause the PDF to be printed.

The printers I use are mapped to LPTn. Is there a better way to do this and to store the definitions in the app? i.e. Labels go to MyLabelPrinter and A4 PDFs got to MyA4Printer.

Has anyone done this?

解决方案

ProcessStartInfo info = new ProcessStartInfo("[path to your file]");
info.Verb = "PrintTo";
info.Arguments = "\"[printer name]\"";
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(info);

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

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