Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
![]() |
Colour Detection on Page |
Post Reply
|
| Author | |
making
Beginner
Joined: 09 Jan 14 Location: UK Status: Offline Points: 5 |
Post Options
Thanks(0)
Quote Reply
Topic: Colour Detection on PagePosted: 09 Jan 14 at 11:20PM |
|
Hi All,
This is my first post so please be gentle |
|
![]() |
|
Ingo
Moderator Group
Joined: 29 Oct 05 Status: Offline Points: 3530 |
Post Options
Thanks(0)
Quote Reply
Posted: 12 Jan 14 at 1:41PM |
|
Hi Making,
there's a lot you can "see" without a pdf-library. Please read my blog here: http://pdfcomments.blogspot.de/2009/09/under-surface.html What you're looking for is code like the following: // ... // textcomplete contains the filecontent ... devrgb := CountSubStr('/DEVICERGB', UpperCase(textcomplete)); devcmyk := CountSubStr('/DEVICECMYK', UpperCase(textcomplete)); devgray := CountSubStr('/DEVICEGRAY', UpperCase(textcomplete)); // ... Cheers and welcome here, Ingo |
|
|
Cheers,
Ingo |
|
![]() |
|
AndrewC
Moderator Group
Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
Post Options
Thanks(0)
Quote Reply
Posted: 14 Jan 14 at 11:13AM |
|
A complex question.
Ingo's answer is a good solution. Another idea is to render the PDF to a low DPI BMP file and then manually counting the colours. There is no easy solution to this. Another option is to call QP.GetPageColorSpaces functions to see which colorspaces are directly referenced. You will need to do testing with each solution to make sure it is working correctly with your PDF's. The PDF spec is very complex and there are many tricks that can be used including functions and Indexed colorspaces. It will be interesting to hear about your testing. Andrew. |
|
![]() |
|
making
Beginner
Joined: 09 Jan 14 Location: UK Status: Offline Points: 5 |
Post Options
Thanks(0)
Quote Reply
Posted: 14 Jan 14 at 1:26PM |
|
Thanks Andrew and Ingo, After a lot of playing about it looks like the rendering could be the safest approach. There's lot of colourspaces but we also need to take into account the actual colour of any images being rendered. I came up with the following C# which seems to work most of the time (I've got a class derived from the Quick PDF class, hence the base. calls):
public bool IsBiColour(int FileHandle, int PageRef) { double renderScale = base.GetRenderScale(); SetRenderScale(0.1); base.SetGDIPlusOptions(1, 0); // turn text / vector smoothing off so we get a true bicolour image base.SetGDIPlusOptions(3, 0); // turn image smoothing off (off as default anyway) bool biColour = false; using (MemoryStream ms = new MemoryStream(base.DARenderPageToString(FileHandle, PageRef, 0, 300))) { using (Bitmap bitmap = new Bitmap(ms)) { List<int> colours = new List<int>(); for (int y = 0; y < bitmap.Height && colours.Count <= 2; y++) { for (int x = 0; x < bitmap.Width && colours.Count <= 2; x++) { int colour = bitmap.GetPixel(x, y).ToArgb(); if (!colours.Contains(colour)) colours.Add(colour); } } biColour = (colours.Count <= 2); } } SetRenderScale(renderScale); return biColour; } A (very) minor annoyance is there is no GetGDIPlusOptions. I can set the options but I cannot restore them back to their previous values (like I do with renderScale). |
|
![]() |
|
Post Reply
|
|
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store