Quoting the pdfpages
manual (page 2):
[...] all kinds of links1 will get lost during inclusion. (Using \includepdf
,
\includegraphics
, or other low-level commands.)
However, there's a gleam of hope. Some links may be extracted and later
reinserted by a package called pax which can be downloaded from CTAN [3].
Have a look at it!
The pax
package mentioned is actually a Java program which reads the PDF file, extracts the links and writes their positions to a .pax
file. This information can be processed by an extended version of \includegraphics
which reinserts the links at the correct position. However, the package is considered experimental and only works with pdfLaTeX
.
This is how to use pax
:
- Download and install the package from CTAN.
- Run
pdfannotextractor.pl --install
. This downloads and installs PDFBox
, a Java library necessary for using pax
.
- Now you can run
pdfannotextractor.pl <filename.pdf>
in order to read the links from any given PDF file and write them to filename.pax
.
- In your LaTeX document, invoke
\usepackage{pax}
. This extends \includegraphics
in order to read and process the auxiliary .pax
file.
Regarding the cropping of the PDF file with Ghostscript: In my experiments, this seemed to confuse pax
, resulting in wrong positions of the hyperlinks. So it's probably best to call wkhtmltopdf
with
wkhtmltopdf -B 0mm -L 0mm -R 0mm -T 0mm
in order to not create any margin from the start.
This is my working test case (using the site https://tex.stackexchange.com/about):
Creation of the PDF and the annotation file:
wkhtmltopdf -B 0mm -L 0mm -R 0mm -T 0mm https://tex.stackexchange.com/about screenshot.pdf
pdfannotextractor.pl screenshot.pdf
LaTeX source code
\documentclass{article}
\usepackage[margin=0mm]{geometry}
\usepackage{pax}
% Visible squares for demonstration purposes, can be removed without harm
% (change \iftrue to \iffalse or remove the following lines altogether)
\iftrue
\usepackage{hyperref}
\hypersetup{
filebordercolor={1 1 0},
}
\fi
\begin{document}
\includegraphics[scale=0.9]{screenshot}
\end{document}
Result:
(The cyan boxes are there to prove that hyperlinks work, and can be removed without consequences.)
As far as the yellow LyX notes are completely lost in the generated LaTeX source (i.e, the .tex
file), your goal seem impossible without touching the LyX's guts or deal with the original .lyx
file. An easier starting point could be use the black comments for this purpose.
With this approach, you only have to transform a \begin{comment} note \end{comment}
of the verbatim
package in a \pdfcomment{note}
of the pdfcomment
package.
How-to:
1) Go to Document > Configuration... > LaTex preamble
2) Paste the following lines:
% Change comments in PDF notes
\usepackage{pdfcomment}
\usepackage{environ}
\RenewEnviron{comment}{\pdfcomment{\BODY}}
3) Go to Insert > Note > Comment) and write some text.
This left a comment
environment in the .tex
file. Example of the ouput in LyX:
(you will see "Comment" instead of "Comentario" in a english OS, obviously...)
3) Go to File > Export > PDF(pdflatex)
4) Open the PDF open in Acrobat Reader:
LyX-generated LaTeX source:
%% LyX 2.0.5.1 created this file. For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{verbatim}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
%add this in Lyx Preamble
\usepackage{pdfcomment}
\usepackage{environ}
\RenewEnviron{comment}{\pdfcomment{\BODY}}
\makeatother
\usepackage{babel}
\begin{document}
Plain text %
\begin{comment}
This is a note (comment)
\end{comment}
\end{document}
Minimal working example in plain LaTeX
\documentclass{article}
\usepackage{verbatim}
\usepackage{pdfcomment}
\usepackage{environ}
\RenewEnviron{comment}{\pdfcomment{\BODY}}
\begin{document}
Plain text
\begin{comment}
This is a note (comment)
\end{comment}
\end{document}
Best Answer
According to the LyX FAQ, you have to enable
hyperref
support in the document settings under PDF properties.