getting Dia to give you a pdf

Hello again !  Today’s quick tip concerns a software package called Dia, which is an open source tool (available for both Windows and Linux, as it goes) used to make diagrams, flowcharts, network maps, and so forth.  It has its own file format (.dia), which is (obviously?) useful for saving the projects you’re working on, but less useful if you need to give the diagram to anybody else, either in print or electronic form.

Dia can export to a variety of formats including SVG, PNG, and EPS, but one export format that it lacks native support for is the venerable PDF, which has become a de facto standard for transmitting documents between diverse environments.  There are many advantages and interesting aspects of the PDF format, not the least of which being that what you see on your screen is what you get when it’s printed.  It is unfortunate, then, that Dia won’t spit out a PDF (even if you ask very nicely).

Of course, being that it’s so easy to print directly to PDF (via CUPS, for example) these days, having native support for PDF may not, at first, seem all that useful.  Well, as it turns out, printing directly to PDF might not give you quite what you were looking for.  In practice, you do get a PDF, but what appeared to be a modestly-sized diagram in Dia will turn out to be a multi-page monster in (virtually) printed form.  As a general rule, this is not what you want.

In order to get a usable PDF we need to use an intermediate step between Dia and the final file.  The idea, quite simply, is to export the diagram as one of the supported formats, then convert that file into a PDF.  There are a number of options here, but for our purposes we’ll save the diagram as an EPS file, then use a quick little command-line tool called « epstopdf » to perform the conversion.

There’s a good chance that you don’t have epstopdf on your machine.  If you’re using Ubuntu, you used to be able to install it easily via the APT packager, but these days the little conversion tool comes as part of a larger suite of tools called « texlive-extra-utils ».  This suite is dependant on a number of other packages, so go ahead and install them all :

$ sudo apt-get install texlive-extra-tools

EDIT : In Ubuntu 10.04, the package is named « texlive-font-utils ».

Among many, many little items of interest, our target application will be installed.  To use it, simply feed it the name of the EPS file as an argument :

$ epstopdf somediagram.eps

It will automatically output a PDF file of the same name.  There you go – a nice, shiny PDF of your Dia diagram.

Enjoy !

setting the from address in GNU mail

Today i’m going to address a question that comes up again and again on the various Linux help forums and mailing lists (in one form or another) :

« How do i set the From address when using mail ? »

Of course, « mail » in this case refers to that most basic of all Linux mail applications : GNU mail.  Commonly part of the default software on a Linux box, it’s not used very often in an interactive capacity, but it still gets a lot of play in the System Administration world as a way to quickly fire off automated emails from scripts.  For example :

$ echo "This is the message" | mail -s "This is the subject" user@domain.tld

This would result in a message that’s from whatever raw user@system that the local mailing software detects, such as « » or some such thing.  Normally, whatever defaults (including the From address) that get used are good enough, but occasionally it can be handy to have a finer level of control ; for example, policy restrictions on your local mail relay, or just because the default From address looks bad and you want to make it more readable.

The solution, like so many others in the Linux world, is straightforward once you already know about it, but just obscure enough that it isn’t obvious at first.  The man page for « mail » on Ubuntu (and, likely, other distros as well) has this tasty little morsel of information listed as the very first option :

-a, --append=HEADER: VALUE Append given header to the message being sent

« Headers » form part of every email message, and are used to store all sorts of information about the email, from such pedestrian items as « From: » and « To: », to more esoteric things like Spam analysis breakdowns and binary encoding methods.  For now, the important thing to realise is that the From: address is contained within the From header, and using the argument noted above, we can set it quite easily :

$ echo "The message" | mail -s "The subject" --append=FROM:sensible@domain.tld user@domain.tld

This would send the same message as above, but with the From: address set to « sensible@domain.tld ».  In fact, any header can be altered in this fashion, not just the From header – so if you ever have the need to change other headers, now you know at least one way. 🙂