clickable checkmarks in pdf with ocgs

I want to create a pdf (with pdflatex) with some ocgs layers. These layers are only images. Further I want to activate and deactivate these layers with boxes and checkmarks. So for example if I see a image the box has a checkmark. Then I click in the box on the checkmark and the image will disappear.

I already created the pdf with the images, the boxes (makeboxes) with checkmarks at the right position. I used makeboxes, because I could not handle checkboxes. The only problem is, that I do not know, how to include the function, that the checkmark in the box will disappear and appear again, if I click on it.

Currently I just have one makebox with a checkmark for one layer.

Can someone help me?

Thank you.

That is my code:

\documentclass{article}
\usepackage[pscoord]{eso-pic}
\usepackage[left=0.0001mm, right=0.0001mm, top=0.0001mm, bottom=0.0001mm, paperheight=16.54in, paperwidth=11.69in]{geometry}
\usepackage{pdflscape}
\usepackage{ocgx}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{rotating}
\usepackage{listings}
\usepackage{wasysym}
\usepackage{hyperref}

\newcommand{\placetextbox}[3]{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>}
\setbox0=\hbox{#3}% Put <stuff> in a box
\put(\LenToUnit{#1\paperwidth},\LenToUnit{#2\paperheight}){\vtop{{\null}\makebox[2pt][c]{#3}}}%
}%
}%

\begin{document}
\begin{landscape}

\makebox[0pt][l]{%
\begin{ocg}{a}{1}{1}%
\begin{tikzpicture}%
\node [inner sep=0pt] {\includegraphics[scale=0.98]{image_a}};%
\placetextbox{0.31}{0.81}{%
\switchocg{2}{%
\begin{sideways}%
\scalebox{2.6}{%
\makebox{\ooalign{$\checkmark$\cr\hidewidth$\square$\hidewidth\cr}}}%
\end{sideways}}}%
\end{tikzpicture}%
\end{ocg}%
}%
\makebox[0pt][l]{%
\begin{ocg}{b}{2}{1}%
\begin{tikzpicture}%
\node [inner sep=0pt] {\includegraphics[scale=0.98]{image_b}};%
\end{tikzpicture}%
\end{ocg}%
}%
\end{landscape}
\end{document}


To appear/disappear together with the image, the \checkmark must be placed on the same layer as the image.

For this purpose, the example defines

 \layerCheckBox{<layer name>}{<layer internal name>}{on | off}


For convenience, a command for creating radio buttons is also provided. From layers belonging to the same radio button group, only one can be enabled at a time (requires ocgx2):

\layerRadioBtn{<radio btn group name>}{<layer name>}{<layer internal name>}{on | off}


Moreover, the TikZ facilities for absolute positioning on the page are used here:

\documentclass[12pt]{article}
\usepackage[a4paper,landscape,left=1pt, right=1pt, top=1pt, bottom=1pt]{geometry}

\usepackage{ocgx2}  % PDF Layers
\usepackage{amssymb} % \checkmark
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% check box command for layer switching
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\layerCheckBox[3]{%
% #1: layer name (as shown in Layers tab), #2: layer id,
% #3: initial visibility
\resizebox{2ex}{!}{\ooalign{%
\switchocg{#2}{$\square$}\cr%
\begin{ocg}{#1}{#2}{#3}$\checkmark$\end{ocg}%
}}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% radio button command for layer switching
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% #2: layer name (as shown in Layers tab), #3: layer id,
% #4: initial visibility
\resizebox{2ex}{!}{\ooalign{%
\showocg{#3}{$\circ$}\cr%
\begin{ocg}[radiobtngrp=#1]{#2}{#3}{#4}$\bullet$\end{ocg}%
}}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{tikz}
\usetikzlibrary{calc}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% absolute positioning of typeset material
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\placetextbox}[3]{%
% #1: horizontal position (fraction of page width)
% #2: vertical position (fraction of page height)
% #3: content
\tikz[remember picture,overlay,x=\paperwidth,y=\paperheight]{%
\node[anchor=south west,inner sep=0pt]
at ($(current page.south west)+(#1,#2)$) {#3};
}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{graphics}
\usepackage{mwe} % example images

\begin{document}

\placetextbox{0.1}{0.9}{\layerCheckBox{Image A}{imgA}{on}~Image~A}
\placetextbox{0.5}{0.9}{\layerCheckBox{Image B}{imgB}{off}~Image~B}

\placetextbox{0.1}{0.55}{%
\begin{ocg}{Image A}{imgA}{on}%
\includegraphics[width=0.3\paperwidth]{example-image-a}%
\end{ocg}%
}
\placetextbox{0.5}{0.55}{%
\begin{ocg}{Image B}{imgB}{off}%
\includegraphics[width=0.3\paperwidth]{example-image-b}%
\end{ocg}%
}

\placetextbox{0.5}{0.5}{\layerRadioBtn{myRdoBtns}{Image ?}{img?}{off}~Image~?'}

\placetextbox{0.1}{0.15}{%
\begin{ocg}{Image C}{imgC}{on}%
\includegraphics[width=0.3\paperwidth]{example-image-c}%
\end{ocg}%
}
\placetextbox{0.5}{0.15}{%
\begin{ocg}{Image ?}{img?}{off}%
\includegraphics[width=0.3\paperwidth]{example-image}%
\end{ocg}%
}

\end{document}
`
• Hey, @AlexG ,thanks for that answer and the code. But I have one problem with it. When I run the script I get the following error message back form the terminal: ! Undefined control sequence. l.115 \sys_if_engine_xetex:T {\bool_gset_true:N\g_ocgxii_dvipdfmx_bool} I have the ocgx2 package. Do you have a tip for me? Thank you. – HHVice May 2 '16 at 17:06
• I am using TeXLive-2015 with the last package updates before freezing a couple of weeks ago. TeXLive-2016 is still in pretesting phase but soon to be released. But MiKTeX should do as well, if you are on Windows. To get the latest updates available you should first synchronize the package database, then do the actual packages update. – AlexG May 2 '16 at 19:51
• Alternatively, you could use the sharelatex.com online editor. I have just tested the code and it works (you have to download the generated PDF and open it in Adobe Reader or Evince. – AlexG May 2 '16 at 20:03