![pdf 文件中的交互按钮](https://linux22.com/image/429689/pdf%20%E6%96%87%E4%BB%B6%E4%B8%AD%E7%9A%84%E4%BA%A4%E4%BA%92%E6%8C%89%E9%92%AE.png)
答案1
正如评论中所述,这种交互性是通过 PDF 层实现的。
PDF 图层有两种类型:奥卡特s(可选内容组),其可见性可以通过 PDF 查看器中的用户交互直接设置,以及眼科医学博士s(可选内容成员字典),其可见性是在运行时通过 OCG 可见性的逻辑组合计算得出的。
只有两个图层protrusion
和expansion
被创建为 OCG。这两个图层只带有“开启”标题。这两个图层最初都设置为“关闭”。
所有剩余的图层都创建为 OCMD,并且它们的可见性在运行时逻辑上取决于两个 OCG 类型图层protrusion
和的可见性expansion
。四个microtype
依赖的段落版本和两个“关闭”标题都存在于此类 OCMD 类型图层上。
pdflatex
用或排版lualatex
,因为xelatex
不支持扩展;至少需要运行三次:
\documentclass[12pt,a5paper]{article}
\usepackage{hyperref}
\usepackage{ocgx2}
\usepackage{xsavebox}
\usepackage{microtype}
\usepackage{kantlipsum}
\parindent=0pt
\begin{document}
% inside saveboxes, define layers using OCMDs (optional content membership dictionaries);
% paragraphs on these layers are typeset subject to various combinations of
% protrusion & expansion
\begin{xlrbox}{p=0,e=0}
\begin{ocmd}{\And{\Not{protrusion},\Not{expansion}}}
\begin{minipage}{\textwidth}
\microtypesetup{protrusion=false,expansion=false}
\kant[1]
\end{minipage}
\end{ocmd}
\end{xlrbox}%
%
\begin{xlrbox}{p=1,e=0}
\begin{ocmd}{\And{protrusion,\Not{expansion}}}
\begin{minipage}{\textwidth}
\microtypesetup{protrusion=true,expansion=false}
\kant[1]
\end{minipage}
\end{ocmd}
\end{xlrbox}%
%
\begin{xlrbox}{p=0,e=1}
\begin{ocmd}{\And{\Not{protrusion},expansion}}
\begin{minipage}{\textwidth}
\microtypesetup{protrusion=false,expansion=true}
\kant[1]
\end{minipage}
\end{ocmd}
\end{xlrbox}%
%
\begin{xlrbox}{p=1,e=1}
\begin{ocmd}{\And{protrusion,expansion}}
\begin{minipage}{\textwidth}
\microtypesetup{protrusion=true,expansion=true}
\kant[1]
\end{minipage}
\end{ocmd}
\end{xlrbox}%
%
\switchocg{protrusion}{\strut Protrusion:} % button which toggles OCG `protrusion'
\makebox[0pt][l]{\begin{ocg}{protrusion}{protrusion}{off}On\end{ocg}}% `On' on OCG
\begin{ocmd}{\Not{protrusion}}Off\end{ocmd}\\[1ex]% `Off' on OCMD
%
\switchocg{expansion}{\strut Expansion:} % button which toggles OCG `expansion'
\makebox[0pt][l]{\begin{ocg}{expansion}{expansion}{off}On\end{ocg}}% `On' on OCG
\begin{ocmd}{\Not{expansion}}Off\end{ocmd}\\[2ex]% `Off' on OCMD
%
% insert saved paragraphs
\makebox[0pt][l]{\xusebox{p=0,e=0}}%
\makebox[0pt][l]{\xusebox{p=1,e=0}}%
\makebox[0pt][l]{\xusebox{p=0,e=1}}%
\xusebox{p=1,e=1}%
\end{document}