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:

always means that it is printed always, independent from the current visiblity state in the document, and never means that is never printed.

M(not)WE (compiled with pdfLaTeX)




Some text to be printed and viewed.

    This \textit{should be} visible on paper but not in a PDF viewer.\\
    Even if it contains \href{https://stackexchange.com}{hyperlinks}.

    This \textit{should be} visible in any PDF viewer but not on a printed paper.\\
    And the \href{https://stackexchange.com}{hyperlink} is clickable.

Some other stuff later.


So, basically it should work like CSS on web pages:

@media print {
  .web-only {
    display: none !important;


  1. In some PDF viewers (e.g. Evince, GIMP, Xournal), you have two blank lines with a colored box. enter image description here
  2. In Chromium, you only have blank lines without box (but it looks like the box is not supported). enter image description here
  3. In Firefox ESR, you just see everything. enter image description here
  4. 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.


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.

  • There is nothing you can do about PDF viewer specific problems other than complain to the provider. If it works for acrobat, your job is done. – John Kormylo Jul 16 at 13:06
  • Suppressing the blank space of hidden PDF Layers (OCGs) is not supported by the PDF standard. In contrast to HTML (mentioned in the question) the PDF format targets paginated content. Reflowing of content is not intended. – AlexG Jul 16 at 13:43
  • @AlexG So if I would really like to do this, I have to manually care about the reflowing stuff. Maybe with some "absolutely positioned" content? – Crsi Jul 16 at 14:30
  • 1
    You would have to compile to different PDFs, one for print and another one for viewing on-screen, with the paragraphs to be hidden commented out in the code (or based on a boolean you set in the code and using, e. g. \ifthenelse [pkg ifthen]). 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 at 15:06
  • Sadly, that was my exact use case. I know about such a possibility but I wanted to avoid two different documents. But shouldn't the ocg-p package 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 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.