Even though viewerlayer layers are viewed independently they are typeset together. Content is positioned as though all layers are visible, and surrounding text doesn't shift according to the visibility of the layer.
\defineviewerlayer [print] [state=stop,printable=yes]
\starttext
\rightaligned{First flush-right sentence\viewerlayer[print]{... or is it}}
\rightaligned{Second flush-right sentence}
\stoptext
When this prints both sentences appear equally aligned to each other and the right edge. When viewed, the first sentence is aligned left of the second as its position is determined by the subsequent viewerlayer content even though that layer is hidden. To solve this you need to typeset all the affected content twice, assign each to one of two exclusive layers (i.e. print only vs view only), and then overlap these layers:
\defineviewerlayer [print] [state=stop,printable=yes]
\defineviewerlayer [view] [state=start,printable=no]
\starttext
\rightaligned{\viewerlayer[view]{First flush-right sentence}\llap{\viewerlayer[print]{First flush-right sentence... or is it}}}
\rightaligned{Second flush-right sentence}
\stoptext
This, however, is where you start to encounter bugs. The following examples demonstrate problems ConTeXt 2018.12.18 has when typesetting documents with multiple viewerlayers. Primarily the layers do not seem properly closed, so that the layer subsumes all subsequent content. Documents tested in Adobe Reader 11.
When \showallmakeup is enabled, all content after \viewerlayer[print] belongs to that layer:
\defineviewerlayer[print][state=stop,printable=yes,]
\showallmakeup
\starttext
\viewerlayer[print]{One} more.
\samplefile{knuth}
\stoptext
The same problem as above, demonstrated with \start...stopviewerlayer rather than \viewerlayer:
\defineviewerlayer[print][state=stop,printable=yes,]
\showallmakeup
\starttext
\startviewerlayer[print]
And then:
\stopviewerlayer
\samplefile{knuth}
\stoptext
Rather than two independent layers, the print layer (along with other content) belongs to the view layer. So hiding the view layer hides all content in this document:
- [view]
- first
\samplefile{knuth}
- [print]
\defineviewerlayer[print][state=stop,printable=yes,]
\defineviewerlayer[view][state=start,printable=no,]
\starttext
\startviewerlayer[view]{first}
\samplefile{knuth}
\startviewerlayer[print]{second}
\stoptext
Nevermind, I forgot to close the blocks with \stopviewerlayer.
Additionally ConTeXt creates PDFs whose print-only layers are ignored by the ghostscript and poppler engines, even though those engines support such features. See comments to the accepted answer.
If you don't need such involved typesetting you might be better off using link annotations. See comments to the question:
Keep in mind that link annotations aren't markup annotations and so
don't display the "Contents" entry. Therefore they can only be used to
supplement standard page content (i.e. the URI, which will be always
displayed, whether print or screen) by overlaying additional content
as specified by the Border, BS, BE, AP, and AS entries... [as well as
the link action].
Here are the (visible) link annotation features ConTeXt supports, per lpdf-ano.lua. For more information see section 8.4, Annotations, of the Adobe PDF 1.7 specification, also mentioned in the comments.
/Border
ConTeXt only supports the PDF 1.0 fields. This is set to {0,0,0} if references.border isn't used; otherwise {0,0,0.5}. Can't be configured by the user.
horizontal corner radius (PDF 1.0)
vertical corder radius (PDF 1.0)
border width (PDF 1.0)
dash array (PDF 1.1)
/C (color)
This is the field set by references.border. ConTeXt only supports the three-entry version, DeviceRGB. You can use color names like "green" because of a ConTeXt-specific conversion.
/H (highlight; specific to link annotations)
Set to N, no highlighting, if actions.highlight is False. This is what you usually see. Otherwise ConTeXt leaves this field empty and per the PDF specifications it defaults to I, invert - invert the contents of the annotation rectangle. I'm not sure how to set actions.highlight.
ConTeXt does not support or set the newer "Border Style" (BS, PDF 1.2), "Border Effect" (BE, PDF 1.5), Appearance (AP, PDF 1.2), or Appearance State (AS, PDF 1.2) fields.
The /F entry is a bitfield representing various flags. For link annotations ConTeXt appears to set /F to 4, or 0b100. This enables only the Print field, and should force the link annotation border to print when the page is printed for PDF/A compatibility. This doesn't happen - when printed the link annotation border is hidden - and I'm not sure why.
references.borderuse - can I hook into that? Also did a quick search for[context] + [ocg]|[hyperref]|[links]|[printing]and I don't think there are any other niche approaches. – user19087 Dec 21 '18 at 03:21references.bordermechanism just uses the/Borderfield for/Linkannotations. That is a different approach from OCG. You can find more about that in the Adobe PDF specification. – Henri Menke Dec 21 '18 at 03:51viewerlayermechanism make use of OCG? – user19087 Dec 21 '18 at 18:25