<?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>Windows CE Programming &#187; code</title>
	<atom:link href="http://www.hjgode.de/wp/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hjgode.de/wp</link>
	<description>Windows Mobile Development and usage</description>
	<lastBuildDate>Fri, 03 Feb 2012 08:53:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<!--CodeProjectFeeder channel--><category>CodeProject</category><generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>iTextSharp running on Compact Framework &#8211; Windows Mobile</title>
		<link>http://www.hjgode.de/wp/2009/10/31/itextsharp-running-on-compact-framework-windows-mobile/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=itextsharp-running-on-compact-framework-windows-mobile</link>
		<comments>http://www.hjgode.de/wp/2009/10/31/itextsharp-running-on-compact-framework-windows-mobile/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 19:24:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Compact Framework]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[hjgode-itextsharp]]></category>
		<category><![CDATA[iTextSharp]]></category>
		<category><![CDATA[iTextSharpCF]]></category>
		<category><![CDATA[itextsharpcf-download]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[source]]></category>
		<category><![CDATA[windows mobile]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=231</guid>
		<description><![CDATA[iTextSharp ported to Compact Framework]]></description>
			<content:encoded><![CDATA[<h3>PDF library iTextSharp working in Compact Framework 2: iTextSharpCF</h3>
<p>Recently I needed a tool to combine several pictures into one file.  First I thought about creating a memory bitmap and then BitBlit the source files into this single bitmap. Then I found an entry about iText and iTextSharp. This is a JAVA and .NET class library to create pdf files. As it seems very easy to use I decided to take a closer look. I found one message, where Marco states he has done a port for .NET compact framework and provided a patch to the sourceforge iTextSharp team. Unfortunately the iTextSharp team seems to ignore this port. So I started with iTextSharp and the patch to get iTextSharp running on Compact Framework.</p>
<p>The patch was done against version 4.0.1 of iTextSharp but there were still some rejects and some additional work to do. The main problem was the use of GetInstance where always the general WebRequest.Create(url); and then GetResponseStream() was used. A first workaround is to load the bitmap first and then provide this to doc.Add:</p>
<p><span id="more-231"></span></p>
<pre lang="CSharp">#if !TEST
 Bitmap myBitmap = new Bitmap(sFilename);
 if (sFilename.ToLower().EndsWith("jpg"))
 img = iTextSharp.text.Image.GetInstance(myBitmap, System.Drawing.Imaging.ImageFormat.Jpeg);
 else if (sFilename.ToLower().EndsWith("gif"))
 img = iTextSharp.text.Image.GetInstance(myBitmap, System.Drawing.Imaging.ImageFormat.Gif);
 else if (sFilename.ToLower().EndsWith("bmp"))
 img = iTextSharp.text.Image.GetInstance(myBitmap, System.Drawing.Imaging.ImageFormat.Bmp);
 else if (sFilename.ToLower().EndsWith("png"))
 img = iTextSharp.text.Image.GetInstance(myBitmap, System.Drawing.Imaging.ImageFormat.Png);
 else
 throw new NotSupportedException("Unsupported image format");
#else
 img = iTextSharp.text.Image.GetInstance(sFilename);
#endif
 doc.Add(img);
</pre>
<p>The GetResponseStream() returns a stream or filestream within full framework. But with Comapct Framework you will always get &#8216;NotSupportedException&#8217; for local files. The CF does not support local files within GetResponseStream. The URI for a local file is &#8216;file://&#8230;&#8217; and an easy replacement for getting a filestream was to use &#8216;new FileStream(url.LocalPath, FileMode.Open);&#8217;. I did insert a #ifdef in all source files with GetResponseStream() as I have no real need to build image instances from network files:</p>
<pre lang="CSharp">//NETCF does not know fileWebRequest (file://...)
#if !NETCF
 WebRequest w = WebRequest.Create(url);
 istr = w.GetResponse().GetResponseStream();
#else
 istr = new FileStream(url.LocalPath, FileMode.Open);
#endif
</pre>
<p>There are also some more #if !NETCF inside the source files for everything that differs between full and compact framework.</p>
<p>The attached zip archive has all files you need to compile and use iTextSharp on your windows mobile. The Visual Studio 2005 solution includes a simple demo application that allows you to add some image files and create a PDF with the filenames and images inside. I inserted a new page for every image. The solution is written against the target &#8220;Windows Mobile 6 Prof&#8221;. So you need Windows Mobile 6 SDK installed.</p>
<p><img class="alignnone size-medium wp-image-232" title="Screen01" src="http://www.hjgode.de/wp/wp-content/uploads/2009/10/Screen01-225x300.jpg" alt="Screen01" width="225" height="300" /> <img class="alignnone size-medium wp-image-233" title="Screen02" src="http://www.hjgode.de/wp/wp-content/uploads/2009/10/Screen02-225x300.jpg" alt="Screen02" width="225" height="300" /></p>
<p>The left screen shows the demo application and the right one the created pdf inside Adobe Reader Mobile.</p>
<p>The <a href="http://sourceforge.net/tracker/index.php?func=detail&amp;aid=1689935&amp;group_id=72954&amp;atid=536238" target="_blank">incomplete patch source</a></p>
<p>A <a href="http://itextsharp.sourceforge.net/tutorial/" target="_blank">tiny tutorial</a> for iTextSharp usage</p>
<p>The new full source: <b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=45" title="Downloaded 680 times">iTextSharpCF-4.0.1_CF</a> - Sample source code using the modified iTextSharp library (also included) (Hits: 680, size: 3.23 MB)</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F10%2F31%2Fitextsharp-running-on-compact-framework-windows-mobile%2F&amp;title=iTextSharp+running+on+Compact+Framework+%26%238211%3B+Windows+Mobile" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F10%2F31%2Fitextsharp-running-on-compact-framework-windows-mobile%2F&amp;title=iTextSharp+running+on+Compact+Framework+%26%238211%3B+Windows+Mobile" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F10%2F31%2Fitextsharp-running-on-compact-framework-windows-mobile%2F&amp;title=iTextSharp+running+on+Compact+Framework+%26%238211%3B+Windows+Mobile" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F10%2F31%2Fitextsharp-running-on-compact-framework-windows-mobile%2F&amp;T=iTextSharp+running+on+Compact+Framework+%26%238211%3B+Windows+Mobile" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F10%2F31%2Fitextsharp-running-on-compact-framework-windows-mobile%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F10%2F31%2Fitextsharp-running-on-compact-framework-windows-mobile%2F&amp;t=iTextSharp+running+on+Compact+Framework+%26%238211%3B+Windows+Mobile" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2009/10/31/itextsharp-running-on-compact-framework-windows-mobile/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

