# Export algorithm as pdf

I use algorithm2e package for my algorithms and want to export my algorithm as pdf and could not find a way to do it. Is there any way to do this?

The reason is that I use a style file provided to me and when I use this style file, the space between the lines gets huge and none of my algorithms fits into a page. I would like to export them as pdf and then include them.

Below is an example of what I want to do, it exports the given tikz picture as pdf. I want to put an algorithm and get a pdf which includes the algorithm as if it is an image or graphics.

\documentclass{article}

\usepackage{tikz,nicefrac,amsmath,pifont}
\usepackage[ruled,vlined,linesnumbered]{algorithm2e}
\usepackage[graphics,tightpage,active]{preview}
\PreviewEnvironment{tikzpicture}
\newlength{\imagewidth}
\newlength{\imagescale}

\begin{document}

\begin{tikzpicture}[<->,>=stealth,auto,shorten >=1pt]
\tikzstyle{agent}=[rectangle,draw,rounded corners,text
centered,node distance=2cm,text width=1.1cm,scale=0.9];
\tikzstyle{ont}=[ellipse,draw,node distance=2.4cm,text
width=1.7cm,scale=0.9,text centered];
\tikzstyle{edge}=[<->,scale=0.9]

\node at (0,0.5) [agent] (UA) {UA};
\node at (3,-1.5) [ont] (EO) {Environment\\Ontology};
\node at (3,2.5) [ont] (DO) {Domain\\Ontology};
\node at (7,2) [agent] (A1) {Agent\\1};
\node at (7,0.5) [agent] (A2) {Agent\\2};
\node at (7,-1) [agent] (A3) {Agent\\3};
\path
(A1) edge (UA)
edge[->,dashed] (EO)
edge[->,dashed] (DO)
(A2) edge (UA)
edge[->,dashed] (EO)
edge[->,dashed] (DO)
(A3) edge (UA)
edge[->,dashed] (EO)
edge[->,dashed] (DO)
(UA) edge[->,dashed] (EO)
edge[->,dashed] (DO);
\end{tikzpicture}
\end{document}


I do not use any packages like setspace in my latex code. The provided style file is here.

-
Please describe how "exporting as PDF" differs from compiling a LaTeX document to PDF. –  Andrey Vihrov May 23 '11 at 7:18
Please, show a minimal example. Are you using the setspace package or other tools that enlarge the interline space? –  egreg May 23 '11 at 8:38
the problem is why you want to do this and not include the tikz environment directly in your document. –  egreg May 23 '11 at 9:32
@egreg because my algorithms, figures etc does not look nice and neat any more when I apply the style. I am not familiar with the style file and it is complicated for my knowledge. I am looking for a turnaround like the example, thats all. –  Basak May 23 '11 at 9:39

You can use the standalone document class; a little example:

\documentclass{standalone}
\usepackage{algorithm2e}

\begin{document}

\begin{algorithm}[H]
\SetAlgoLined
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{