PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat May 18, 2024 11:27 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun May 05, 2024 8:27 am 
Offline

Joined: Sun May 05, 2024 8:12 am
Posts: 1
Hello,

I am currently writing a program that categorizes PDFs by size an colour information.

It works well for scanned images which have only one rasterimage embedded.
I would like to expand the program to work with every PDF.

I simply need to know if there is any colour in a PDF or if its black and white.

My questions :

Is it right that i have do parse every element in each page and query its colour information
and how ist this done ?

Or is there an easier method ?

Thanks for any answer,

Chris


Top
 Profile  
Reply with quote  
PostPosted: Wed May 15, 2024 11:45 am 
Offline

Joined: Wed May 15, 2024 7:06 am
Posts: 1
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 generator
For 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.");
}


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 31 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group