文档打印在工作中很常用,本篇文章将介绍一种在C#中通过第三方免费组件Free Spire.Doc for .NET来实现Word文档中打印的方法。这里提供了两种可供选择的打印方法,即静默打印和弹出对话框打印。文章转载自http://www.cnblogs.com/Yesi/p/6000247.html?
需要打印的原Word文档截图如下:

?下面是实现文档打印的全部代码,供参考:
class="c#">using System;
using Spire.Doc;
using System.Windows.Forms;
namespace Doc_Print
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// 创建一个Documnet类对象
Document doc = new Document();
// 加载需要打印的Word文档
doc.LoadFromFile(@"C:\Users\Administrator\Desktop\示例文档.doc");
// 实例化System.Windows.Forms.PrintDialog对象
PrintDialog dialog = new PrintDialog();
dialog.AllowPrintToFile = true;
dialog.AllowCurrentPage = true;
dialog.AllowSomePages = true;
dialog.UseEXDialog = true;
// 关联doc.PrintDialog属性和PrintDialog对象
doc.PrintDialog = dialog;
// 后台打印
// PrintDocument printDoc = doc.PrintDocument;
// printDoc.Print();
// 显示打印对话框并打印
if (dialog.ShowDialog() == DialogResult.OK)
{
//printDoc.Print();
}
}
}
}
打印文档过后XPS格式的截屏:
??
?
?