<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sleepiness in Seattle &#187; thumbnail</title>
	<atom:link href="http://stanblog.jojoyao.com/tag/thumbnail/feed/" rel="self" type="application/rss+xml" />
	<link>http://stanblog.jojoyao.com</link>
	<description>Stanley&#039;s Chat on the Technology and Business</description>
	<lastBuildDate>Tue, 21 Apr 2009 04:29:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Create thumbnails of PowerPoint presentations in C#</title>
		<link>http://stanblog.jojoyao.com/2007/02/create-thumbnails-of-powerpoint-presentations-in-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=create-thumbnails-of-powerpoint-presentations-in-c</link>
		<comments>http://stanblog.jojoyao.com/2007/02/create-thumbnails-of-powerpoint-presentations-in-c/#comments</comments>
		<pubDate>Thu, 08 Feb 2007 04:53:43 +0000</pubDate>
		<dc:creator>Stanley Yao</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[office]]></category>
		<category><![CDATA[PowerPoint]]></category>
		<category><![CDATA[thumbnail]]></category>

		<guid isPermaLink="false">http://stanblog.jojoyao.com/newblog/?p=12</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s sometimes useful to generate JPEG thumbnails of office documents programmatically.&nbsp; With Office object library, it&#8217;s very convenient to do this in C#.NET.&nbsp; If it&#8217;s for a quick and dirty task, an easy way is to convert the office document into a webpage and then use a WebBrowser control to generate the thumbnail.&nbsp; For a more performance oriented task, customized controls subclassed from the Office classes could be written to dump the bitmaps directly into images.&nbsp; The following is a sample implementation of the first approach.&nbsp; Don&#8217;t forget to add the reference to COM object library &quot;Microsoft PointPoint 12.0 Object Library&quot;.</p>
<table width="90%" cellspacing="1" cellpadding="1" border="1" align="center" summary="">
<caption>Creating Thumbnails for PowerPoint Presentations</caption>
<tbody>
<tr>
<td>using PowerPoint = Microsoft.Office.Interop.PowerPoint;</p>
<p>private void pptThumbnail(string sourceFile, string targetFile, int thumbW, int thumbH)<br />
{<br />
&nbsp;&nbsp;&nbsp; // Open the document and convert into HTML pages<br />
&nbsp;&nbsp;&nbsp; PowerPoint.ApplicationClass oApp = new PowerPoint.ApplicationClass();<br />
&nbsp;&nbsp;&nbsp; PowerPoint.Presentation oDoc = oApp.Presentations.Open(<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sourceFile,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft.Office.Core.MsoTriState.msoTrue, // read only<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft.Office.Core.MsoTriState.msoTrue, // untitled<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft.Office.Core.MsoTriState.msoFalse); // with window<br />
&nbsp;&nbsp;&nbsp; string tmpHtmlFile = System.IO.Path.GetTempFileName() + &quot;.html&quot;;<br />
&nbsp;&nbsp;&nbsp; oApp.Presentations[1].SaveCopyAs(<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tmpHtmlFile,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PowerPoint.PpSaveAsFileType.ppSaveAsHTML, // format<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft.Office.Core.MsoTriState.msoTrue); // embed true type font</p>
<p>&nbsp;&nbsp;&nbsp; // Create the thumbnail from the HTML pages<br />
&nbsp;&nbsp;&nbsp; Size browserSize = new Size(800, 800);<br />
&nbsp;&nbsp;&nbsp; WebBrowser browser = new WebBrowser();<br />
&nbsp;&nbsp;&nbsp; browser.Size = browserSize;<br />
&nbsp;&nbsp;&nbsp; browser.Navigate(tmpHtmlFile);<br />
&nbsp;&nbsp;&nbsp; while (WebBrowserReadyState.Complete != browser.ReadyState)<br />
&nbsp;&nbsp;&nbsp; {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Application.DoEvents();<br />
&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; Bitmap bm = new Bitmap(browserSize.Width, browserSize.Height);<br />
&nbsp;&nbsp;&nbsp; browser.DrawToBitmap(bm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new Rectangle(0, 0, browserSize.Width, browserSize.Height));<br />
&nbsp;&nbsp;&nbsp; Bitmap thumbnail = new Bitmap(thumbW, thumbH);<br />
&nbsp;&nbsp;&nbsp; Graphics g = Graphics.FromImage(thumbnail);<br />
&nbsp;&nbsp;&nbsp; g.DrawImage(<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new Rectangle(0, 0, thumbnail.Width, thumbnail.Height),<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new Rectangle(0, 0, browserSize.Width, browserSize.Height),<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GraphicsUnit.Pixel);<br />
&nbsp;&nbsp;&nbsp; thumbnail.Save(targetFile);<br />
}
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://stanblog.jojoyao.com/2007/02/create-thumbnails-of-powerpoint-presentations-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

