C#:打印出Word文档而不保存它在事先document.PrintOut() [英] C#: print out Word document without saving it in advance document.PrintOut()

查看:59
本文介绍了C#:打印出Word文档而不保存它在事先document.PrintOut()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打印出Word文档而不预先保存.这可能吗?

I want to print out a Word document without saving it in advance. Is this possible?

//I created an instance for word app  
Microsoft.Office.Interop.Word.Application winword = new Microsoft.Office.Interop.Word.Application();

//I created a Word document (including pararaphs and tables):
Microsoft.Office.Interop.Word.Document document = winword.Documents.Add(ref missing, ref missing, ref missing, ref missing);

//I can print the document, if I save it before. But I want to print it without saving the word document.
document.SaveAs2(@"C:\User\\Desktop\Test");
document.PrintOut()

//Export of the document as pdf-file. 
document.ExportAsFixedFormat(label24.Text + "Document" + textBox13.Text, WdExportFormat.wdExportFormatPDF, true);

推荐答案

如果问题是文档在打印作业完成之前就已关闭,那么最好的方法是至少在以下时间内关闭后台打印代码执行.

If the problem is that the document is closing before the print job has completed, then the best approach is to turn off background printing, at least for the duration of code execution.

winword.Options.PrintBackground = false;

引入背景打印是为了允许用户在处理打印作业时继续工作.对用户来说这很好,但是对于代码(例如问题中的代码)来说却是一个问题.

Background printing was introduced in order to allow the user to continue working while a print job was processing. This is fine for the user, but a problem for code such as that in the question.

这篇关于C#:打印出Word文档而不保存它在事先document.PrintOut()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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