This how-to tutorial details how to edit PDF background color using C#. It has complete information about the resources required to run the sample code, a list of commands, and a runnable sample code to change PDF background color using C#. You may edit the background of all the pages or selected pages based upon some criteria and also modify the output PDF file before saving the resultant PDF file on the disk.
Steps to Change Background Color in PDF using C#
- Set the environment to use Aspose.PDF for .NET to change the page color
- Load the source PDF file using the Document class to set the background
- Parse through the entire collection of pages in the PDF
- Set the Color for Page.Background property of each page
- Save the PDF
These steps summarize the process to change page color in PDF using C#. The process is quite simple: firstly, the source PDF file is loaded and then the complete collection of pages is parsed. In the final step, the background property is set with the Color value however, you may set other properties of each page as well. Also, the resultant PDF file can be customized by changing different properties, for instance, setting some watermarks or rotating the page to name a very few.
Code to Change the Background Color of a PDF using C#
The aforementioned code describes the process of PDF background color change using C#. In this code sample, we have changed the background color of all the pages however you may set different colors for different pages, for instance, setting different colors for portrait and landscape pages, or setting different colors based on the previous color of the page. Along with changing the background, you may also change the MediaBox, ArtBox, BleedBox, CropBox, or TrimBox.
This quick guide has explained how to change background color of PDF using C# If you need the information to adjust the size of the PDF, refer to the article on how to change page size of PDF using C#.