翻譯|行業(yè)資訊|編輯:胡濤|2024-09-13 15:40:32.263|閱讀 81 次
概述:在本文中,您將學(xué)習(xí)如何使用Spire.PDF for .NET以編程方式設(shè)置 PDF 的背景顏色或圖像。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
在 PDF 文檔中,背景是指頁面內(nèi)容背后的整體視覺外觀。背景可以是簡單的純色,也可以是您選擇的圖像。向 PDF 添加背景可以幫助您增加文檔的視覺趣味,并提高可讀性。在本文中,您將學(xué)習(xí)如何使用Spire.PDF for .NET以編程方式設(shè)置 PDF 的背景顏色或圖像。
Spire.PDF for .NET 是一款獨(dú)立 PDF 控件,用于 .NET 程序中創(chuàng)建、編輯和操作 PDF 文檔。使用 Spire.PDF 類庫,開發(fā)人員可以新建一個(gè) PDF 文檔或者對現(xiàn)有的 PDF 文檔進(jìn)行處理,且無需安裝 Adobe Acrobat。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團(tuán)隊(duì)研發(fā),不依賴第三方軟件,不受其他國家的技術(shù)或法律法規(guī)限制,同時(shí)適配國產(chǎn)操作系統(tǒng)如中科方德、中標(biāo)麒麟等,兼容國產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
首先,您需要將 Spire.PDF for.NET 包中包含的 DLL 文件作為引用添加到您的 .NET 項(xiàng)目中。 可以從此鏈接下載 DLL 文件,也可以通過NuGet安裝。
PM> Install-Package Spire.PDF
Spire.PDF for .NET 提供的PdfPageBase.BackgroundColor屬性允許您將純色設(shè)置為 PDF 背景。以下是詳細(xì)步驟。
【C# 】
using Spire.Pdf; using System.Drawing; namespace PDFBackgroundColor { class Program { static void Main(string[] args) { //Create a PdfDocument instance PdfDocument pdf = new PdfDocument(); //Load a sample PDF file from disk pdf.LoadFromFile("input.pdf"); //Loop through the pages in the PDF file foreach (PdfPageBase page in pdf.Pages) { //Set the background color for each page page.BackgroundColor = Color.Yellow; //Set the opacity of the background page.BackgroudOpacity = 0.1f; } //Save the result PDF file pdf.SaveToFile("BackgroundColor.pdf"); pdf.Close(); } } }
【VB.NET 】
Imports Spire.PDF Imports System.Drawing Namespace PDFBackgroundColor Class Program Private Shared Sub Main(ByVal args() As String) 'Create a PdfDocument instance Dim pdf As PdfDocument = New PdfDocument 'Load a sample PDF file from disk pdf.LoadFromFile("input.pdf") 'Loop through the pages in the PDF file For Each page As PdfPageBase In pdf.Pages 'Set the background color for each page page.BackgroundColor = Color.Yellow 'Set the opacity of the background page.BackgroudOpacity = 0.1! Next 'Save the result PDF file pdf.SaveToFile("BackgroundColor.pdf") pdf.Close() End Sub End Class End Namespace
如果要添加圖像作為背景以匹配文檔主題,可以使用PdfPageBase.BackgroundImage屬性。以下是詳細(xì)步驟。
【C# 】
using Spire.Pdf; using System.Drawing; namespace PDFBackgroundColor { class Program { static void Main(string[] args) { //Create a PdfDocument instance PdfDocument pdf = new PdfDocument(); //Load a sample PDF file from disk pdf.LoadFromFile("input.pdf"); //Loop through the pages in the PDF file foreach (PdfPageBase page in pdf.Pages) { //Set the background color for each page page.BackgroundColor = Color.Yellow; //Set the opacity of the background page.BackgroudOpacity = 0.1f; } //Save the result PDF file pdf.SaveToFile("BackgroundColor.pdf"); pdf.Close(); } } }
【VB.NET 】
Imports Spire.PDF Imports System.Drawing Namespace PDFBackgroundColor Class Program Private Shared Sub Main(ByVal args() As String) 'Create a PdfDocument instance Dim pdf As PdfDocument = New PdfDocument 'Load a sample PDF file from disk pdf.LoadFromFile("input.pdf") 'Loop through the pages in the PDF file For Each page As PdfPageBase In pdf.Pages 'Set the background color for each page page.BackgroundColor = Color.Yellow 'Set the opacity of the background page.BackgroudOpacity = 0.1! Next 'Save the result PDF file pdf.SaveToFile("BackgroundColor.pdf") pdf.Close() End Sub End Class End Namespace
歡迎下載|體驗(yàn)更多E-iceblue產(chǎn)品
獲取更多信息請咨詢 ;技術(shù)交流Q群(767755948)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn