Spire.PDF for .NET【页面设置】演示:为 PDF 添加配景颜色或配景图像 ...

打印 上一主题 下一主题

主题 1026|帖子 1026|积分 3078

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
在 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 配景。以下是详细步调。


  • 创建一个PdfDocument实例。
  • 使用PdfDocument.LoadFromFile()方法加载示例 PDF 文件。
  • 循环遍历所有 PDF 页面并使用PdfPageBase.BackgroundColor属性为每个页面添加配景颜色。
  • 使用PdfPageBase.BackgroudOpacity属性设置配景的不透明度。
  • 使用PdfDocument.SaveToFile()方法保存效果文档。
【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属性。以下是详细步调。


  • 创建一个PdfDocument实例。
  • 使用PdfDocument.LoadFromFile()方法加载示例 PDF 文件。
  • 循环遍历所有 PDF 页面并使用PdfPageBase.BackgroundImage属性为每个页面添加配景图片。
  • 使用PdfPageBase.BackgroudOpacity属性设置配景的不透明度。
  • 使用PdfDocument.SaveToFile()方法保存效果文档。
【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企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

宝塔山

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表