Create PDF Files in Linux

There's a real easy way to create pdf files in Linux. Many distros by default allow users to "Print to File," and the resulting file can be a pdf. But I found that this doesn't always work; some apps need to see an installed printer, not the print to file option. Let me introduce to you the cups-pdf package, which will also create pdf files in Linux.

October 26, 2012

I've mentioned around here before that I run a Java app at work every day.  Since this system we run generates an OBSCENE amount of paper, and I try to avoid printing when I can.  And while the clients we're using are Linux boxes, and one of the choices that pops up in any other print dialog I've seen is "Print to File", this doesn't happen in our ERP.  When a print dialog pops up, it only contains the Dell 5530dn we have sitting on the counter.

The latest task I wanted to complete without paper is the daily cash drawer count up.  There are some screens people need printed off that contain stuff like the cash count, credit card and check count, variance, and a few other things.  While the cups-pdf package for Ubuntu generally works great, initially it always prints to the same file.  This means that every time I print another screen, it overwrites the file with the current print.  No good…

I landed (after some googling for cups-pdf prompt for filename) on the Ubuntu Forums in a thread entitled CUPS-PDF file name prompt. After monkeying around the with the bash script posted there, I think I figured it out.

By default, cups-pdf prints to /home/me/PDF  That's fine.  I'm running a web server on my box with a few php apps that we use internally, and I also wanted everyone to be able to get these pdf files.  I made a directory ~/PDF/count-sheets, then did a ln -s /home/me/PDF/count-sheets /var/www/count-sheets  and chmodded it all to 777.  This is so that during the filename prompting I can choose that subdirectory of PDF and not have EVERYTHING stuck in that one directory.

I modified the bash script so that it would create a file with today's datestamp called today's date ( SUGGEST_PDF="${CURRENT_PDF%/*}/$(date '+%Y-%m-%d')_" is the relevant line) and now I get prompted when I print a pdf.  The file names start  like 2012-10-26_  and I've just got to provide a name after the underscore to keep it straight in my own head.

The "Print to File" pdf and the PDF printer file size is about the same.  On a test, I got a 49k file form the former and 50k file form the latter.  The same was true when comparing a PDF printing to a LibreOffice pdf export.  Those exports can be huge sometimes though, so I'm not sure how well this cups-pdf printer will do in various scenarios compared to other ways of creating pdf files.

So, now I can print out our cash counts to a file rather than paper, and anyone at my location or at the other end of the VPN can get hold of them.  Of course, they'll probably just print it out anyway, but that's their problem.


Let me know how you make out.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.