Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I know that pdfimages can extract bitmap graphics from a pdf file.

But what if the embedded image is some line drawings, e.g., an image generated by some TikZ code in LaTeX?

Assumption: the pdf file is a certain scientific paper. It could contain multi figures on one page. (Sorry that I did not mention this.)

EDIT

I just need the high quality picture. It seems the picture is generated by some tikz commands (it's a vector picture for sure).

Well, it's nice to know the commands for generating that picture, but I did not expect that would be possible.

EDIT2

I'm using the trim & clip, options of \includegraphics now, but still looking forward to some automatic extraction commands.

\documentclass{standalone}
\usepackage{graphicx}

\begin{document}
    \includegraphics[trim = 15mm 113mm 110mm 130mm, clip]{a-single-page-pdf-file}
\end{document}

EDIT3

Add a ruler, just to make it easier

\documentclass{standalone}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}
    %\includegraphics[trim = 1.5cm 11.3cm 11cm 13cm, clip]{single-page-pdf}

    \begin{tikzpicture}
        \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics{single-page-pdf}};
        % A4 paper size: 21.0 × 29.7
        \draw[help lines,xstep=1,ystep=1] (0,0) grid (21,29.7);
        \foreach \x in {0,1,...,21} { \node [anchor=north] at (\x,0) {\x}; }
        \foreach \y in {0,1,...,29.7} { \node [anchor=east] at (0,\y) {\y}; }
    \end{tikzpicture}

\end{document}
share|improve this question
1  
So what you actually want is the TikZ code of the picture in the PDF? –  Count Zero Jun 2 '13 at 16:53
1  
You cannot extract the TikZ information. You can of course extract the vector graphics produced, if that is what you want. –  tohecz Jun 2 '13 at 16:56
    
I just need the high quality picture. Or should I just use trim option to include that pdf file? –  Hongying Jun 2 '13 at 16:56
1  
Maybe this question is what you're looking for: How can I use TikZ to make standalone graphics? –  Alan Munn Jun 2 '13 at 16:59
    
@AlanMunn Actually I want to do the inverse. –  Hongying Jun 2 '13 at 17:02

1 Answer 1

I'm not quite sure if this is what you want, because it's unclear how much automation will be of use to you. In this answer, I'll first generate a PDF document that has one TikZ image on each page (I know you don't need to know how to do that, but it will make the whole process a self-contained example for others.) Then I'll use the pdftk utility to split each page into a single PDF file. I'll then use the pdfcrop utility from within the LaTeX document to crop each page and then use \includegraphics to include it. So the final result will be a single page with each of the individual images included and automatically cropped.

To make this solution work, you need to compile the second document with \write18 enabled.

Generate some images

Filename: repeat-circles.tex

\documentclass{article}
\usepackage{tikz}
\usepackage{pgffor}
\pagestyle{empty}
\begin{document}
\foreach \x in {1,...,5}
{\begin{tikzpicture}
\node [red,fill,text={white},font={\bfseries\Huge}, circle, minimum width=\x cm ] {\x};
\end{tikzpicture}
\clearpage
}
\end{document}

This will create a file with 5 circles of different sizes, each on its own page.

Split the file with pdftk

Now we use pdftk to split the file into 5 separate pages:

% pdftk repeat-circles.pdf burst

By default this will create one file for each page with filenames pg_<nnnn>.pdf.

If you are generating the single pages manually, you will not need this step.

Crop and include each file as in image into another document

Now we create a LaTeX document which will take each of these individual pages, crop the image and include each one using \includegraphics.

\documentclass{article}
\usepackage{graphicx}
\usepackage{pgffor}
\begin{document}
\foreach \x in {1,...,5}
{
\immediate\write18{pdfcrop pg_000\x.pdf}
\includegraphics{pg_000\x-crop.pdf}
}
\end{document}

The final output of this document is:

output of code

share|improve this answer
    
Thanks for your answer. But what if the figure is surrounded by some text and other figures? (there is some text and could be several figures on one single page of a paper.) –  Hongying Jun 3 '13 at 6:06
    
I don't think there's any way to do that automatically. Or at least, I know of no way to do this. –  Alan Munn Jun 3 '13 at 10:56

Your Answer

 
discard

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.