Linux.com

Feature

Turn your Linux box into a PDF-making machine

By Joe 'Zonker' Brockmeier on May 08, 2007 (8:00:00 AM)

Share    Print    Comments   

Remember the paperless office? By now we were supposed to be handling all of our documents digitally, and saving trees by using computers to handle everything electronically. If you'd like to make backup copies of ephemeral content without printing it out, turn your Linux box into a PDF generation device for your entire network.

What sort of things might you want to save as PDFs? When you buy stuff online, virtually every site provides a receipt, which you may want later if the order email is lost or if you need to send in a receipt for expense reports. However, you may not want to print all of them out just to keep them around, and Firefox only supports writing to PostScript, rather than PDF.

What you'll need is a Linux box with the Common UNIX Printing System (CUPS) and the CUPS-PDF driver. I set this up on Ubuntu Feisty, but it should work on any Linux distro with CUPS and the CUPS-PDF driver.

By default, CUPS-PDF is not installed, so grab it by using sudo apt-get install cups-pdf. You should then be able to add a fake printer that will convert print jobs to PDF files. Go to System -> Administration -> Printing to bring up the Printer configuration dialog. Select New Printer from the toolbar, and walk through the New Printer Wizard. You can give the printer pretty much any name you want. PDF seems like a logical choice. The Description and Location fields are optional.

On the next screen, when asked to select a connection, choose Virtual Printer, and leave the device URI as it is: cups-pdf:/. Next, on the screen where you can select a Printer from the database, choose Generic. On the next screen, choose PostScript as the Model and as the driver for the printer. Then you'll see a screen that says "Going to create a new printer PDF at cups-pdf:/." Click Apply and you should have a virtual PDF printer.

Now you should be able to create PDF files from most Linux apps by sending your print jobs to the PDF printer. When you send jobs to the printer, they'll be saved to a directory under your home directory that's named after the virtual printer -- so if you choose PDF as the name of your virtual printer, then the jobs will be sent to /home/yourusername/PDF.

Most Linux apps are fairly well-behaved, but I've noticed that some jobs come through as zero-length files even though the applications don't indicate any problems when printing. For example, Opera happily prints to the virtual printer, but the resulting jobs are empty files. Firefox and Thunderbird print to the virtual printer just fine.

Many GNOME and KDE apps now have the ability to print directly to PDF or export a file to PDF, so it's not necessary to utilize the virtual printer. However, where the PDF printer comes in really handy is if you have one or more Windows machines on your network and you'd like to generate PDFs from Windows apps without spending the money on Adobe's tools.

Sharing with Windows

It's fairly straightforward to set up sharing with Windows. You'll need to make some simple edits to the CUPS configuration file. On Ubuntu, use sudo vi /etc/cups/cupsd.conf.

First, make sure that you have the port set correctly:

# Allow remote access
Port 631
Listen /var/run/cups/cups.sock
Browsing On
BrowseOrder allow,deny
BrowseAllow @LOCAL
BrowseAddress @LOCAL
DefaultAuthType Basic

Then, under the first Location directive, you'll want to have something like this:

<Location />
  # Allow remote administration...
  Order allow,deny
  Allow From 127.0.0.1
  Allow From 10.0.0.*
</Location>

The line you want to change is Allow From 10.0.0.* . You'll want to make sure that the IP address reflects your network.

Next, restart CUPS:

sudo /etc/init.d/cupsys restart

Now you can set up the new printer on Windows. In the Add Printer Wizard in Windows, you'll select "Connect to a printer on the Internet or on a home office network:" and set the URL as http://ipaddress/printers/PDF. Windows should see the printer. Now it's time to choose the printer driver. I Googled a bit and found that the consensus seems to be that if you want color PDFs, the HP 1200C/PS driver is the way to go.

Finish walking through the wizard and try to print. If you succeed you will find a PDF waiting for you on your Ubuntu system. By default, if you print to the Linux machine, the PDF files will be saved to /var/spool/cups-pdf/ANONYMOUS. This is in contrast to printing locally, which saves as /home/yourusername/PDF. To change the directory, uncomment this line:

#AnonDirName /var/spool/cups-pdf/ANONYMOUS

and modify it. For example, if you want to print to your home directory under a directory called shared, you could use:

AnonDirName /home/shared

Restart CUPS again and you should be golden.

With any luck, armed with a new PDF "printing" machine, you can make copies of documents you want to save without having to kill a tree in the process.

Share    Print    Comments   

Comments

on Turn your Linux box into a PDF-making machine

Note: Comments are owned by the poster. We are not responsible for their content.

making pdf files

Posted by: Anonymous Coward on May 10, 2007 11:50 AM
If you don't have cups-pdf, simply choose any printer on your list, and select the "print to file" option. Give the file a<nobr> <wbr></nobr>.ps extension. This produces a postscript file. Then convert it to a pdf file with the little command-line utility program ps2pdf (virtually all distros have ps2pdf).

