Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
5  
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
3  
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

1 Answer 1

up vote 24 down vote accepted
+50

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

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.

\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.

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

Your Answer

 
discard

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.