\newif\ifpdf
\ifx\pdfoutput\undefined
\pdffalse    % we are not running PDFLaTeX
\else
\pdfoutput=1    % we are running PDFLaTeX
\pdftrue
\fi
% Then use your new variable \ifpdf
% \ifpdf
% \usepackage[pdftex]{graphicx}
% \pdfcompresslevel=9
% \else
% \usepackage{graphicx}
% \fi