For some reason, I wanted to insert a notice to users that they can click on certain elements in my PDF document. However, this notice should not appear when the document is printed on paper, as it's not clickable anymore.
I've used the ocg-p package as suggested here and here. I printed the document -- including the notice on paper. According to the package docs, the switch printocg=always should do the job:
alwaysmeans that it is printed always, independent from the current visiblity state in the document, andnevermeans that is never printed.
M(not)WE (compiled with pdfLaTeX)
\documentclass[a4paper]{article}
\usepackage{ocg-p}
\usepackage{hyperref}
\begin{document}
Some text to be printed and viewed.
\begin{ocg}[printocg=always,exportocg=never,listintoolbar=never]{Paper}{block0}{0}
This \textit{should be} visible on paper but not in a PDF viewer.\
Even if it contains \href{https://stackexchange.com}{hyperlinks}.
\end{ocg}
\begin{ocg}[printocg=never,exportocg=never,listintoolbar=always]{Digital}{block1}{1}
This \textit{should be} visible in any PDF viewer but not on a printed paper.\
And the \href{https://stackexchange.com}{hyperlink} is clickable.
\end{ocg}
Some other stuff later.
\end{document}
So, basically it should work like CSS on web pages:
@media print {
.web-only {
display: none !important;
}
}
Problems
- In some PDF viewers (e.g. Evince, GIMP, Xournal), you have two blank lines with a colored box.

- In Chromium, you only have blank lines without box (but it looks like the box is not supported).

- In Firefox ESR, you just see everything.

- But on a printed paper, you still see the second part for PDF viewers but not the part for printed documents. So, it's basically like for Chromium above.
Goal
The first box should not appear in a PDF viewer with support for PDF 1.5 (even no blank line!). The second box should not appear on a printed paper (but the first box should). Of course, the box for the hyperlinks can easily be disabled, but they prove that something else is not working.
\ifthenelse[pkgifthen]). You just cannot have a single PDF that has two different paginations (different distribution of typeset content [one with collapsed white space, another with unveiled text]). – AlexG Jul 16 '20 at 15:06ocg-ppackage allow me to this somehow (even if it's not reflowing as I suggested)? I thought it does so but it didn't in my tests. – Crsi Jul 16 '20 at 18:00ocg-pis outdated, useocgx2instead. It provides the same interface, but fixes a lot of bugs and has some neat additions. Different printing/screen-viewing Layers are currently supported only by Acrobat (Reader) and Chromium/Chrome PDF built-in viewers (of course still without text reflow).ocgx2ensures that hyperlink borders on hidden layers are invisible in the PDF viewer (Only Acrobat R and Chromium support this). – AlexG Jul 17 '20 at 07:15ocgx2package and see what I can do with it. My original use case seems to be impossible to achieve as long as most of the PDF viewers don't support this layers. Thanks so far. :) – Crsi Jul 17 '20 at 07:40