#

Sharing it with Windows: why not Samba?

Posted by: Anonymous Coward on May 08, 2007 06:02 PM

CUPS plays well with Samba. Why not use Samba when you want to share the printer? (or pdf generator).

#

Re:Sharing it with Windows: why not Samba?

Posted by: Anonymous Coward on May 08, 2007 08:02 PM
Perhaps 'cuz Samba can be a real pain to install and configure? This looks a lot easier.

But you're missing the point: this is one solution; Samba is another. That's the great thing about Linux: there are a lot of great ways to carry out tasks, regardless of your technical skills.

#

Re:Sharing it with Windows: why not Samba?

Posted by: Anonymous Coward on May 08, 2007 08:45 PM
Samba can be extremely easy to setup. If you don't know how to do it by editing the configuration files, you can always use GSambad, which just happens to be in the Ubuntu repositories.

#

Re:Sharing it with Windows: why not Samba?

Posted by: Anonymous Coward on May 09, 2007 01:49 AM
<tt>My way might be a little more complicated but the file is put in the users directory with the date and time the pdf was created. It is done with samba and is for windows shares. I use the same hp printer driver that was in the article for color pdf's. I also have samba setup to load the windows driver to the windows computer for me. Good directions on how to do that are found at samba.org.

The Samba entry:
[pdfprinter]
        path =<nobr> <wbr></nobr>/tmp
        printer admin = @ntadmin, @administrators
        create mask = 0700
        guest ok = Yes
        printable = Yes
        printer name = PDFPrinter
        printing = lprng
        cups options =
        print command =<nobr> <wbr></nobr>/home/pdfprinter/pdfconvert %s %U
        lpq command = lpq -P'%p'
        lprm command = lprm -P'%p' %j
        lppause command = lpc hold '%p' %j
        lpresume command = lpc release '%p' %j
        queuepause command = lpc stop '%p'
        queueresume command = lpc start '%p'

The script to do the work:
#!/bin/sh

# pdfconvertemail
# Date Modified: 12/06/2005

#
# Converts text input from a Samba print Spool into a PDF
#  then saves that pdf into the users home directory.
#
# Input: Arg 1 = Spool File Name (Provided by sabma)
#        Arg 2 = Username of person printing (Provided by sabma)
#
# Output: Produces a Pdf version of the text input
#          named for the user, and the date/time
#          the job was printed.  Thne places that
#          file in the users home directory in
#          a subdirectory called pdf.  If that
#          directory is not there it is created.
#
# Requires: date, enscript, ps2pdf, mv, rm, cat, mutt
#

# Retrieve the name of the spool file provided by samba
SPOOLFILE=`echo $1`

# Get the date and time of execution
#  Month Abbr Number of Day, Hours Minutes Seconds
DATE=`date +%b%d-%H%M%S`

# Retrieve the Username of the person who printed the job
UN=`echo $2`

# File name to be used
FILENAME=${UN}-${DATE}

# Set the paths needed for execution
OUTDIR=/home
TEMPDIR=/tmp
#          the job was printed.  Then places that
#          file in the users home directory in
#          a subdirectory called pdf.  If that
#          directory is not there it is created.
#
# Requires: date, enscript, ps2pdf, mv, rm, cat, mutt
#

# Retrieve the name of the spool file provided by samba
SPOOLFILE=`echo $1`

# Get the date and time of execution
#  Month Abbr Number of Day, Hours Minutes Seconds
DATE=`date +%b%d-%H%M%S`

# Retrieve the Username of the person who printed the job
UN=`echo $2`

# File name to be used
FILENAME=${UN}-${DATE}

# Set the paths needed for execution
OUTDIR=/home
TEMPDIR=/tmp

# Save the full paths to the needed programs
PCL6=`which pcl6`

# Save the spool file into a text file
cat $TEMPDIR/$SPOOLFILE > $TEMPDIR/$FILENAME.pcl

$PCL6 -sDEVICE=pdfwrite -sOutputFile=$TEMPDIR/$FILENAME.pdf $TEMPDIR/$FILENAME.pcl

# Move the pdf file to the users home directory
#  if the pdf directory exists.
if [ ! -d $OUTDIR/$UN/pdf ]
then
        mkdir $OUTDIR/$UN/pdf
fi

mv $TEMPDIR/$FILENAME.pdf $OUTDIR/$UN/pdf/$FILENAME.pdf

# Remove all temp files and the spool file
rm $TEMPDIR/$FILENAME.pcl
rm $TEMPDIR/$SPOOLFILE
rm $TEMPDIR/$FILENAME.pdf

</tt>

#

Re: Sharing it with Windows: why not Samba?

