<?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>Nefaria.com &#187; I.T.</title>
	<atom:link href="http://nefaria.com/category/information_technology/feed/" rel="self" type="application/rss+xml" />
	<link>http://nefaria.com</link>
	<description>☠ ☠ ☠ ☠ ☠ ☠</description>
	<lastBuildDate>Wed, 31 Aug 2011 16:12:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>new jQuery stuff!</title>
		<link>http://nefaria.com/2011/08/new-jquery-stuff/</link>
		<comments>http://nefaria.com/2011/08/new-jquery-stuff/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 17:08:46 +0000</pubDate>
		<dc:creator>musashi</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[I.T.]]></category>
		<category><![CDATA[Programming / Scripting]]></category>

		<guid isPermaLink="false">http://nefaria.com/?p=1020</guid>
		<description><![CDATA[Check it out: http://nefaria.com/project_index/jqueryfilebrowser/ Enjoy!]]></description>
			<content:encoded><![CDATA[<p>Check it out: <a href="http://nefaria.com/project_index/jqueryfilebrowser/">http://nefaria.com/project_index/jqueryfilebrowser/</a></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://nefaria.com/2011/08/new-jquery-stuff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Opening Terminal Server registry propogation window. (aka: Installing software in windows takes forever)</title>
		<link>http://nefaria.com/2011/02/opening-terminal-server-registry-propogation-window-aka-installing-software-in-windows-takes-forever/</link>
		<comments>http://nefaria.com/2011/02/opening-terminal-server-registry-propogation-window-aka-installing-software-in-windows-takes-forever/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 13:57:22 +0000</pubDate>
		<dc:creator>musashi</dc:creator>
				<category><![CDATA[I.T.]]></category>
		<category><![CDATA[Terminal Services]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://nefaria.com/?p=978</guid>
		<description><![CDATA[That&#8217;s not a typo. For the past few months, I&#8217;ve noticed that installing software or running updates on one particular terminal server that I manage (Windows Server 2003, std.), the updates/installation take hours &#8212; in some cases, days. So I enabled windows installer logging and here&#8217;s what I found: MSI (s) (2C:30) [01:58:16:558]: Opening Terminal [...]]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s not a typo. For the past few months, I&#8217;ve noticed that installing software or running updates on one particular terminal server that I manage (Windows Server 2003, std.), the updates/installation take hours &#8212; in some cases, days. <a href="http://support.microsoft.com/kb/223300">So I enabled windows installer logging</a> and here&#8217;s what I found:</p>
<div class="code_block">
MSI (s) (2C:30) [<strong>01:58:16:558</strong>]: Opening Terminal Server registry propogation window.<br />
MSI (s) (2C:E8) [<strong>02:35:44:188</strong>]: RunEngine wait timed out<br />
Installer is no longer responding.<br />
MSI (s) (2C:E8) [<strong>03:13:14:358</strong>]: RunEngine wait timed out<br />
Installer is no longer responding.<br />
MSI (s) (2C:E8) [<strong>03:50:44:453</strong>]: RunEngine wait timed out<br />
Installer is no longer responding.<br />
MSI (s) (2C:E8) [<strong>04:28:14:529</strong>]: RunEngine wait timed out<br />
Installer is no longer responding.<br />
MSI (s) (2C:E8) [<strong>05:05:44:619</strong>]: RunEngine wait timed out<br />
Installer is no longer responding.<br />
MSI (s) (2C:E8) [<strong>05:43:14:897</strong>]: RunEngine wait timed out<br />
Installer is no longer responding.<br />
Action ended 5:52:07: InstallInitialize. Return value 1.<br />
MSI (s) (2C:30) [<strong>05:52:07:859</strong>]: Doing action: SxsInstallCA<br />
Action start 5:52:07: SxsInstallCA.</div>
<p>So as you can see by the snippet above, this routine installation took an enormous amount of time. This exact scenario played out anytime I tried running updates or installing software. As it turns out, <a href="http://forums11.itrc.hp.com/service/forums/questionanswer.do?admit=109447626+1297688771164+28353475&amp;threadId=1247687">this</a> was the problem. Simply removing the driver and deleting the following registry keys, and then installing the latest version of the driver (&#8230; I was on ~3 something; at the time of this writing, the latest version is 6.1) fixed the problem. Here are the registry keys that should be removed after the driver has been uninstalled (and before the latest version has been installed):</p>
<div class="code_block">HKEY_LOCAL_MACHINE\SOFTWARE\Hewlett-Packard<br />
HKEY_CURRENT_USER\SOFTWARE\Hewlett-Packard<br />
HKEY_USERS\.DEFAULT\Software\Hewlett-Packard</div>
<p>This was an extremely frustrating issue &#8212; other symptoms included server crashes with an error message about the registry being too large; logging in a brand new user for the first time takes ~15 minutes or so, and a whole host of other performance related weirdness. At first I thought that installing UPHClean would help solve this (the symptoms being registry-related and all) but it may have actually made the problem worse. If you scroll all the way down to the bottom of the page of the previous link to HP&#8217;s website, you&#8217;ll see the following post:</p>
<div class="code_block">
JulianBlue  Oct 6, 2010 07:37:53 GMT<br />
It is very likely that HP UPD problem replicating tons of registry keys to global default registry hive (.DEFAULT) being related to Terminal Server on which the Microsoft UPHClean Tool is installed. I would recommend to look at the readme.txt with UPHClean and setup an exclusion for svchost.exe/rpcss.dll.</p>
<p>&#8220;UPHClean assists the operating system to unload user profile hive by remapping the handles to the user profile hive to the default user hive. For example if a process has a handle to HKEY_USERS\S-1-5-21-X-Y-Z\Software\Microsoft after remapping it would have a handle to HKEY_USERS\.DEFAULT\Software\Microsoft.&#8221;
</p></div>
<p>I haven&#8217;t had the chance to test this yet, but it does sound plausible enough. There&#8217;s also some <a href="http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1217189">other posts</a> related to this on HP&#8217;s website that are worth having a look at. Here&#8217;s the <a href="http://download.microsoft.com/download/a/8/7/a87b3d05-cd04-4743-a23b-b16645e075ac/readme.txt">readme.txt that comes with UPHClean</a>. Setting up an exclusion list is fairly straightforward; for convenience, I&#8217;ve pasted the pertinent section of the UPHClean readme here:</p>
<div class="code_block">
PROBLEMS USING UPHCLEAN<br />
=======================</p>
<p>Because UPHClean assists in unloading the users registry<br />
hive some services may behave incorrectly.  Administrators<br />
are encouraged to test and watch for unexpected behavior.<br />
If unwanted behavior is identified contact the developers of<br />
software that UPHClean identified as preventing profile from<br />
unloading.</p>
<p>UPHClean assists the operating system to unload user profile<br />
hive by remapping the handles to the user profile hive to the<br />
default user hive. For example if a process has a handle to<br />
HKEY_USERS\S-1-5-21-X-Y-Z\Software\Microsoft after remapping<br />
it would have a handle to HKEY_USERS\.DEFAULT\Software\Microsoft.<br />
This allows the profile hive to unload.  This may not work if the<br />
application expects data that would only be available under the<br />
specific user profile hive it was accessing since the data will not be copied.</p>
<p>If you find that removing UPHClean stops a particular problem from<br />
occurring then you may be interested in restricting UPHClean from<br />
processing certain handles.  UPHClean ignores handles that are<br />
held opened to profile hives for the users specified on the user<br />
exclusion list or by processes specified on the process exclusion list.<br />
These lists are specified using the following registry values:</p>
<p>HKLM\System\CurrentControlSet\Services\UPHClean\Parameters\PROCESS_EXCLUSION_LIST</p>
<p>HKLM\System\CurrentControlSet\Services\UPHClean\Parameters\USER_EXCLUSION_LIST</p>
<p>Note that since these values are specified as REG_MULTI_SZ strings<br />
you should use regedt32 on Windows NT and Windows 2000 to edit them.</p>
<p>The process exclusion list is a list of process names that UPHClean<br />
should  ignore when determining which handles to user profile hives<br />
to act on.  Each process name is specified on its own line when<br />
input in registry editor.  The process name should be specified the<br />
same way as it shows in Task Manager. Usually this is the file<br />
name of the program (e.g. notepad.exe).</p>
<p>A few process show multiple times in Task Manager.  It is possible to<br />
specify that a certain DLL be loaded in the process to allow a selection<br />
of a specific process.  This is useful with the svchost process to identify<br />
a specific instance.  For example to specify the svchost process that<br />
the Remote Procedure Call (RPC) service is running in on Windows 2000,<br />
Windows XP and Windows Server 2003 you would specify<br />
svchost.exe/rpcss.dll in the process exclusion list</p>
<p>The user exclusion list is a list of user security identifier (SID) or user that<br />
UPHClean should ignore when determining which handle to user profile<br />
hives to act on.  Each user SID or name is specified on its own line when<br />
input in registry editor.  If specifying a user name you must enter the user<br />
domain name followed by a backslash followed by the user name.  For<br />
example RCARONDOM\RCARON to specify the user RCARON from<br />
domain RCARONDOM.  SIDs should be specified in the usual string<br />
format (e.g. S-1-5-21-2127521184-1604012920-1887927527-68486).<br />
This is the same string you see under HKEY_USERS in registry editor.</p>
<p>Note that the user exclusion list always includes the following<br />
SIDs: S-1-5-18, S-1-5-19, S-1-5-20.  Unloading these profiles can cause<br />
problems so UPHClean will not attempt to process handles to these profiles.</p>
<p>Which processes UPHClean performs handle remapping can specified<br />
using the following registry value:</p>
<p>HKLM\System\CurrentControlSet\Services\UPHClean\Parameters\REMAP_HANDLE_PROCESS_LIST</p>
<p>The list by default contains &#8216;*&#8217; which specifies that handle remapping should<br />
be performed for all non-excluded processes.  This list can be changed to<br />
only include specified processes in the same manner as the process<br />
exclusion list. Processes specified on this list can be preceeded by a &#8216;-&#8217;<br />
character to specify that they should be excluded from handle remapping.<br />
Any handle for a process that is not excluded but has handle remapping<br />
turned off will be closed.
</p></div>
<p>I hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://nefaria.com/2011/02/opening-terminal-server-registry-propogation-window-aka-installing-software-in-windows-takes-forever/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Solution for: &#8220;Microsoft office has stopped working&#8221; (applies to Office 2007 &amp; 2010)</title>
		<link>http://nefaria.com/2010/08/solution-for-microsoft-office-has-stopped-working-applies-to-office-2007-2010/</link>
		<comments>http://nefaria.com/2010/08/solution-for-microsoft-office-has-stopped-working-applies-to-office-2007-2010/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 15:44:12 +0000</pubDate>
		<dc:creator>musashi</dc:creator>
				<category><![CDATA[I.T.]]></category>

		<guid isPermaLink="false">http://nefaria.com/?p=944</guid>
		<description><![CDATA[Symptoms: Microsoft word/excel/powerpoint/etc. crash a few seconds after being opened with the error message: &#8220;Microsoft office has stopped working&#8221; As a few clients of mine have upgraded to MS Office 2010, this problem has appeared a few times and it seems damn near impossible to fix&#8230; but there is a fix. You ready? Set your [...]]]></description>
			<content:encoded><![CDATA[<p>Symptoms: Microsoft word/excel/powerpoint/etc. crash a few seconds after being opened with the error message:</p>
<div class="code_block">&#8220;Microsoft office has stopped working&#8221;</div>
<p>As a few clients of mine have upgraded to MS Office 2010, this problem has appeared a few times and it seems damn near impossible to fix&#8230; <em>but there is a fix</em>. You ready?</p>
<p><strong>Set your default printer to the &#8220;Microsoft XPS Document Writer&#8221;.</strong></p>
<p>I don&#8217;t know why this works, but it&#8217;s going to have to do until M$ releases and update/patch/fix/etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://nefaria.com/2010/08/solution-for-microsoft-office-has-stopped-working-applies-to-office-2007-2010/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jqueryFileTree connector script for python cgi</title>
		<link>http://nefaria.com/2010/08/jqueryfiletree-connector-script-for-python-cgi/</link>
		<comments>http://nefaria.com/2010/08/jqueryfiletree-connector-script-for-python-cgi/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 15:49:12 +0000</pubDate>
		<dc:creator>musashi</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[I.T.]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Programming / Scripting]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://nefaria.com/?p=934</guid>
		<description><![CDATA[If you use jquery and haven&#8217;t messed with the jqueryFileTree plugin, I&#8217;d highly recommend you do so. It&#8217;s pretty neat, and there are connector scripts already written in various languages for use with this plugin. However, there wasn&#8217;t one for python cgi (there was one for django however). So, I wrote my own! Try it [...]]]></description>
			<content:encoded><![CDATA[<p>If you use jquery and haven&#8217;t messed with the <a href="http://abeautifulsite.net/blog/2008/03/jquery-file-tree/">jqueryFileTree</a> plugin, I&#8217;d highly recommend you do so. It&#8217;s pretty neat, and there are <a href="http://abeautifulsite.net/blog/2008/03/jquery-file-tree/#connectors">connector scripts</a> already written in various languages for use with this plugin. However, there wasn&#8217;t one for python cgi (there was one for django however). So, I wrote my own! Try it out:</p>
<div class="code_block">
<font color="#8080ff">#!/usr/bin/python</font></p>
<p><font color="#8080ff">#&nbsp;jqueryFileTree connector script for python cgi</font><br />
<font color="#8080ff">#&nbsp;Version: 1.0 / 10 August 2010</font><br />
<font color="#8080ff">#&nbsp;Author: Charles Hamilton / musashi@nefaria.com</font><br />
<font color="#8080ff">#&nbsp;Released under the GNU GPLv3</font><br />
<font color="#8080ff">#&nbsp;Modifications and improvements are welcome</font></p>
<p><font color="#ff40ff">import</font>&nbsp;os, cgi, cgitb, urllib, re<br />
cgitb.enable() <br />
form = cgi.FieldStorage()</p>
<p><font color="#ffff00">print</font>&nbsp;&#8217;<font color="#ff6060">Content-Type: text/html</font><font color="#ff40ff">\n\n</font>&#8216;<br />
<font color="#ffff00">print</font>&nbsp;&#8217;<font color="#ff6060">&lt;ul class=&quot;jqueryFileTree&quot; style=&quot;display: none;&quot;&gt;</font>&#8216;</p>
<p>path = urllib.unquote(form['<font color="#ff6060">dir</font>'].value)</p>
<p>dirs = []<br />
files = []</p>
<p>filelist = sorted(os.listdir(path))</p>
<p><font color="#ffff00">for</font>&nbsp;object <font color="#ffff00">in</font>&nbsp;filelist:<br />
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">if</font>&nbsp;os.path.isfile(path + &#8216;<font color="#ff6060">/</font>&#8216;&nbsp;+ object):<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ext = os.path.splitext(object)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;files.append(&#8216;<font color="#ff6060">&lt;li class=&quot;file ext_</font>&#8216;&nbsp;+ re.sub(&#8216;<font color="#ff6060">\.</font>&#8216;, &#8221;, ext[1]) + &#8216;<font color="#ff6060">&quot;&gt;&lt;a href=&quot;#&quot; rel=&quot;</font>&#8216;+ path + object + &#8216;<font color="#ff6060">&quot;&gt;</font>&#8216;+ object + &#8216;<font color="#ff6060">&lt;/a&gt;&lt;/li&gt;</font>&#8216;)<br />
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">elif</font>&nbsp;os.path.isdir(path + &#8216;<font color="#ff6060">/</font>&#8216;&nbsp;+ object):<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dirs.append(&#8216;<font color="#ff6060">&lt;li class=&quot;directory collapsed&quot;&gt;&lt;a href=&quot;#&quot; rel=&quot;</font>&#8216;+ path + object +&#8217;<font color="#ff6060">/&quot;&gt;</font>&#8216;&nbsp;+ object + &#8216;<font color="#ff6060">&lt;/a&gt;&lt;/li&gt;</font>&#8216;)</p>
<p><font color="#ffff00">for</font>&nbsp;d <font color="#ffff00">in</font>&nbsp;dirs:<br />
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">print</font>&nbsp;d</p>
<p><font color="#ffff00">for</font>&nbsp;f <font color="#ffff00">in</font>&nbsp;files:<br />
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">print</font>&nbsp;f</p>
<p><font color="#ffff00">print</font>&nbsp;&#8217;<font color="#ff6060">&lt;/ul&gt;</font>&#8216;<br />
</font>
</div>
]]></content:encoded>
			<wfw:commentRss>http://nefaria.com/2010/08/jqueryfiletree-connector-script-for-python-cgi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Python + Reportlab: example #1</title>
		<link>http://nefaria.com/2010/08/python-reportlab-example-1/</link>
		<comments>http://nefaria.com/2010/08/python-reportlab-example-1/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 14:57:06 +0000</pubDate>
		<dc:creator>musashi</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[I.T.]]></category>
		<category><![CDATA[Programming / Scripting]]></category>

		<guid isPermaLink="false">http://nefaria.com/?p=922</guid>
		<description><![CDATA[So I&#8217;ve been using reportlab lately and I have to say, it&#8217;s pretty neat. This post will (hopefully) be the first of many to follow. It&#8217;s just a simple example that shows how to take input from a web form and insert it into a PDF. First, the code: &#160;1 #!/usr/bin/python &#160;2 &#160;3 import&#160;cgi, sys [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been using <a href="http://www.reportlab.com/software/opensource/">reportlab</a> lately and I have to say, it&#8217;s pretty neat. This post will (hopefully) be the first of many to follow. It&#8217;s just a simple example that shows how to take input from a web form and insert it into a PDF. First, the code:</p>
<div class="code_block">
<font color="#ffff00">&nbsp;1 </font><font color="#8080ff">#!/usr/bin/python</font><br />
<font color="#ffff00">&nbsp;2 </font><br />
<font color="#ffff00">&nbsp;3 </font><font color="#ff40ff">import</font>&nbsp;cgi, sys<br />
<font color="#ffff00">&nbsp;4 </font><br />
<font color="#ffff00">&nbsp;5 </font>form = cgi.FieldStorage()<br />
<font color="#ffff00">&nbsp;6 </font><br />
<font color="#ffff00">&nbsp;7 </font><font color="#ffff00">if</font>&nbsp;<font color="#ffff00">not</font>&nbsp;&quot;<font color="#ff6060">name</font>&quot;&nbsp;<font color="#ffff00">in</font>&nbsp;form:<br />
<font color="#ffff00">&nbsp;8 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">print</font>&nbsp;&quot;&quot;&quot;<font color="#ff6060">Content-Type: text/html</font><font color="#ff40ff">\n\n</font><br />
<font color="#ffff00">&nbsp;9 </font><font color="#ff6060">&lt;html&gt;</font><br />
<font color="#ffff00">10 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&lt;head&gt;</font><br />
<font color="#ffff00">11 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Reportlab Example&lt;/title&gt;</font><br />
<font color="#ffff00">12 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/head&gt;</font><br />
<font color="#ffff00">13 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&lt;body&gt;</font><br />
<font color="#ffff00">14 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;form action=&quot;index2.cgi&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;</font><br />
<font color="#ffff00">15 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;fieldset&gt;</font><br />
<font color="#ffff00">16 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;legend&gt;Personal Info:&lt;/legend&gt;</font><br />
<font color="#ffff00">17 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name: &lt;input type=&quot;text&quot; name=&quot;name&quot;&gt;&lt;br /&gt;</font><br />
<font color="#ffff00">18 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Photo: &lt;input type=&quot;file&quot; name=&quot;photo&quot;&gt;&lt;br /&gt;</font><br />
<font color="#ffff00">19 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;submit&quot;&gt;</font><br />
<font color="#ffff00">20 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fieldset&gt;</font><br />
<font color="#ffff00">21 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/form&gt;</font><br />
<font color="#ffff00">22 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/body&gt;</font><br />
<font color="#ffff00">23 </font><font color="#ff6060">&lt;/head&gt;</font>&quot;&quot;&quot;<br />
<font color="#ffff00">24 </font><br />
<font color="#ffff00">25 </font><font color="#ffff00">else</font>:<br />
<font color="#ffff00">26 </font><br />
<font color="#ffff00">27 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff40ff">from</font>&nbsp;reportlab.platypus <font color="#ff40ff">import</font>&nbsp;*<br />
<font color="#ffff00">28 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff40ff">from</font>&nbsp;reportlab.lib.styles <font color="#ff40ff">import</font>&nbsp;getSampleStyleSheet<br />
<font color="#ffff00">29 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff40ff">from</font>&nbsp;reportlab.lib.units <font color="#ff40ff">import</font>&nbsp;inch<br />
<font color="#ffff00">30 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff40ff">from</font>&nbsp;reportlab.lib <font color="#ff40ff">import</font>&nbsp;colors<br />
<font color="#ffff00">31 </font>&nbsp;&nbsp;&nbsp;&nbsp;doc = SimpleDocTemplate(sys.stdout)<br />
<font color="#ffff00">32 </font>&nbsp;&nbsp;&nbsp;&nbsp;styles = getSampleStyleSheet()<br />
<font color="#ffff00">33 </font>&nbsp;&nbsp;&nbsp;&nbsp;content = []<br />
<font color="#ffff00">34 </font>&nbsp;&nbsp;&nbsp;&nbsp;<br />
<font color="#ffff00">35 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">if</font>&nbsp;form['<font color="#ff6060">photo</font>'].filename:<br />
<font color="#ffff00">36 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image = Image(form['<font color="#ff6060">photo</font>'].file)<br />
<font color="#ffff00">37 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image.drawHeight = 2*inch*image.drawHeight / image.drawWidth<br />
<font color="#ffff00">38 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image.drawWidth = 2*inch<br />
<font color="#ffff00">39 </font><br />
<font color="#ffff00">40 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">if</font>&nbsp;form['<font color="#ff6060">name</font>'].value:<br />
<font color="#ffff00">41 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text1 = Paragraph(form['<font color="#ff6060">name</font>'].value, styles['<font color="#ff6060">Heading1</font>'])<br />
<font color="#ffff00">42 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text2 = Paragraph(form['<font color="#ff6060">name</font>'].value, styles['<font color="#ff6060">Heading2</font>'])<br />
<font color="#ffff00">43 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text3 = Paragraph(form['<font color="#ff6060">name</font>'].value, styles['<font color="#ff6060">Heading3</font>'])<br />
<font color="#ffff00">44 </font><br />
<font color="#ffff00">45 </font>&nbsp;&nbsp;&nbsp;&nbsp;content.append(text1)<br />
<font color="#ffff00">46 </font>&nbsp;&nbsp;&nbsp;&nbsp;content.append(text2)<br />
<font color="#ffff00">47 </font>&nbsp;&nbsp;&nbsp;&nbsp;content.append(text3)<br />
<font color="#ffff00">48 </font>&nbsp;&nbsp;&nbsp;&nbsp;content.append(image)<br />
<font color="#ffff00">49 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">print</font>&nbsp;&quot;<font color="#ff6060">Content-Type: application/pdf</font>&quot;<br />
<font color="#ffff00">50 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">print</font>&nbsp;&quot;<font color="#ff6060">Content-Disposition: attachment; filename=example.pdf</font><font color="#ff40ff">\n\n</font>&quot;<br />
<font color="#ffff00">51 </font>&nbsp;&nbsp;&nbsp;&nbsp;doc.build(content)<br />
</font>
</div>
<p>Now the explanation:</p>
<p>Lines #1 &#8211; #5 handle specifying the interpreter, importing modules, and initializing the &#8220;FieldStorage&#8221; dictionary (as the variable &#8216;form&#8217;).</p>
<div class="code_block">
<font color="#ffff00">&nbsp;1 </font><font color="#8080ff">#!/usr/bin/python</font><br />
<font color="#ffff00">&nbsp;2 </font><br />
<font color="#ffff00">&nbsp;3 </font><font color="#ff40ff">import</font>&nbsp;cgi, sys<br />
<font color="#ffff00">&nbsp;4 </font><br />
<font color="#ffff00">&nbsp;5 </font>form = cgi.FieldStorage()
</div>
<p>Line #7 tests whether the form has been submitted by checking to see if the &#8216;name&#8217; field has been filled out. There&#8217;s many better ways to test for form submission, but for the purposes of our example, this will work just fine.</p>
<div class="code_block">
<font color="#ffff00">&nbsp;7 </font><font color="#ffff00">if</font>&nbsp;<font color="#ffff00">not</font>&nbsp;&quot;<font color="#ff6060">name</font>&quot;&nbsp;<font color="#ffff00">in</font>&nbsp;form:
</div>
<p>Lines #8 &#8211; #23 print the form</p>
<div class="code_block">
<font color="#ffff00">&nbsp;8 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">print</font>&nbsp;&quot;&quot;&quot;<font color="#ff6060">Content-Type: text/html</font><font color="#ff40ff">\n\n</font><br />
<font color="#ffff00">&nbsp;9 </font><font color="#ff6060">&lt;html&gt;</font><br />
<font color="#ffff00">10 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&lt;head&gt;</font><br />
<font color="#ffff00">11 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Reportlab Example&lt;/title&gt;</font><br />
<font color="#ffff00">12 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/head&gt;</font><br />
<font color="#ffff00">13 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&lt;body&gt;</font><br />
<font color="#ffff00">14 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;form action=&quot;index2.cgi&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;</font><br />
<font color="#ffff00">15 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;fieldset&gt;</font><br />
<font color="#ffff00">16 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;legend&gt;Personal Info:&lt;/legend&gt;</font><br />
<font color="#ffff00">17 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name: &lt;input type=&quot;text&quot; name=&quot;name&quot;&gt;&lt;br /&gt;</font><br />
<font color="#ffff00">18 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Photo: &lt;input type=&quot;file&quot; name=&quot;photo&quot;&gt;&lt;br /&gt;</font><br />
<font color="#ffff00">19 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;submit&quot;&gt;</font><br />
<font color="#ffff00">20 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fieldset&gt;</font><br />
<font color="#ffff00">21 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/form&gt;</font><br />
<font color="#ffff00">22 </font><font color="#ff6060">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/body&gt;</font><br />
<font color="#ffff00">23 </font><font color="#ff6060">&lt;/head&gt;</font>&quot;&quot;&quot;
</div>
<p>Lines #26 &#8211; #29 import some more modules (i.e., reportlab related stuff).</p>
<div class="code_block">
<font color="#ffff00">26 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff40ff">from</font>&nbsp;reportlab.platypus <font color="#ff40ff">import</font>&nbsp;*<br />
<font color="#ffff00">27 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff40ff">from</font>&nbsp;reportlab.lib.styles <font color="#ff40ff">import</font>&nbsp;getSampleStyleSheet<br />
<font color="#ffff00">28 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff40ff">from</font>&nbsp;reportlab.lib.units <font color="#ff40ff">import</font>&nbsp;inch<br />
<font color="#ffff00">29 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff40ff">from</font>&nbsp;reportlab.lib <font color="#ff40ff">import</font>&nbsp;colors
</div>
<p>Now line #30 is important, this is where we decide where we want to write the output. We can either save the output to a file, or we can dump it to stdout (i.e., back to the web browser). In this example, we&#8217;re going to send the output back to the web browser.</p>
<div class="code_block">
<font color="#ffff00">30 </font>&nbsp;&nbsp;&nbsp;&nbsp;doc = SimpleDocTemplate(sys.stdout)
</div>
<p>Line #31 handles getting the style sheet that we&#8217;re going to use to format our text.</p>
<div class="code_block">
<font color="#ffff00">31 </font>&nbsp;&nbsp;&nbsp;&nbsp;styles = getSampleStyleSheet()
</div>
<p>In line #32, we initialize the &#8216;content&#8217; dictionary &#8212; this is where we&#8217;re going to keep the elements of our PDF until we&#8217;re ready to write it to stdout.</p>
<div class="code_block">
<font color="#ffff00">32 </font>&nbsp;&nbsp;&nbsp;&nbsp;content = []
</div>
<p>In lines #34 &#8211; #37, we test for the &#8216;photo&#8217; field &#8212; if it has been submitted, we create an Image object out of it. We&#8217;re assuming that the user is going to submit a photo, but in reality, the user could submit anything so some further &#8220;hardening&#8221; of this form would be required in order to ensure that the only things that actually get submitted are image files.</p>
<div class="code_block">
<p><font color="#ffff00">34 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">if</font>&nbsp;form['<font color="#ff6060">photo</font>'].filename:<br />
<font color="#ffff00">35 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image = Image(form['<font color="#ff6060">photo</font>'].file)<br />
<font color="#ffff00">36 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image.drawHeight = 2*inch*image.drawHeight / image.drawWidth<br />
<font color="#ffff00">37 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image.drawWidth = 2*inch
</div>
<p>Lines #39 &#8211; #42 test to see if the &#8216;name&#8217; field has been submitted; if it has, it creates some text objects to insert into our PDF.</p>
<div class="code_block">
<font color="#ffff00">39 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">if</font>&nbsp;form['<font color="#ff6060">name</font>'].value:<br />
<font color="#ffff00">40 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text1 = Paragraph(form['<font color="#ff6060">name</font>'].value, styles['<font color="#ff6060">Heading1</font>'])<br />
<font color="#ffff00">41 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text2 = Paragraph(form['<font color="#ff6060">name</font>'].value, styles['<font color="#ff6060">Heading2</font>'])<br />
<font color="#ffff00">42 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text3 = Paragraph(form['<font color="#ff6060">name</font>'].value, styles['<font color="#ff6060">Heading3</font>'])
</div>
<p>Lines #44 &#8211; #47 append all the objects that we want to appear in our PDF, to the &#8216;content&#8217; dictionary we created earlier.</p>
<div class="code_block">
<font color="#ffff00">44 </font>&nbsp;&nbsp;&nbsp;&nbsp;content.append(text1)<br />
<font color="#ffff00">45 </font>&nbsp;&nbsp;&nbsp;&nbsp;content.append(text2)<br />
<font color="#ffff00">46 </font>&nbsp;&nbsp;&nbsp;&nbsp;content.append(text3)<br />
<font color="#ffff00">47 </font>&nbsp;&nbsp;&nbsp;&nbsp;content.append(image)
</div>
<p>Lines #48 &#8211; #49 send the appropriate headers to the web browser, before we send our completed PDF file.</p>
<div class="code_block">
<font color="#ffff00">48 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">print</font>&nbsp;&quot;<font color="#ff6060">Content-Type: application/pdf</font>&quot;<br />
<font color="#ffff00">49 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">print</font>&nbsp;&quot;<font color="#ff6060">Content-Disposition: attachment; filename=example.pdf</font><font color="#ff40ff">\n\n</font>&quot;
</div>
<p>And finally, line #50 builds our PDF and sends the output to stdout.</p>
<div class="code_block">
<font color="#ffff00">50 </font>&nbsp;&nbsp;&nbsp;&nbsp;doc.build(content)
</div>
<p>Test it out; you should end up with a PDF that looks something like this:</p>
<p><a class="shutterset_" href='http://nefaria.com/wp-content/gallery/miscellaneous-media/reportlab_example1_img1.png' title=''><img src='http://nefaria.com/wp-content/gallery/miscellaneous-media/thumbs/thumbs_reportlab_example1_img1.png' alt='reportlab_example1_img1' class='ngg-singlepic ngg-center' /></a></p>
<p>Of course, this example doesn&#8217;t even scratch the surface of what you can do with reportlab. Hopefully I&#8217;ll post some more examples later on <img src='http://nefaria.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://nefaria.com/2010/08/python-reportlab-example-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

