How to change page background color and font color

Hi, Support:

Is there any method to change page background color and font color?
For example:
The page background color of pdf is blue and the font color is white, now, I want to change the page background color to white, and the font color to black. How to get it?
Thanks for your help!

@ducaisoft

Please use following code snippet to change the Page Background Color:

foreach (var page in document.Pages)
{
  page.Background = Color.White;
}

You can find text from PDF using TextFragmentAbsorber and change color of found TextFragments as following:

Document pdfDocument = new Document(dataDir + "ExtractTextPage.pdf");                

TextFragmentAbsorber tfa = new TextFragmentAbsorber();
pdfDocument.Pages.Accept(tfa);
TextFragmentCollection tfc = tfa.TextFragments;
foreach (TextFragment tf in tfc)
{
    tf.TextState.ForegroundColor = Aspose.Pdf.Color.Black;
}

In case you face any issue, please let us know.

Thanks for your sample, I try it on version 20.7, but all failed.
The page background color and text font color can not be changed any more!
Input.pdf (97.9 KB)
Output.pdf (97.8 KB)

@ducaisoft

We were able to change the text color in your PDF, however the background color of page could not get changed using following code snippet:

Document pdfDocument = new Document(dataDir + "Input.pdf");

foreach (var page in pdfDocument.Pages)
{
 page.Background = Color.White;
}
TextFragmentAbsorber tfa = new TextFragmentAbsorber();
pdfDocument.Pages.Accept(tfa);
TextFragmentCollection tfc = tfa.TextFragments;
foreach (TextFragment tf in tfc)
{
 tf.TextState.ForegroundColor = Aspose.Pdf.Color.Black;
}
pdfDocument.Save(dataDir + "output20.7.pdf");

output20.7.pdf (98.5 KB)

Hence, we have logged an issue as PDFNET-48598 in our issue management system. We will investigate reasons behind it and keep you posted with its resolution status. Please have patience and give us some time.

We are sorry for the inconvenience.