<?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>Guy Rutenberg &#187; DjVu</title>
	<atom:link href="http://www.guyrutenberg.com/tag/djvu/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guyrutenberg.com</link>
	<description>Keeping track of what I do</description>
	<lastBuildDate>Sat, 14 Jan 2012 11:30:25 +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>Convert PNMs to DjVu</title>
		<link>http://www.guyrutenberg.com/2008/03/11/convert-pnms-to-djvu/</link>
		<comments>http://www.guyrutenberg.com/2008/03/11/convert-pnms-to-djvu/#comments</comments>
		<pubDate>Tue, 11 Mar 2008 20:47:38 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[DjVu]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/2008/03/11/convert-pnms-to-djvu/</guid>
		<description><![CDATA[I&#8217;ve decided to scan some notebooks. After researching a bit, I&#8217;ve decided to use DjVu (instead of PDF which I normally use). I&#8217;ve chose to use DjVu because it offered great quality with very good compression rate (~26KB per page) in lineart (black and white). While XSane can natively save a multipage project into PDF [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve decided to scan some notebooks. After researching a bit, I&#8217;ve decided to use <a href="http://www.djvu.org">DjVu</a> (instead of PDF which I normally use). I&#8217;ve chose to use DjVu because it offered great quality with very good compression rate (~26KB per page) in lineart (black and white). </p>
<p>While XSane can natively save a multipage project into PDF it can&#8217;t do so for DjVu. So, the solution is to use the PNMs generated by XSane and convert them using the command line tools offered by <a href="http://djvu.sourceforge.net/">DjVuLibre</a> to bundle them together to a DjVu file. As you can guess doing this manually is pretty hard work. To make this task easier I&#8217;ve written a small bash script to automate the process.<br />
<span id="more-45"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># pnm2djvu </span>
<span style="color: #666666; font-style: italic;">#(C) 2008 Guy Rutenberg</span>
<span style="color: #666666; font-style: italic;">#pnm2djvu - A small script that takes a directory with PNMs and converts them to </span>
<span style="color: #666666; font-style: italic;">#monochrome (bitonal) djvu file with the PNMs ordered alphabetically.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Directory of PNMs reguired&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$2&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;filename for output required&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">pnms</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #ff0000;">&quot;$1/&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;.pnm$&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">pagenum</span>=<span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${pnms}</span>; <span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Processing page number <span style="color: #007800;">${pagenum}</span>&quot;</span>
	cjb2 <span style="color: #ff0000;">&quot;$1/<span style="color: #007800;">$i</span>&quot;</span>  <span style="color: #ff0000;">&quot;page<span style="color: #007800;">$i</span>.djvu&quot;</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;$2&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		djvm <span style="color: #660033;">-i</span> <span style="color: #ff0000;">&quot;$2&quot;</span> <span style="color: #ff0000;">&quot;page<span style="color: #007800;">$i</span>.djvu&quot;</span>
	<span style="color: #000000; font-weight: bold;">else</span>
		djvm <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;$2&quot;</span> <span style="color: #ff0000;">&quot;page<span style="color: #007800;">$i</span>.djvu&quot;</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #ff0000;">&quot;page<span style="color: #007800;">$i</span>.djvu&quot;</span>
	<span style="color: #007800;">pagenum</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$pagenum</span> + <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">done</span>;</pre></div></div>

<p>Using the script is pretty simple. Pass as the first argument a path to a directory holding the PNMs (it can also be &#8220;.&#8221;), and the name of the output DjVu file. If the file already exist the script will append all the PNMs to it, otherwise it will just create a new one.</p>
<p>I&#8217;ve released this script following the &#8220;release early&#8221; practice in the open-source community. This script is far from perfect and I plan t improve when I&#8217;ve some more time. Currently this script has some major drawbacks such as fixed DPI (300) and it only support bitonal (black and white) compression. As I wrote above, I plan to address this issues and make the script more flexible in the future.</p>
<p>Despite its drawbacks I hope you will still find this script useful. If you have any questions or suggestions please comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2008/03/11/convert-pnms-to-djvu/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.294 seconds -->