Posted by: Anonymous [ip: 192.168.1.1] on August 16, 2007 09:15 PM
Current CUPS distribution ( eg. supplied with FC6 or CentOS5) allows seamless integration of Cups-PDF printer and Samba.
Just install cups-pdf rpm ( the source rpm for FC6 compiles OK on CentOS5) and restart CUPS. The new printer Cups-PDF is added to the list.
Go to administrator interface and use "Export Printers to Samba" option to prepare this printer for 'Point'n'Print' installation on Windows clients.

#

PDFCreator

Posted by: Anonymous Coward on May 08, 2007 08:43 PM
This allows a Windows box to print to PDF without Adobe's tools as well, and its free and Free under the GPL:

<a href="http://sourceforge.net/projects/pdfcreator/" title="sourceforge.net">http://sourceforge.net/projects/pdfcreator/</a sourceforge.net>

It has been very handy for all of my frustrating user base who demands that their computers "do stuff" while also demanding that they keep Windows. Seems so oxymoronic some times...

#

Re:PDFCreator

Posted by: Anonymous Coward on May 09, 2007 02:27 AM
If I don't hear about this POS product mentioned everytime another PDF product is in the news this world would be a better place.

#

Re:PDFCreator

Posted by: Anonymous Coward on May 09, 2007 08:07 AM
You mean Windows?

#

Re:PDFCreator

Posted by: Administrator on May 09, 2007 05:30 AM
If people could stop themselves from making nasty comments when others are just trying to help, the world would be a better place.

#

Re(1):PDFCreator

Posted by: Anonymous [ip: 76.114.147.255] on October 01, 2007 01:20 AM
POS?? This lil' program saved the compnay where I work, a few thousand dollars. The one neat feature it has, print straight to email.

#

A little off topic....

Posted by: Anonymous Coward on May 08, 2007 11:01 PM
Thanks for the details. Can anyone tell me how to optimize PDFs for the web in Linux? I get a lot of monster files that are quickly and simply reduced in Acrobat (full version) on win, but I've never been able to figure this out in Linux.

#

Re:A little off topic....

Posted by: Anonymous Coward on May 08, 2007 11:32 PM
That depends upon where the source is from. If your source simply converts a bitmap to PDF (such as several scanners), you are out of luck. On the other hand, if you are producing a PDF you can manipulate it with GhostScript. Tools such as ps2pdf and pdf2ps can help. Specifically, look at the -dPDFSETTINGS, -dProcessColorModel, and -r settings. You can save significant space by dropping to grayscale and a low resolution. There are many other options, too.

#

Re:A little off topic....

Posted by: Anonymous Coward on May 09, 2007 03:40 AM
man pdfopt

PDFOPT(1) Ghostscript Tools PDFOPT(1)

NAME

              pdfopt - Ghostscript PDF Optimizer

SYNOPSIS

              pdfopt [ options ] input.pdf output.pdf

DESCRIPTION

              pdfopt uses gs(1) to convert the Adobe Portable Document Format (PDF)

              file "input.pdf" to a so-called optimized form in "output.pdf". Opti-

              mization puts the elements of the file into a more linear order and

              adds "hint" pointers, allowing Adobe’s Acrobat(TM) products to display

              individual pages of the file more quickly when accessing the file

              through a network.


              Note: input.pdf and output.pdf must not be the same. If they are, the

              file will probably be destroyed. pdfopt checks for this.

#

Re:A little off topic....

Posted by: Anonymous Coward on May 09, 2007 10:41 PM
Thanks, I'll give that a whirl!

#

Next stop: scanning to PDF

Posted by: Anonymous Coward on May 09, 2007 04:05 AM
A true "PDF-making machine" ought to make it easy to convert scans to PDF as well.

ps2pdf works great for the occasional paper form - once you know what to do and don't mind the extra steps, but it would be nice to have a graphical utility with preview mode to make the process easier and more accessible to neophytes.

#

Re:Next stop: scanning to PDF

Posted by: Anonymous Coward on May 09, 2007 11:56 AM
gscan2pdf

<a href="http://gscan2pdf.sourceforge.net/" title="sourceforge.net">http://gscan2pdf.sourceforge.net/</a sourceforge.net>

#

Re:Next stop: scanning to PDF

Posted by: Anonymous Coward on May 09, 2007 10:19 PM
Xsane has save to pdf-
<a href="http://xsane.org/" title="xsane.org">http://xsane.org/</a xsane.org>

#

Thanks!

Posted by: Anonymous Coward on May 09, 2007 05:34 AM
Thanks for letting me know about cups-pdf. I guess I've overlooked it before.

#

It's a shame

Posted by: Anonymous Coward on May 09, 2007 06:04 AM
It is a shame, that not all operating systems have native support for printing to PDF and PostScript.

#

Primo PDF - free for windows

