
ocgx
PDF 内のリンクをクリックすると、異なるテキスト ブロック (同じページの同じ領域内) が表示されるように使用しています。
ただし、これらのテキスト ブロックにはそれぞれ独自のリンクがあり、テキストが表示されていない場合でも、これらのリンクはページ上で重なり合います (以前に定義された OCG が隠れます)。表示だけでなく、レイヤーの順序も切り替える\href
ことは可能ですか?ocg
下のMWEでは、ボタン1、2でテキストブロックの表示を切り替えると、ではないhref リンクの有無を切り替えると、どちらの ocg も表示されない場合でも、「google.com」リンクのみが表示されます (スクリーンショットではマウス ポインターがキャプチャされていません)。
\documentclass{article}
\usepackage{ocgx}
\usepackage{hyperref}
\usepackage{textpos}
\setlength{\TPHorizModule}{12pt}
\setlength{\TPVertModule}{12pt}
\begin{document}
\actionsocg{ocg1}{}{ocg2}{{\color{blue}{button 1}}}$|$ %toggle ocg1, hide ocg2
\actionsocg{ocg2}{}{ocg1}{{\color{blue}{button 2}}}%toggle ocg2, hide ocg1
%define OCGs:
\begin{ocg}{}{ocg1}{0}
\begin{textblock}{40}(1,1)
\href{http://overleaf.com}{Link 1}
\end{textblock}
\end{ocg}
\begin{ocg}{}{ocg2}{0}
\begin{textblock}{40}(1,1)
\href{http://google.com}{Link 2}
\end{textblock}
\end{ocg}
\end{document}
答え1
これはパッケージで実行できますocgx2
さらに、hyperref
PDF レイヤーを認識できるように少しパッチを適用します。
ただし、PDF レイヤーに配置されたリンクの可視性を尊重するのは Acrobat Reader のみであることに注意してください。
\documentclass{article}
\usepackage{ocgx2}
\usepackage{hyperref}
%patch hyperref to make PDF Annotations PDF-Layer-(OCG)-aware
\makeatletter
\let\Hy@setpdfborderOrig\Hy@setpdfborder
\def\Hy@setpdfborder{\ocgbase@insert@oc\Hy@setpdfborderOrig}%
\makeatother
\usepackage{textpos}
\setlength{\TPHorizModule}{12pt}
\setlength{\TPVertModule}{12pt}
\begin{document}
\actionsocg{ocg1}{}{ocg2}{{\color{blue}{button 1}}}$|$ %toggle ocg1, hide ocg2
\actionsocg{ocg2}{}{ocg1}{{\color{blue}{button 2}}}%toggle ocg2, hide ocg1
%define OCGs:
\begin{ocg}{}{ocg1}{0}
\begin{textblock}{40}(1,1)
\href{http://overleaf.com}{Link 1}
\end{textblock}
\end{ocg}
\begin{ocg}{}{ocg2}{0}
\begin{textblock}{40}(1,1)
\href{http://google.com}{Link 2}
\end{textblock}
\end{ocg}
\end{document}
PDFレイヤーを相互に隠すためのスイッチを で作成するのは、\actionsocg
PDFレイヤーの数が増えると面倒になります。簡素化するために、 pkgocgx2
OCGをグループ化できるラジオボタングループ同じラジオ ボタン グループに属するすべての OCG のうち、一度に有効にできるのは 1 つだけです。これにより、以前に表示されていた OCG が自動的に非表示になります。OCG は、オプションを使用してラジオ ボタン グループに追加されます。OCG をラジオ ボタン グループにグループ化すると、簡単なコマンドを使用して各レイヤーのスイッチを作成radiobtngrp=...
できます。\showocg
\documentclass{article}
\usepackage{ocgx2}
\usepackage{hyperref}
%patch hyperref to make PDF Annotations PDF-Layer-(OCG)-aware
\makeatletter
\let\Hy@setpdfborderOrig\Hy@setpdfborder
\def\Hy@setpdfborder{\ocgbase@insert@oc\Hy@setpdfborderOrig}%
\makeatother
\usepackage{fontawesome,pgffor}
\parindent=0pt
\begin{document}
\foreach \ocgname / \urlicon in {%
GitHub/\faGithub, StackExchange/\faStackExchange, StackOverflow/\faStackOverflow, Google/\faGoogle%
}{\showocg{\ocgname}{\urlicon}\ }\\[1ex]
%define OCGs, within the same Radio Button Group
\foreach \ocgname / \weburl in {%
GitHub/{https://github.com}, StackExchange/{https://stackexchange.com}, StackOverflow/{https://stackoverflow.com}, Google/{https://google.com}%
}{%
\makebox[0pt][l]{%
\begin{ocg}[radiobtngrp=myURLs]{\ocgname}{\ocgname}{off}
\url{\weburl}
\end{ocg}}%
}
\end{document}