Combining hyperref and pdfcomment

Asked 2 years ago, Updated 2 years ago, 95 views

The link functionality provided by the hyperref package (\hyperref command) and the tooltip functionality provided by the pdfcomment package are encountered.Verifying in the following TeX document:

\ documentclass {article}
\uspackage [dvipdfmx] {hyperref}
\uspackage [dvipdfmx] {pdfcomment}

\begin { document }
\section {Hello World}\label {sec:hw}
\begin {enumerate}
  \item\pdftooltip {itworks} {this is tooltip text}
  \item\ref{sec:hw}
  \item\hyperref [sec:hw] {click here}
  \item\pdftooltip {\hyperref[sec:hw]{click here}}{this is tooltip text}
  \item\hyperref [sec:hw] {\pdftooltip {click here} {this is tooltip text}}
\end {enumerate}
\end { document }

What I want to achieve is a way to use it like the fourth and fifth items, but it doesn't seem to work even though I can compile it.Is there any solution?

Environment:
- This is e-pTeX, Version 3.14159265-p3.8.2-190131-2.6 (utf8.euc) (TeX Live 2019/Cygwin) (preloaded format=platex2019.12.14) - Package:hyperref 11/30/2018 v6.88e Hypertext links for LaTeX
- Package:pdfcomment November 1, 2018 pdfcomment.sty v2.4a-Josef Kleber(C) 2008-2012, 2015-2016, 2018
- This is dvipdfmx Version 20190225 by the DVIPDFMx project team, modified for TeX Live, extended version of dvipdfm-0.13.2c developed by Mark A.Wicks.
- viewer:Adobe Acrobat Reader DC Product Version 19.21.20058.359605

If you get the same results, you won't be obsessed with these package compilers.
Thank you for your cooperation.

latex

2022-09-29 22:42

1 Answers

https://tex.stackexchange.com/q/103628 I found something that works, so I'll post it.

When used in combination with \hyperref and \pdftooltip, PDF markups (?) are duplicated in the same area, so one of them (links as far as I've tried) appears on top of the other, which is likely the problem mentioned in the question.Therefore, it would be possible to either attach the tooltip to link not. or attach the link to widget not.The former does not appear to exist in the specification, so the code for experimenting with the latter is as follows:

\ documentclass {article}
\uspackage [colorlinks]{hyperref}

\makeatter
\newcounter {hyperref@tooltip}
\def\hyperrefWithTooltip[#1]#2#3\beginggroup%
  \let\hyper@link\hyper@link@insert@tooltip%
  \def\tooltip@content{#3}%
  \hyperref[#1]{#2}%
  \endgroup}
\def\hyper@link@insert@tooltip#1#2#3{%
  \Hy@VerboseLinkStart {#1}{#2}%
  \ltx @IfUndefined {@#1 bordercolor}{%
    \let\Hy@tempcolor\relax%
  }{%
    \edef\Hy@tempcolor\endcsname}%
  }%
  \beginggroup%
    \protected@edef\Hy@testname{#2}%
    \ifx\Hy@testname\@empty%
      \Hy@Warning {Empty destination name,%
        \MessageBreak using `\Hy@undefinedname'}
      \let\Hy@testname\Hy@undefinedname%
    \fi%
    \pdfmark [{#3}]{%
      Color=\Hy@tempcolor,%
      linktype = {#1},%
      AcroHighlight=\@pdfhighlight,%
      Border=\@pdfborder,%
      BorderStyle=\@pdfborderstyle, %
      pdfmark=/ANN, %
      %Subtype=/Link,%
      Subtype=/Widget,%
      Raw = {%
        /TU(\tooltip@content)%
        /T(tooltip.\thehyperref@tooltip)%
        /C[]%
        /FT/Btn%
        /F768%
        /Ff65536%
        /H/N%
        /BS<</W 0>>%
        %/A</S/GoTo/D(\Hy@testname)>>%equiv.to.Dest
      },%
      PDFAFlags = 4,%
      Dest=\Hy@testname}%
  \endgroup}%
\makeatother

\begin { document }
\section {hello world}\label {sec:hw}
\begin {itemize}
  \item hello\ref {sec:hw}
  \item\hyperref [sec:hw] {click here}
  \item\hyperrefWithTooltip [sec:hw] {click here} {this is tooltip text}
\end {itemize}
\end { document }

Compiling this with latex + dvips + ps2pdf resulted in the expected results.However, there are the following problems:

  • \hyperrefWithTooltip does not display a link frame (no problem with operation)
  • tooltip does not appear outside of Acrobat Reader
  • pdf.js does not function as a link and does not display tooltip

I would appreciate it if you could continue to suggest better solutions.


2022-09-29 22:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.