国产Word .NET库组件Spire.Doc系列教程(58):如何在C#/VB.NET中自定义纸张尺寸上打印 Word

*这么优秀的国产工具怎能错过呢!在线下单专享“一口价”,查看折扣价!想要获取更多福利的朋友可以咨询在线客服哦~


在自定义纸张尺寸上打印 Word

下表显示了此场景中使用的核心类、方法和属性的列表。

名称 描述
文件类 表示 Word 的文档模型。
纸张大小类 指定一张纸的尺寸。
打印文档类 定义从 Windows 窗体应用程序打印时将输出发送到打印机的可重用对象。
PrintDocument.DefaultPageSettings 属性 获取或设置用作要打印的所有页面的默认值的页面设置。
Document.PrintDocument 属性 获取 PrintDocument 对象。
DefaultPageSettings.PaperSize 属性 设置自定义纸张尺寸。
Document.LoadFromFile()方法 加载示例文档。
PrintDocument.Print() 方法 打印文档。

以下是在自定义纸张尺寸上打印 Word 的步骤。

  • 实例化一个Document对象
  • 使用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.DocImports System.Drawing.PrintingNamespace PrintWordClass ProgramPrivate Shared Sub Main(args As String())'Instantiate a Document object.Dim doc As New Document()'Load the documentdoc.LoadFromFile("Sample.docx")'Get the PrintDocument objectDim printDoc As PrintDocument = doc.PrintDocument'Customize the paper sizeprintDoc.DefaultPageSettings.PaperSize = New PaperSize("custom", 900, 800)'Print the documentprintDoc.Print()End SubEnd ClassEnd Namespace


是E-iceblue官方友好合作伙伴,如果您对spire.Doc兴趣,可以联系在线客服了解具体授权价格和使用机制。
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年9月12日
下一篇 2021年9月12日

相关推荐

发表回复

登录后才能评论