‘Print’ anything to a PDF Document in GNU/Linux

March 1, 2007

Being able to save a file as a PDF document is very handy. Whether you want to save something from a browser, a presentation / document you are creating, or the output from any other application, being able to save it as a PDF document offers a number of advantages, but probably most especially when you want to pass it around.

Saving documents and spreadsheets to PDF has long been as simple as a button push with Open Office.org. This approach I would recommend where you can use it, as its’ output is slightly better than the alternatie approach shown here, in that the PDF exports from Open Office can include links, internal and external, and some other stuff to boot probably.

However, what about the rest of the applications you use ?

Saving a web document as html can get messy if you are moving things around and forget a piece (such as the files folder). It is also messier to pass things around in this format.

PDF is simply a single file to deal with whether you are making a back-up copy or passing it on. But probably a more significant point is that the format is accessible to almost anybody with a computer, whether a desktop, portable or handheld, thanks to Acrobat reader.

If we take the example of an online resource, I have tried printing to a file, essentially saving it as a postscript document. I was a little disappointed, however, to find that Envince wouldn’t output Postscript to PDF. A quick search showing this made me happy again. It’s a more elegant solution in that it goes directly to PDF rather than using PostScript as an intermediate that is visible in the process. I have taken that solution, but progress on a slightly different route, while still using the Ubuntu flavour of Gnu/Linux.

[ Primo PDF is a nice free app for windows that achieves the same results.]

So here we go with Ubuntu, The Edgy/6.10 release.

First off, you will need to get and install the cups-pdf package. Open Synaptic… (use your own password if prompted, this is for administration functions required to install packages )

Open Synaptic… and search for cups-pdf, select it for install and click apply.

Next, open the CUPS web interface at http://localhost:631. This was up and listening by default on my install of Ubuntu.

Your Local CUPS Web Interface Page

Fill in the details for the new printer. The ‘Name‘ is what the printer will be shown to you as by application you later want to print from. Thus it makes sense to be explicit that it is a virtual PDF printer, especially if you have lots of printers on your network.

Add Printer, step 01

select the Virtual PDF printer

Add Printer, step 02

Pick Postscript as the make…

Add Printer, step 03

Select the generic postscript colour printer, click Add Printer.

Add Printer, step 04

At this point you may be prompted for a username and password, simply enter your own details. It is possible to disable this security measure, but probably not wise if you are on a public network.

And you are done :)

Add Printer, finished :)

To test it out, I went to Java World, picked a random article and switched to the print version in order to print it cleanly (without menus etc. from the web site showing.).

Just make sure the printer selected is the cups pdf printer just set up, and click print…

Example web page conversion-

And your job is printed, the output actually being sent to the local file system in the form of a PDF document :)

When the print job is complete, browse to ~/PDF/ and your file should be there. This location is probably /home/<username>/PDF/ on most systems, but to be sure, you can you can press CTRL+L in the Nautilus File Browser (the default file browser on Ubuntu Gnome) and type in ~/PDF/ manually into the location bar.

Your PDF file should be ready to be viewed.

Output PDF File

And that is it !

I have been using this for a while now without issue, and it can be used from almost any application.

From applications that provide a more basic printing interface, I have used “lpr -P pdf-printer ” as the print command to ensure the output goes through this PDF generation process I have set up.

If you want to keep the links from a web-page working in your output PDF document, this does not yet work with this approach. Where this would be useful, I have simply selected and copied the data from my browser and pasted it into Open Office, and then output to PDF from there. A more automated solution would of course be preferrable, maybe down the road firefox will have an “export to PDF” function :)

It might be nice to configure the target location of the PDFs to somewhere else, or have the option of specifying a location when you hit print, and this is possible, but I prefer not to have to take that extra step. The output is always in the PDF folder in my home directory, so I always know where to find them.

Now that I am using it a while, being able to specify a file name might well be useful. Especially when printing from web pages, where the title is used. I do however find myself going to the PDF folder after printing, renaming the output and putting it somewhere else in my filesystem. Stil, it would be a nice feature to have.


Gnu/Linux

March 1, 2007

I am taking a course at WIT since Autumn 2006.

I found it interesting to hear one of the lecturers discuss “Gnu/Linux” rather than just “Linux”.

In my experience that latter is the norm. Ok it is less of a mouthful, though on the other hand however this is a free platform, developed primarily by individual voluntary efforts, so I can understand the sentiment that the major groups involved should get credit where it is due.

The “Linux” bit comprises the OS Kernel, and “provides the basic services and device drivers used by all other programs running” (http://www.linux.org) on the system.

The GNU utilities and programs make up most of the basic OS and other tools.

There seems to have been quite a bit of discussion elsewhere about this, see this article on GNU.org and this wikipedia entry. The Debian distribution (http://www.debian.org/ ) is one flavour of the platform that actually use GNU/Linux rather than just Linux in their name. I am not sure if there are many others.

Perhaps interestingly, between the flavours even there may be cause for similar discussion. Ubuntu ( http://www.ubuntu.com/ ) for instance, is heavily based on Debian GNU/Linux (http://www.debian.org/misc/children-distros).  However I can’t recall ever seeing a mention of it while using or installing the system…

Should we rename to Ubuntu Debian GNU/Linux ?

Lets have a vote, who is for and against ?

(”,)