翻譯|使用教程|編輯:胡濤|2023-05-08 13:46:36.977|閱讀 113 次
概述:在本文中,您將學習如何使用Spire.Doc for .NET實現如何在自定義紙張尺寸上打印 Word,歡迎查閱~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發,不依賴第三方軟件,不受其他國家的技術或法律法規限制,同時適配國產操作系統如中科方德、中標麒麟等,兼容國產文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
有時您可能希望根據自己的喜好打印 Word 文檔,例如,在自定義紙張尺寸上打印文件以使其更具個性化。在本文中,您將學習如何使用Spire.Doc for .NET實現此功能。
PM> Install-Package Spire.Doc
下表顯示了此場景中使用的核心類、方法和屬性的列表。
Name | 描述 |
文檔類 | 表示 Word 的文檔模型。 |
紙張大小類 | 指定一張紙的尺寸。 |
打印文檔類 | 定義一個可重復使用的對象,當從 Windows 窗體應用程序打印時,該對象將輸出發送到打印機。 |
PrintDocument.DefaultPageSettings 屬性 | 獲取或設置用作所有要打印頁面的默認頁面設置。 |
Document.PrintDocument 屬性 | 獲取 PrintDocument 對象。 |
DefaultPageSettings.PaperSize 屬性 | 設置自定義紙張尺寸。 |
Document.LoadFromFile() 方法 | 加載示例文檔。 |
PrintDocument.Print() 方法 | 打印文檔。 |
以下是在自定義紙張尺寸上打印 Word 的步驟。
【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,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
獲取更多信息請咨詢 ;技術交流Q群(767755948)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn