ALINK="#FF0000">

LINUX GAZETTE

[ Prev ][ Table of Contents ][ Front Page ][ Talkback ][ FAQ ][ Next ]

"Linux Gazette...making Linux just a little more fun!"


Converting Linux HOWTOs into Book Format

By Mark Nielsen


  1. Introduction
  2. Perl script to convert the Postscript files
  3. Conclusion
  4. References

Introduction

I wanted to print out Linux HOWTOs into book format. However, I am not fond of manually converting the HOWTOs. Instead, since all the HOWTOs are available in Postscript format, I figured out that I could download the Postscript files on a regular basis and use various tools to convert the Postscript files into book formatted Postscript and PDF files. I accomplished this with a relatively small Perl script using a variety of Unix tools. I plan on have a cron job run at least once a week to update the books.

Perl script to convert the Postscript files

The Perl script is in this section, and you can also get the Perl script here.

#!/usr/bin/perl

# ftp://ftp.tardis.ed.ac.uk/users/ajcd/psutils.tar.gz
# http://www.dcs.ed.ac.uk/home/ajcd/psutils/ 
# cp Makefile.unix Makefile
# ln -s /usr/bin/perl /usr/local/bin/perl
# mkdir -p /usr/local/share/man/man1
# /usr/local/bin/psbook

#system ("lynx --source ftp://ftp.tardis.ed.ac.uk/users/ajcd/psutils.tar.gz > /tmp/psutils.tar.gz)";
# system ("cd /tmp; tar -zxvf psutils.tar.gz; cd psutils; cp Makefile.unix Makefile");
# system ("ln -s /usr/bin/perl /usr/local/bin/perl; mkdir -p /usr/local/share/man/man1");
# system ("cd /tmp/psutils; make; make install; ln -s /usr/local/bin/psutils /usr/bin/psutils");

# Ignore the lines above, unless you don't have psutils. 
# I keep the lines above just so I remember how I installed psutils.

my $TempFile1 = "/tmp/HOWTO_Convert_1.ps";
my $TempFile2 = "/tmp/HOWTO_Convert_1.pdf";
my $SourceDir = "/root/HOWTO";
my $Destination = "/root/HOWTO_Books";
my $ZippedPDF = "/root/HOWTO_books_pdf.tgz";
my $ZippedPS = "/root/HOWTO_books_ps.tgz";

if (!(-d $Destination)) {system "mkdir $Destination";}

print "Downloading HOWTOs from http://www.ibiblio.org/pub/Linux/docs/HOWTO/other-formats/ps/Linux-ps-HOWTOs.tar.gz\n";
system ("lynx --source http://www.ibiblio.org/pub/Linux/docs/HOWTO/other-formats/ps/Linux-ps-HOWTOs.tar.gz > $SourceDir/Linux-ps-HOWTOs.tar.gz");
system ("cd $SourceDir; tar -zxvf Linux-ps-HOWTOs.tar.gz"); 

my @Files = <$SourceDir/*.ps.gz>;

foreach my $File (@Files)
  {
  my $command="gunzip -c $File | /usr/bin/psbook -s4 | mpage -2 > $TempFile1";
  print "Executing psbook and mpage on $File\n$command\n";
  system ($command);
  $command = "ps2pdf $TempFile1 $TempFile2";
  print "Executing ps2pdf\n$command\n";
  system ($command);

  my (@Temp) = split(/\//,$File);
  my $NamePDF = pop @Temp;
  my $NamePS = $NamePDF;
  $NamePDF =~ s/\.ps\.gz$/\.pdf/;
  $NamePS =~ s/\.ps\.gz$/\.ps/;
  my $NewPS = "$Destination/$NamePS";
  my $NewPDF = "$Destination/$NamePDF";

  system ("mv $TempFile2 $NewPDF"); 
  print "Created the book-formatted HOWTO, $NewPDF\n";
  system ("mv $TempFile1 $NewPS");
  print "Created the book-formatted HOWTO, $NewPS\n";
  }

print "Creating zip files $ZippedPDF and $ZippedPS\n";
system ("tar -zcvf $ZippedPDF $Destination/*.pdf");
system ("tar -zcvf $ZippedPS $Destination/*.ps");

Conclusion

This is just a simple Perl script I use to download and convert the Postscript HOWTOs. My future goals involve:
  1. using LWP in Perl instead of Lynx. Simple enough.
  2. converting the entire Perl script into Python.
  3. better error checking if the files don't get downloaded or if the conversion doesn't work.
  4. creating objects accepting text, TeX, Postscript, PDF, or other formats that can be converted into Postscript fairly easily and then into book format.
For now, my simple Perl script works out just fine. I am interested in converting other documents for people provided that the documentation falls under some form of free documentation, like Licenses For Documentation located at www.gnu.org.

References

  1. 10/2000 Micro Publishing: Part 3 , by Mark Nielsen .
  2. 7-1-2000 Micro Publishing, part II (Mark's Update)
  3. 12-1999 -- Micro Publishing.
  4. If this article changes, it will be available here http://www.gnujobs.com/Articles/18/HOWTO_Books.html

Mark works as an independent consultant donating time to causes like GNUJobs.com, writing articles, writing free software, and working as a volunteer at eastmont.net.

Mark Nielsen

Mark works at ZING (www.genericbooks.com) and GNUJobs.com. Previously, Mark founded The Computer Underground. Mark works on non-profit and volunteer projects which promote free literature and software. To make a living, he recruits people for GNU related jobs and also provides solutions for web/database problems using Linux, FreeBSD, Apache, Zope, Perl, Python, and PostgreSQL.


Copyright © 2001, Mark Nielsen.
Copying license http://www.linuxgazette.net/copying.html
Published in Issue 66 of Linux Gazette, May 2001

[ Prev ][ Table of Contents ][ Front Page ][ Talkback ][ FAQ ][ Next ]