我想创建一个包含一些 ocgs 层的 pdf(使用 pdflatex)。这些层只是图像。此外,我想使用方框和复选标记激活和停用这些层。例如,如果我看到一个图像,该方框上有一个复选标记。然后我单击复选标记上的方框,图像就会消失。
我已经创建了包含图像的 PDF,框(makeboxes)带有正确位置的复选标记。我使用 makeboxes,因为我无法处理复选框。唯一的问题是,我不知道如何包含该功能,即如果我单击框中的复选标记,该复选标记会消失并再次出现。
目前,我只有一个带有一层复选标记的 makebox。
有人能帮我吗?
谢谢。
这是我的代码:
\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
\AddToShipoutPictureFG*{% Add <stuff> to current page foreground
\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}
答案1
要与图像一起出现/消失,\checkmark
必须将其放置在与图像相同的层上。
为此,示例定义
\layerCheckBox{<layer name>}{<layer internal name>}{on | off}
为了方便起见,创建命令单选按钮还提供。从属于同一单选按钮组的图层中,一次只能启用一个(需要ocgx2
):
\layerRadioBtn{<radio btn group name>}{<layer name>}{<layer internal name>}{on | off}
此外,这里还使用了 TikZ 页面上的绝对定位功能:
\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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\layerRadioBtn[4]{%
% #1: radiobutton group name
% #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.1}{0.5}{\layerRadioBtn{myRdoBtns}{Image C}{imgC}{on}~Image~C}
\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}