Using C# PDF SDK
C# PDF Library: how to add, remove, update PDF page background using c#
C# Demo Code to add, remove, update PDF page background using c#
Apply Page Background settings to a PDF document object
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
String outputFilePath = Program.RootPath + "\\" + "1_backgd.pdf";
// open a PDF file
PDFDocument doc = new PDFDocument(inputFilePath);
PDFBackgroudRes resBackground = new PDFBackgroundFillColorRes(Color.Yellow);
{
// define a page background setting
PDFPageBackground background1 = new PDFPageBackground(resBackground);
background1.Opacity = 0.2F;
// define page range: all odd pages
PageRangeOptions pageRange1 = new PageRangeOptions();
pageRange1.AllPages = true;
pageRange1.Subset = PageRangeSubset.Odd;
// apply page background settings to all odd pages
PDFPageFieldHandler.ApplyBackground(doc, background1, pageRange1);
}
{
// define a page background setting
PDFPageBackground background2 = new PDFPageBackground(resBackground);
background2.Opacity = 0.2F;
// define page range: all even pages
PageRangeOptions pageRange2 = new PageRangeOptions();
pageRange2.AllPages = true;
pageRange2.Subset = PageRangeSubset.Even;
// apply page background settings to all even pages
PDFPageFieldHandler.ApplyBackground(doc, background2, pageRange2);
}
doc.Save(outputFilePath);
Remove all Page Background settings in a PDF document object
String inputFilePath = Program.RootPath + "\\" + "1_backgd.pdf";
String outputFilePath = Program.RootPath + "\\" + "output.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
PDFPageFieldHandler.RemoveBackgrounds(doc);
doc.Save(outputFilePath);
Retrieve all Page Background settings from a PDF file
String inputFilePath = Program.RootPath + "\\" + "1_backgd.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
// get all Background settings in the document
PDFPageBackgroundInfo info = PDFPageFieldHandler.RetreiveBackgrounds(doc);
// get default setting for Background and Page Range
PDFPageBackground defaultSetting = info.GetDefaultSetting();
PageRangeOptions defaultPageRange = info.GetDefaultPageRangeSettings();