Posted by: Anonymous Coward on May 09, 2007 06:16 AM
For windows users, they can install primo pdf to do this for free.
<a href="http://www.primopdf.com/" title="primopdf.com">http://www.primopdf.com/</a primopdf.com>

#

Trees

Posted by: Anonymous Coward on May 09, 2007 06:27 AM
Paper is a renewable resource. Paper manufacturers support the planting of more trees than any of us can imagine. Go ahead and print on paper. Saving PDFs will only save you money (which isn't so bad).

#

Re:True.

Posted by: Anonymous Coward on May 09, 2007 09:16 AM
Seems like everyone forgets that. We're not printing on paper from 1000 year old trees. The ingredients in paper include the 'waste' products from lumber production.

It's impossible to make a 2'x4' from a twig -- but that twig can be ground into pulp, spread, bleached, and dried into paper.

#

Re:Trees

Posted by: Anonymous Coward on May 09, 2007 10:46 AM
And running the computers 24/7 probably harms the environment more than when we used a pen the piece of paper.

#

Re:Trees

Posted by: Anonymous Coward on May 09, 2007 10:43 PM
That is very true, and everyone should be aware of that. Please save the planet, don't run your computers 24*7.

#

Do Linux users need this?

Posted by: Anonymous Coward on May 09, 2007 05:59 PM
In Linux, one can use "convert" to convert an image to PDF, "ps2pdf" to convert PostScript files to PDF, and OpenOffice to convert `office files' (including *.doc and *.xml) to PDF. Why bother with cups-pdf then?

#

Re:Do Linux users need this?

Posted by: Anonymous Coward on May 09, 2007 07:27 PM
Network print for users, save installing software on their machines.

Also, doing network print can bring the processing back to the server, where you may want to do it cause the workstations are crap.

Easier administration.

Really, there are a bunch of reasons for doing this.

#

CutePDF

Posted by: Anonymous Coward on May 09, 2007 08:09 PM
CutePDF does the trick on windows.

<a href="http://www.cutepdf.com/" title="cutepdf.com">http://www.cutepdf.com/</a cutepdf.com>

#

Your instruction doesn't work...

Posted by: Anonymous Coward on May 10, 2007 02:13 AM
Your instructions don't work:


    "Go to System -> Administration -> Printing

      to bring up the Printer configuration dialog."

On my system, this menu item is not present. (I have openSUSE 10.2 with KDE). Why do you assume a Gnome desktop without saying so??

#

Re: Your instruction doesn't work...

Posted by: Anonymous [ip: 211.221.130.120] on August 17, 2007 06:22 AM
Doesn't Ubuntu Feisty install Gnome desktop if you go by default installation procedure? Guess that's why.

#

What linux really needs

Posted by: Anonymous Coward on May 10, 2007 06:24 AM
is the ability to create pdfs that retain their links, eg webpages, indexes, tables of contents etc. PDF print drivers only go so far.

It is frustrating to create a linux document that has its links stripped out when its printed to pdf.

Are there any apps that can retain links like Adobe Professional?

#

ps2pdf does it better

Posted by: Anonymous Coward on May 18, 2007 10:57 AM
tried this and ooffice build in pdf creation tool. Still ps2pdf gave several times better results.

#

Great Article

Posted by: Administrator on May 09, 2007 01:43 AM
Great article. Inspired me to write this one for Fedora: <a href="http://www.pronetit.com/2007/05/08/howto-turn-your-fedora-box-into-a-pdf-making-machine/" title="pronetit.com">http://www.pronetit.com/2007/05/08/howto-turn-you<nobr>r<wbr></nobr> -fedora-box-into-a-pdf-making-machine/</a pronetit.com>

#

Fonts

Posted by: Administrator on May 10, 2007 03:52 AM
Whenever I create a pdf under linux (under kde) the fonts look jagged. Any tips for make crisp looking pdf's?

#

Turn your Linux box into a PDF-making machine

Posted by: Anonymous [ip: 212.2.101.20] on August 10, 2007 01:28 PM
About fonts - I use Kubuntu 7.04, the same problem. Fonts are ugly. Anyway all that pd2pdf, cute-pdf, pdftk are nothing compared to PDFCreator, Adobe Acrobat. N-O-T-H-I-N-G. It is high time to create some applications that do that work in a human way.

#

Turn your Linux box into a PDF-making machine

Posted by: Anonymous [ip: 211.221.130.120] on August 17, 2007 06:25 AM
Well, they are free aren't they? Care to contribute? That is what this OPEN means.

#

Can't get this to work....

Posted by: Anonymous [ip: 74.61.189.242] on September 30, 2007 10:00 PM
There is no 'virtual printer' option anywhere in my Ubuntu 6.06 add new printer wizard! Help!

#

it doesn't work when Apache is running

Posted by: Anonymous [ip: 129.118.164.161] on October 02, 2007 08:26 PM
Windows will say that it can't connect to the printer.

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya