简体   繁体   English

如何以编程方式从C#Windows Forms应用程序将openoffice writer odt文件发送到打印机

[英]How to programatically send openoffice writer odt file to printer from C# Windows Forms Application

I'd like to send an OpenOffice writer document to the default printer from within a C# WinForms application. 我想从C#WinForms应用程序中将OpenOffice编写器文档发送到默认打印机。 The purpose is to print customer receipts. 目的是打印客户收据。 I plan on opening a prepared OpenOffice file, substitute dynamic customer information and then print the modified document. 我计划打开准备好的OpenOffice文件,替代动态客户信息,然后打印修改后的文档。 It is important that OO not necessarily be installed so solutions which depend on OO or open up an OO prompt won't work. 重要的是,不一定要安装OO,这样依赖于OO或打开OO提示的解决方案将无法工作。 Any suggestions would be appreciated. 任何建议,将不胜感激。

I too use open office for printing customer generated invoices, I do so in bulk and below is the method that I use. 我也使用开放式办公室打印客户生成的发票,我这样做是批量的,下面是我使用的方法。

What you are seeking is achievable by using "ProcessStartInfo" from the Systems.Diagnostics namespace found here: https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo(v=vs.110).aspx 通过使用Systems.Diagnostics命名空间中的“ ProcessStartInfo”,可以在此处找到所需的内容: https ://msdn.microsoft.com/zh-cn/library/system.diagnostics.processstartinfo( v= vs.110).aspx

the important part is ensuring you have set "CreateNoWindow" to true as well as settings the "WindowStyle" to "ProcessWindowStyle.Hidden". 重要的部分是确保将“ CreateNoWindow”设置为true以及将“ WindowStyle”设置为“ ProcessWindowStyle.Hidden”。

Simply pass in the location of the file to print, and ensure you include the file extension after the location. 只需输入要打印的文件的位置,并确保在该位置之后包括文件扩展名即可。 I use this snippet regularly so if you have any problems just let me know. 我会定期使用此代码段,因此,如果您有任何问题,请告诉我。

void printDoc(String fileLocation) {
    ProcessStartInfo info = new ProcessStartInfo(fileLocation);
    info.Verb = "print";
    info.CreateNoWindow = true;
    info.WindowStyle = ProcessWindowStyle.Hidden;
    Process.Start(info);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用C#的OpenOffice Writer的问题 - Problems with OpenOffice Writer using C# 使用C#将HTML文本插入.odt OpenOffice文档 - Insert html text into .odt OpenOffice document with C# 如何使用 C# 以编程方式从 Windows 窗体中的 DataGridView 中删除单元格? - How to remove a cell programatically from DataGridView in Windows Forms using C#? 如何在Windows窗体应用程序中的c#中将标准输出重定向到psexec进程中的文件 - How to redirect standard output to a file from psexec process in c# within a Windows Forms Application 如何在Windows Phone 8.1(C#)中以编程方式发送SMS - How to send SMS programatically in Windows Phone 8.1(C#) 如何在Windows 7中使用C#以编程方式打印到标签打印机 - How do I programatically print to a label printer in windows 7 using C# 如何在C#中退出Windows Forms应用程序 - How to exit a Windows Forms Application in C# 如何在C#Windows应用程序中以编程方式修改设置文件(app.config)的信息? - How to modify the information of the Settings file(app.config) programatically in C# windows Application? 如何在C#中从Windows应用程序发送电子邮件? - How to send Email from windows application in c#? 在浏览器中单击按钮后未打开ODT文件。 如何使用C#代码打开ODT文件? - ODT files not opened on button click in browser. How to open an ODT file using C# code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM