<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>Debenu Quick PDF Library - PDF SDK Community Forum : Colour Detection on Page</title>
  <link>http://www.quickpdf.org/forum/</link>
  <description><![CDATA[This is an XML content feed of; Debenu Quick PDF Library - PDF SDK Community Forum : I need help - I can help : Colour Detection on Page]]></description>
  <copyright>Copyright (c) 2006-2013 Web Wiz Forums - All Rights Reserved.</copyright>
  <pubDate>Sun, 05 Apr 2026 17:32:51 +0000</pubDate>
  <lastBuildDate>Tue, 14 Jan 2014 13:26:39 +0000</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 11.01</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.quickpdf.org/forum/RSS_post_feed.asp?TID=2809</WebWizForums:feedURL>
  <image>
   <title><![CDATA[Debenu Quick PDF Library - PDF SDK Community Forum]]></title>
   <url>http://www.quickpdf.org/forum/forum_images/QPDF_Forum_Title.png</url>
   <link>http://www.quickpdf.org/forum/</link>
  </image>
  <item>
   <title><![CDATA[Colour Detection on Page :  Thanks Andrew and Ingo, After...]]></title>
   <link>http://www.quickpdf.org/forum/colour-detection-on-page_topic2809_post11437.html#11437</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.quickpdf.org/forum/member_profile.asp?PF=2513">making</a><br /><strong>Subject:</strong> 2809<br /><strong>Posted:</strong> 14 Jan 14 at 1:26PM<br /><br />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):<div></div><div>public bool IsBiColour(int FileHandle, int PageRef)<br>{<br>&nbsp;&nbsp;&nbsp; double renderScale = base.GetRenderScale();<br>&nbsp;&nbsp;&nbsp; SetRenderScale(0.1);</div><div>&nbsp;&nbsp;&nbsp; base.SetGDIPlusOptions(1, 0);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // turn text / vector smoothing off so we get a true bicolour image<br>&nbsp;&nbsp;&nbsp; base.SetGDIPlusOptions(3, 0);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // turn image smoothing off (off as default anyway)</div><div>&nbsp;&nbsp;&nbsp; bool biColour = false;</div><div>&nbsp;&nbsp;&nbsp; using (MemoryStream ms = new MemoryStream(base.DARenderPageToString(FileHandle, PageRef, 0, 300)))<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (Bitmap bitmap = new Bitmap(ms))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;int&gt; colours = new List&lt;int&gt;();</div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int y = 0; y &lt; bitmap.Height &amp;&amp; colours.Count &lt;= 2; y++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int x = 0; x &lt; bitmap.Width &amp;&amp; colours.Count &lt;= 2; x++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int colour = bitmap.GetPixel(x, y).ToArgb();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!colours.Contains(colour)) colours.Add(colour);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; biColour = (colours.Count &lt;= 2);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }</div><div>&nbsp;&nbsp;&nbsp; SetRenderScale(renderScale);<br>&nbsp;&nbsp;&nbsp; return biColour;<br>}<br></div><div>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).</div><div>&nbsp;</div>]]>
   </description>
   <pubDate>Tue, 14 Jan 2014 13:26:39 +0000</pubDate>
   <guid isPermaLink="true">http://www.quickpdf.org/forum/colour-detection-on-page_topic2809_post11437.html#11437</guid>
  </item> 
  <item>
   <title><![CDATA[Colour Detection on Page : A complex question.Ingo&amp;#039;s...]]></title>
   <link>http://www.quickpdf.org/forum/colour-detection-on-page_topic2809_post11436.html#11436</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.quickpdf.org/forum/member_profile.asp?PF=1483">AndrewC</a><br /><strong>Subject:</strong> 2809<br /><strong>Posted:</strong> 14 Jan 14 at 11:13AM<br /><br />A complex question.<div><br></div><div>Ingo's answer is a good solution.</div><div><br></div><div>Another idea is to render the PDF to a low DPI BMP file and then manually counting the colours.</div><div><br></div><div>There is no easy solution to this.</div><div><br></div><div>Another option is to call QP.GetPageColorSpaces functions to see which colorspaces are directly referenced. &nbsp;</div><div><br></div><div>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.</div><div><br></div><div>It will be interesting to hear about your testing.</div><div><br></div><div>Andrew.</div><div><br></div><div><br></div>]]>
   </description>
   <pubDate>Tue, 14 Jan 2014 11:13:35 +0000</pubDate>
   <guid isPermaLink="true">http://www.quickpdf.org/forum/colour-detection-on-page_topic2809_post11436.html#11436</guid>
  </item> 
  <item>
   <title><![CDATA[Colour Detection on Page : Hi Making,there&amp;#039;s a lot you...]]></title>
   <link>http://www.quickpdf.org/forum/colour-detection-on-page_topic2809_post11428.html#11428</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.quickpdf.org/forum/member_profile.asp?PF=111">Ingo</a><br /><strong>Subject:</strong> 2809<br /><strong>Posted:</strong> 12 Jan 14 at 1:41PM<br /><br />Hi Making,<div><br></div><div>there's a lot you can "see" without a pdf-library.</div><div>Please read my blog here:</div><div>http://pdfcomments.blogspot.de/2009/09/under-surface.html</div><div>What you're looking for is code like the following:</div><div>// ...</div><div>// textcomplete contains the filecontent ...</div><div>devrgb &nbsp;:= CountSubStr('/DEVICERGB', UpperCase(textcomplete));</div><div>devcmyk := CountSubStr('/DEVICECMYK', UpperCase(textcomplete));</div><div>devgray := CountSubStr('/DEVICEGRAY', UpperCase(textcomplete));</div><div>// ...</div><div><br></div><div>Cheers and welcome here,</div><div>Ingo</div><div><br></div>]]>
   </description>
   <pubDate>Sun, 12 Jan 2014 13:41:04 +0000</pubDate>
   <guid isPermaLink="true">http://www.quickpdf.org/forum/colour-detection-on-page_topic2809_post11428.html#11428</guid>
  </item> 
  <item>
   <title><![CDATA[Colour Detection on Page :  Hi All,This is my first post...]]></title>
   <link>http://www.quickpdf.org/forum/colour-detection-on-page_topic2809_post11427.html#11427</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.quickpdf.org/forum/member_profile.asp?PF=2513">making</a><br /><strong>Subject:</strong> 2809<br /><strong>Posted:</strong> 09 Jan 14 at 11:20PM<br /><br />Hi All,<div>&nbsp;</div><div>This is my first post so please be gentle <img src="http://www.quickpdf.org/forum/smileys/smiley9.gif" height="17" width="17" border="0" alt="Embarrassed" title="Embarrassed" />. Is there any way to tell if a PDF page is black and white or colour (e.g. 256 colour, 65536 colour, 24bit etc). Reason why I'm asking is I want to decide which format to save an image in before I render it&nbsp;(Black and White G4 TIFF, everything else JPG etc.)</div><div>&nbsp;</div>]]>
   </description>
   <pubDate>Thu, 09 Jan 2014 23:20:29 +0000</pubDate>
   <guid isPermaLink="true">http://www.quickpdf.org/forum/colour-detection-on-page_topic2809_post11427.html#11427</guid>
  </item> 
 </channel>
</rss>