TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a document with a significant difference between its hard-copy and soft-copy.

Something like some text-boxes which should be printed bold and big in the hard copy but should be hidden (or as unobtrusive as possible) in the soft-copy version.

Is it possible in latex to incorporate materials in a pdf which are printed but not displayed?

share|improve this question
See tex.stackexchange.com/questions/4425/… for something for something related: you probably need to use 'optional content groups'. – Joseph Wright Sep 18 '12 at 18:26
Just to make sure: soft-copy = screen, hard-copy = printer? – yo' Sep 26 '12 at 6:40
@tohecz yes, wikipedia defines soft-copy as "the unprinted digital document file" – behzad.nouri Sep 26 '12 at 12:45
up vote 26 down vote accepted


As Martin Schröder pointed out, the ocg-p package now supports print-only content out of the box:



This text is always visible.

\begin{ocg}[printocg=always]{Hard copy}{printonly}{0}
This can only be seen if the document is printed.

This text is visible in both the soft and the hard copy.


Soft copy:

soft copy version, with "This can only be seen if the document is printed." not displayed

Hard copy:

hard copy version, with all the text displayed

Original answer

This is possible using optional content groups, which offer the properties ViewState and PrintState to control whether the group content should be visible in the soft or in the hard copy. The following proof of concept defines an environment printonly for things that should only be visible when printing the document.


% Create optional content group dictionary for print-only content
  /Name(Hard copy)%
\xdef\ocg@printonly{\the\pdflastobj\space 0 R}

% Add OCG to resource dictionary
\xdef\ocg@mapping{\the\pdflastobj\space 0 R}%
      /Properties \ocg@mapping%

% List of all optional content groups
\pdfobj reserveobjnum

% Create optional content usage dictionary
  /OCGs \the\ocg@listocgs\space0 R\space%
    /Order [\ocg@printonly\space]% if this line is removed, the OCG isn't shown in the layer toolbar of the viewer
    /OFF [\ocg@printonly\space]%
        /OCGs \the\ocg@listocgs\space0 R\space%
        /OCGs \the\ocg@listocgs\space0 R\space%
        /OCGs \the\ocg@listocgs\space0 R\space%

% List all OCGs
   \immediate\pdfobj useobjnum \ocg@listocgs {%

% "printonly" environment for content which should only be visible when the document is printed
  \pdfliteral{/OC /OCprintonly\space BDC}%

This text is always visible.

This can only be seen if the document is printed.

This text is visible in both the soft and the hard copy.

The code is heavily inspired by ocg.sty, which is distributed with Asymptote; some information about it can be found on texample.net. However it is not necessary for this example to have the package installed.

share|improve this answer
this was elegant and perfect, thank you – behzad.nouri Sep 26 '12 at 20:23
Update: The ocg-p package was released recently and improves on ocg. – Martin Schröder Dec 4 '12 at 20:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.