Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近10年专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷。
E-iceblue 功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式
Spire.Doc for.NET 最新下载(qun:767755948)
https://www.evget.com/product/3368/download
有时您可能希望根据自己的喜好打印 Word 文档,例如,在自定义纸张尺寸上打印文件以使其更具个性化。在本文中,您将学习如何使用Spire.Doc for .NET实现此功能。
安装适用于 .NET 的 Spire.Doc
PM> Install-Package Spire.Doc
在自定义纸张尺寸上打印 Word
下表显示了此场景中使用的核心类、方法和属性的列表。
| Name | 描述 |
| 文档类 | 表示 Word 的文档模型。 |
| 纸张大小类 | 指定一张纸的尺寸。 |
| 打印文档类 | 定义一个可重复使用的对象,当从 Windows 窗体应用程序打印时,该对象将输出发送到打印机。 |
| PrintDocument.DefaultPageSettings 属性 | 获取或设置用作所有要打印页面的默认页面设置。 |
| Document.PrintDocument 属性 | 获取 PrintDocument 对象。 |
| DefaultPageSettings.PaperSize 属性 | 设置自定义纸张尺寸。 |
| Document.LoadFromFile() 方法 | 加载示例文档。 |
| PrintDocument.Print() 方法 | 打印文档。 |
以下是在自定义纸张尺寸上打印 Word 的步骤。
- 实例化一个文档对象
- 使用Document.LoadFromFile()方法加载示例文档。
- 使用Document.PrintDocument属性获取 PrintDocument 对象。
- 使用DefaultPageSettings.PaperSize属性设置自定义纸张尺寸。
- 使用PrintDocument.Print()方法打印文档。
【C#】
using Spire.Doc;
using System.Drawing.Printing;
namespace PrintWord
{
class Program
{
static void Main(string[] args)
{
//Instantiate a Document object.
Document doc = new Document();
//Load the document
doc.LoadFromFile(@"Sample.docx");
//Get the PrintDocument object
PrintDocument printDoc = doc.PrintDocument;
//Customize the paper size
printDoc.DefaultPageSettings.PaperSize = new PaperSize("custom", 900, 800);
//Print the document
printDoc.Print();
}
}
}
【VB.NET】
Imports Spire.Doc
Imports System.Drawing.Printing
Namespace PrintWord
Class Program
Private Shared Sub Main(args As String())
'Instantiate a Document object.
Dim doc As New Document()
'Load the document
doc.LoadFromFile("Sample.docx")
'Get the PrintDocument object
Dim printDoc As PrintDocument = doc.PrintDocument
'Customize the paper size
printDoc.DefaultPageSettings.PaperSize = New PaperSize("custom", 900, 800)
'Print the document
printDoc.Print()
End Sub
End Class
End Namespace
以上便是如何在自定义纸张尺寸上打印 Word,如果您有其他问题也可以继续浏览本系列文章,欢迎咨询~



















