Join 3,572 readers in helping fund MetaFilter (Hide)

Tags:

Including PDF figures in a LaTeX document
February 7, 2006 10:46 AM   Subscribe

How can I include a figure from a PDF file in a LaTeX document?

I have a PDF file (for which I do not have the LaTeX source) and I would like to include one of its figures in a new document.

My method up until now has been to take a screenshot and convert to EPS, but I am not happy with the results. Is there a better way? Thanks.
posted by event to Computers & Internet (11 answers total) 1 user marked this as a favorite
 
If your LaTeX installation comes with the pdflatex command, you can at least. Here is one example from one of my files:

\begin{figure*}[t]
\centering
\includegraphics[width=1.0\textwidth]{col1.pdf}
\caption{Test}
\end{figure*}

I then use pdflatex to directly create an PDF file from the latex file. I always use the command line tools from tetex, and don't know about the support for PDF images in other LaTeX environments.
posted by rpn at 11:04 AM on February 7, 2006


I've used the graphicx package with success. You have a line something like:

\includegraphics[bb=1.0in 1.0in 7.5in 10in,page=2]{file.pdf}

where bb is the bounding box of the thing you want to include.

I don't know if this works if you aren't using pdflatex, though.
posted by advil at 11:05 AM on February 7, 2006


Thirding pdflatex. However, the only way to include vector graphics in pdflatex is with PDF -- you can't use EPS, which may be a problem if your other figures are EPS. When using pdflatex, most people use Ghostscript to convert their EPS figures to PDF. One bonus of pdflatex, though, is that for raster images you can directly include PNG and JPG files, which I like a lot.

If you can't or don't want to use pdflatex, if you have access to Adobe Illustrator, you can open the PDF, crop out what you don't want, and save as an EPS. Ghostscript can also convert from PDF to EPS, with varying levels of success.
posted by zsazsa at 11:21 AM on February 7, 2006


fourthing pdflatex. I often find that pdflatex generates cleaner-looking pdfs, somehow, than dvi->ps->pdf does.

AFAIK, you only need a \includegraphics{file}, not {file.pdf}

If you leave the .pdf off the file, then pdflatex will look for a pdf and latex will look for an eps. Won't help you here, but good for when you're creating your own stuff.
posted by ROU_Xenophobe at 11:28 AM on February 7, 2006


You might want to look at pdfimages, and see if it does what you want. I have it on my Linux machine.

It claims to extract individual images from a PDF file, and save them as PBM or PPM or JPG (which you could convert, if needed). It does make a bunch of such file when I use it, but it's not clear if this utility is actually useful. Most of the output seems like garbage on my machine (when it gives output at all).

But for individual figures from a PDF file, you're going to need something like this.

What platform are you using? This page gives you hints on extracting stuff from a PDF file (again, individual figures from a PDF, not just using a PDF as a figure), but it seems pretty Windows/Mac-centric. For example, I can copy graphics from my own LaTeX generated PDFs in Mac OS X's Preview, and paste them into Photoshop as vector graphics, and then save them for inclusion into another LaTeX document.

That will definitely work if you are using a Mac and have that software. I'm sure something similar is possible on Windows. I'm not so sure about Linux/Unix.
posted by teece at 11:41 AM on February 7, 2006


I am running on a Linux machine, but I do have access to a Solaris box, if that would somehow help.

advil's syntax looks like the perfect thing, but when I run with it, I get blank spaces (of the correct size) instead of my figures.

Do I need to pre-process the PDF somehow?
posted by event at 11:42 AM on February 7, 2006


Correct, you don't need the .pdf suffix. I added it to test that it actually worked correctly, as I had a .png version of the same file as well. If you don't add the suffix, pdflatex will first look for a .png-file, then a .pdf-file if it doesn't exist.
posted by rpn at 11:43 AM on February 7, 2006


pdftex is nice for when you want a PDF final output, too, but that's tangental here at best.
posted by kcm at 12:04 PM on February 7, 2006


I would have liked to have used the \includegraphics method as it seems the most elegant solution, but all I can get from it is blank squares. What did work for me was zsazsa's recommenation to use Illustrator -- at least with it I can get the vector version of the figures.

Thanks, everybody!
posted by event at 12:32 PM on February 7, 2006


all I can get from it is blank squares.

I'm not sure what's wrong -- I actually took that line from a working document that imported a page from another document there, so it should work. Is it possible you were interpreting the bb arguments wrong? The first two are positions and the second two are lengths, but I don't remember which corner the positions are and which direction the lengths go (here's a pdf that seems to explain). If you had it wrong you could be copying a blank square that mostly doesn't overlap with an actual page in the file. Also, I have only ever used this with pdfs that I generated myself -- it's possible that some weird pdf could break it (so to find out you could test it with a document that you generated with pdflatex). Hope this helps.
posted by advil at 7:21 PM on February 7, 2006


Wow, as it turns out, I was making both mistakes you describe, advil.

The coordinates for the bounding box are (bottom-left-x, bottom-left-y, top-right-x, top-right-y), so I was grabbing the wrong spot on the page. On top of that, the particular pdf file I'm dealing with does not seem to want to allow this type of thing to happen. When I use one of my own pdf files it works beautifully.

Many thanks!
posted by event at 9:28 PM on February 7, 2006


« Older So, I've just started selling ...   |  Mac Help Req'd! Trouble with ... Newer »
This thread is closed to new comments.