how to create PDF in grayscale mode?
convert PDF color in PDF grayscale.
I need the PDF in grayscale color.
Or in TikZ figure only.
[Tex/LaTex] how to create PDF in grayscale mode or TikZ figure only
coloroutputpdftikz-pgf
Related Solutions
You have a classical vector drawing (z4z.pdf
). With the command line with convert
(ImageMagick
) the image is converted to a bitmap. PDF can also contain bitmaps.
A better way is using Inkscape
. It has an option to convert to the colors to the gray color model. Save again as PDF, see below.
I would use two different directories, the first directory contains the color images, the second directory the grayscale images. Then it is easy to switch between them using \graphicspath
. The current directory should be free of these images, otherwise they would be found first.
\documentclass{article}
\usepackage{xcolor,graphicx}
\iftrue % color
\graphicspath{{img-color/}}
\else % grayscale
\selectcolormodel{gray}
\graphicspath{{img-gray/}}
\fi
\begin{document}
\includegraphics[scale=.5]{z4z}
\end{document}
In case of grayscale the example also switches to the gray color model for the colors controlled by package xcolor
. Also black/white is possible with option monochrome
, but the option is needed at loading time of the color packages:
\documentclass{article}
\usepackage{graphicx}
%\iftrue % color
\iffalse
\graphicspath{{img-color/}}
\else % grayscale
\PassOptionsToPackage{monochrome}{xcolor}
\graphicspath{{img-gray/}}
\fi
\usepackage{xcolor}
\begin{document}
\includegraphics[scale=.5]{z4z}
\textcolor{yellow}{yellow}
\textcolor{red}{red}
\textcolor{blue}{blue}
\end{document}
I don't know exactly what you mean with without having to manually change all the color values?.
If you only want to avoid to change your picture, then the following solution may be a solution:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\definecolor{red}{gray}{0.9}
\definecolor{green}{gray}{0.8}
\definecolor{blue}{gray}{0.7}
\definecolor{yellow}{gray}{0.6}
\definecolor{violet}{gray}{0.5}
\definecolor{orange}{gray}{0.4}
\begin{tikzpicture}
\node[fill=red] at (0,1) {text};
\node[fill=green] at (0,0.5) {text};
\node[fill=blue] at (0,0){text};
\node[fill=yellow] at (1,1) {text};
\node[fill=violet] at (1,0.5) {text};
\node[fill=orange] at (1,0) {text};
\end{tikzpicture}
\end{document}
You redefine all colors, but only once per document. Your tikzpicture is unchanged.
You also may put the redefinitions to a style 'grey_colors.sty' and reuse it for differnt documents.
Qrrbrbirlbel gave a better solution with \PassOptionsToPackage{gray}{xcolor}
when put before loading TikZ.
You may combine the two solutions. The redefinition of the colors gives you a better control on which grey tone a color should get.
Example:
\documentclass{standalone}
\PassOptionsToPackage{gray}{xcolor}
\usepackage{tikz}
\begin{document}
gray-option:
\begin{tikzpicture}
\node[fill=red] at (0,1) {text};
\node[fill=green] at (0,0.5) {text};
\node[fill=blue] at (0,0){text};
\node[fill=yellow] at (1,1) {text};
\node[fill=violet] at (1,0.5) {text};
\node[fill=orange] at (1,0) {text};
\end{tikzpicture}
Color redefinition:
\definecolor{red}{gray}{0.9}
\definecolor{green}{gray}{0.8}
\definecolor{blue}{gray}{0.7}
\definecolor{yellow}{gray}{0.6}
\definecolor{violet}{gray}{0.5}
\definecolor{orange}{gray}{0.4}
\begin{tikzpicture}
\node[fill=red] at (0,1) {text};
\node[fill=green] at (0,0.5) {text};
\node[fill=blue] at (0,0){text};
\node[fill=yellow] at (1,1) {text};
\node[fill=violet] at (1,0.5) {text};
\node[fill=orange] at (1,0) {text};
\end{tikzpicture}
\end{document}
Best Answer
For TikZ figures, you can use the
xcolor
command\selectcolormodel{gray}
before or at the start of yourtikzpicture
. This won't turn images that you import with\includegraphics
to grayscale, though.