MigraDoc provides built-in classes like Color and ColorTable to represent colors within your PDF. You can access these colors and analyze them to determine if the PDF contains any color other than black.
font generatorFor a simple approach, you can use:
Code:
using MigraDoc.DocumentObjectModel;
// ... (your code)
bool isColored = false;
foreach (Section section in document.Sections) {
foreach (Paragraph paragraph in section.Paragraphs) {
Color paragraphColor = paragraph.Format.Font.Color;
if (paragraphColor.A != 0 || paragraphColor.R != 0 || paragraphColor.G != 0 || paragraphColor.B != 0) {
isColored = true;
break;
}
}
// Check for colors in tables, images, and other elements
foreach (Table table in section.Tables) {
// Iterate through table cells, borders, and fills to check for colors
}
// Similar logic for images and other elements
}
if (isColored) {
Console.WriteLine("The PDF contains color elements.");
} else {
Console.WriteLine("The PDF likely uses black and white content.");
}