TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm planning to use MetaUML to automatically generate UML diagrams (as images) and display them.

I found that there is an utility, mptopdf, that helps generating the output as a PDF file:

mptopdf example.mp

Is there any way that I can generate the output as an image file (png/jpg, or any format)? Please suggest. Am entirely new to this.

share|improve this question
Welcome to tex.sx! Note that you don't have to (and shouldn't) sign with your name since it automatically appears in the lower right corner of your post. – Hendrik Vogt Jan 16 '11 at 16:10
@Hendrik: Thanks! I'll keep that in mind :) – Barun Jan 17 '11 at 5:41
up vote 3 down vote accepted

If you have ImageMagick installed, you can easily convert the pdf to any other image format:

convert -trim +repage example.pdf example.png

You can replace .png by any other supported format. The -trim +repage option removes unnecessary whitespace surrounding the image and sets the canvas size to the trimmed image. You can also add -density 300 (or any other number) to specify the dpi of the resulting raster image. For example,

convert -density 600 -trim +repage example.pdf -resize 200% example.png
share|improve this answer
This is wonderful! With IM I can even scale up the image size. Thanks! However, I'll be using this in context of a web application. I was wondering if the output image could be generated "directly". Becasue, creating a PDF and then converting it requires both time and space. – Barun Jan 17 '11 at 5:43
I have never used MetaUML, so I can't tell. Compiling the metapost to ps instead of pdf and converting from there might be a bit faster (be sure to do some real world test). But basically I think this is the process that is usually used to get an image file out of TeX code. – Caramdir Jan 17 '11 at 6:15
In case someone was as clueless as I was on where to put -density and -resize, it's convert -density 600 -trim +repage example.pdf -resize 200% example.png. Higher sampling density makes the output picture sharper, which is needed when resize up. – Billiska Jan 2 '14 at 7:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.