# Is it possible to distinguish between the soft copy and the hard copy of a pdf?

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?

-
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? –  tohecz 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

# Update

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

\documentclass{article}

\usepackage{ocg-p}

\begin{document}
This text is always visible.

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

This text is visible in both the soft and the hard copy.
\end{document}


## Output

### Hard copy:

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.

\documentclass{article}

\makeatletter
% Create optional content group dictionary for print-only content
\immediate\pdfobj{%
<<%
/Type/OCG%
/Name(Hard copy)%
/Usage<<%
/Print<<%
/PrintState/ON%
>>%
/View<<%
/ViewState/OFF%
>>%
>>%
>>}
\xdef\ocg@printonly{\the\pdflastobj\space 0 R}

% Add OCG to resource dictionary
\immediate\pdfobj{<</OCprintonly\space\ocg@printonly\space>>}
\xdef\ocg@mapping{\the\pdflastobj\space 0 R}%
\begingroup
\edef\x{\endgroup
\pdfpageresources{%
\the\pdfpageresources%
/Properties \ocg@mapping%
}%
}%
\x

% List of all optional content groups
\newcount\ocg@listocgs
\pdfobj reserveobjnum
\ocg@listocgs=\pdflastobj

% Create optional content usage dictionary
\pdfcatalog{%
/OCProperties<<%
/OCGs \the\ocg@listocgs\space0 R\space%
/D<<%
/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]%
/AS[%
<<%
/Event/View%
/OCGs \the\ocg@listocgs\space0 R\space%
/Category[/View]%
>>%
<<%
/Event/Print%
/OCGs \the\ocg@listocgs\space0 R\space%
/Category[/Print]%
>>%
<<%
/Event/Export%
/OCGs \the\ocg@listocgs\space0 R\space%
/Category[/Print]%
>>%
]%
>>%
>>}

% List all OCGs
\AtEndDocument{%
\immediate\pdfobj useobjnum \ocg@listocgs {%
[\ocg@printonly\space]%
}%
}%

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

\begin{document}
This text is always visible.

\begin{printonly}
This can only be seen if the document is printed.
\end{printonly}

This text is visible in both the soft and the hard copy.
\end{document}


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.

-
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