IT评测·应用市场-qidao123.com

标题: Spire.PDF for .NET【页面设置】演示:为 PDF 添加配景颜色或配景图像 [打印本页]

作者: 宝塔山    时间: 2024-9-17 17:41
标题: Spire.PDF for .NET【页面设置】演示:为 PDF 添加配景颜色或配景图像
在 PDF 文档中,配景是指页面内容背后的整体视觉外观。配景可以是简朴的纯色,也可以是您选择的图像。向 PDF 添加配景可以帮助您增长文档的视觉趣味,并进步可读性。在本文中,您将学习如何使用Spire.PDF for .NET以编程方式设置 PDF 的配景颜色或图像。
Spire.PDF for .NET 是一款独立 PDF 控件,用于 .NET 程序中创建、编辑和操作 PDF 文档。使用 Spire.PDF 类库,开发人员可以新建一个 PDF 文档或者对现有的 PDF 文档进行处理惩罚,且无需安装 Adobe Acrobat。
E-iceblue 功能类库Spire 系列文档处理惩罚组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理惩罚软件 WPS(如 .wps/.et/.dps 等格式
Spire.PDF for.net下载   
安装 Spire.PDF for .NET

起首,您必要将 Spire.PDF for.NET 包中包罗的 DLL 文件作为引用添加到您的 .NET 项目中。 可以从此链接下载 DLL 文件,也可以通过NuGet安装。
  
  1. PM> Install-Package Spire.PDF
复制代码
在 C# 和 VB.NET 中为 PDF 文档添加配景颜色

Spire.PDF for .NET 提供的PdfPageBase.BackgroundColor属性答应您将纯色设置为 PDF 配景。以下是详细步调。

【C# 】
  
  1. using Spire.Pdf;
  2. using System.Drawing;
  3. namespace PDFBackgroundColor
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. //Create a PdfDocument instance
  10. PdfDocument pdf = new PdfDocument();
  11. //Load a sample PDF file from disk
  12. pdf.LoadFromFile("input.pdf");
  13. //Loop through the pages in the PDF file
  14. foreach (PdfPageBase page in pdf.Pages)
  15. {
  16. //Set the background color for each page
  17. page.BackgroundColor = Color.Yellow;
  18. //Set the opacity of the background
  19. page.BackgroudOpacity = 0.1f;
  20. }
  21. //Save the result PDF file
  22. pdf.SaveToFile("BackgroundColor.pdf");
  23. pdf.Close();
  24. }
  25. }
  26. }
复制代码
【VB.NET 】
  
  1. Imports Spire.PDF
  2. Imports System.Drawing
  3. Namespace PDFBackgroundColor
  4. Class Program
  5. Private Shared Sub Main(ByVal args() As String)
  6. 'Create a PdfDocument instance
  7. Dim pdf As PdfDocument = New PdfDocument
  8. 'Load a sample PDF file from disk
  9. pdf.LoadFromFile("input.pdf")
  10. 'Loop through the pages in the PDF file
  11. For Each page As PdfPageBase In pdf.Pages
  12. 'Set the background color for each page
  13. page.BackgroundColor = Color.Yellow
  14. 'Set the opacity of the background
  15. page.BackgroudOpacity = 0.1!
  16. Next
  17. 'Save the result PDF file
  18. pdf.SaveToFile("BackgroundColor.pdf")
  19. pdf.Close()
  20. End Sub
  21. End Class
  22. End Namespace
复制代码


使用 C# 和 VB.NET 将配景图像添加到 PDF 文档

如果要添加图像作为配景以匹配文档主题,可以使用PdfPageBase.BackgroundImage属性。以下是详细步调。

【C# 】
  
  1. using Spire.Pdf;
  2. using System.Drawing;
  3. namespace PDFBackgroundColor
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. //Create a PdfDocument instance
  10. PdfDocument pdf = new PdfDocument();
  11. //Load a sample PDF file from disk
  12. pdf.LoadFromFile("input.pdf");
  13. //Loop through the pages in the PDF file
  14. foreach (PdfPageBase page in pdf.Pages)
  15. {
  16. //Set the background color for each page
  17. page.BackgroundColor = Color.Yellow;
  18. //Set the opacity of the background
  19. page.BackgroudOpacity = 0.1f;
  20. }
  21. //Save the result PDF file
  22. pdf.SaveToFile("BackgroundColor.pdf");
  23. pdf.Close();
  24. }
  25. }
  26. }
复制代码
【VB.NET 】
  
  1. Imports Spire.PDF
  2. Imports System.Drawing
  3. Namespace PDFBackgroundColor
  4. Class Program
  5. Private Shared Sub Main(ByVal args() As String)
  6. 'Create a PdfDocument instance
  7. Dim pdf As PdfDocument = New PdfDocument
  8. 'Load a sample PDF file from disk
  9. pdf.LoadFromFile("input.pdf")
  10. 'Loop through the pages in the PDF file
  11. For Each page As PdfPageBase In pdf.Pages
  12. 'Set the background color for each page
  13. page.BackgroundColor = Color.Yellow
  14. 'Set the opacity of the background
  15. page.BackgroudOpacity = 0.1!
  16. Next
  17. 'Save the result PDF file
  18. pdf.SaveToFile("BackgroundColor.pdf")
  19. pdf.Close()
  20. End Sub
  21. End Class
  22. End Namespace
复制代码



免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/) Powered by Discuz! X3.4