Word控件Spire.Doc 【打印】教程(3):如何在自定义纸张尺寸上打印 Word—C#/VB.NET

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)icon-default.png?t=N3I4https://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,如果您有其他问题也可以继续浏览本系列文章,欢迎咨询~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值