‘Print’ anything to a PDF Document in GNU/Linux
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 )
… 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.
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.
select the Virtual PDF printer…
Pick Postscript as the make…
Select the generic postscript colour printer, click Add Printer.
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
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…
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.
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.
April 3, 2007 at 10:14 pm
Thank you! This was very handy. Running Xubuntu Edgy.
May 5, 2007 at 7:00 pm
Much to my surprise this does not work for me. I have two printers currently and the third as above is not adding. I go through the steps but the printer does not get created. I am using fiesty.
August 4, 2007 at 2:20 am
thank you - works well for me.
However, after a while, I found that the generated PDFs were all bitmaps. That means, I can’t search for text within these (or can’t copy text from the PDF).
You can verify this by opening the PDF with the Viewer of your choice and using the “Select Tool” (that’s how it’s called in KPDF) to select some text. KPDF then responds with a Select Box titled “image (xxx by yyy pixels).
Is this the same for you?
August 9, 2007 at 8:45 pm
Thanks for the feedback. Glad somebody is reading
MichaelMunich, sounds about right to me though as the process involves the printing process, and printers would just need the “bitmaps” for the pages.
I have a vague recollection of trying to do what you want before though, create PDFs in this fashion that had selectable text, clickable hyper-links, etc.
I think it involved just using a ps printer driver again, and each time I printed to it (I didn’t actualy have a printer for the dirver I used) I would check ‘print to file’.
I then edited the resultant “.ps” file in GhostView or something like that, and generated the PDF from there.
If I get time I’ll try to reproduce and post it. If you get it working, feel free to link to your post from here.
August 21, 2007 at 9:07 pm
Well, this doesn’t work well at all - much better results printing to PS and using ps2pdf to convert. I tried printing pages from a government website that we need to use, and the output from Virtual-PDF was not aligned, the formatting was all out of whack. If we print the exact same page using Postscript/Default printer and print to file and run ps2pdf, the file looks perfect. Don’t know why, but that’s what we’re sticking with.
September 20, 2007 at 10:23 pm
Thank for the comment Brandy.
that’s just the approach I used to take, pity about your formatting issues, I haven’t come across such myself, yet at leat.
Maybe if I do I will try to see if anything can be done about it with the above approach.