[Tex/LaTex] PDF Layers (OCG) using xelatex

ocgpdfxetex

I am switching from pdflatex to xelatex and have trouble finding an alternative on how to do layers in the pdf. So far I have been using ocg.sty to separate relevant content from eye-candy content (background images, illustrations), so the reader can hide the latter for printing.

However, ocg.sty does not work with xelatex due lack of pdfobj support. The newer CTAN ocgtools package also has this issue and will work with pdflatex, but not xelatex.

Is there currently any way to produce ocg layers using xelatex? Or is there another approach for hiding/disabling some parts (not necessarily only images) in a PDF before printing?

Best Answer

In principle, it is possible. However, someone has to add the support for xetex into the packages. You may try to compile the following text with xetex. The second line is in optional OCG and can be switched off. Stolen from here.

%create new OCG
\special{pdf:obj @ocg <</Type/OCG /Name (myocg)>>}

%register it and configure its default behaviour
\special{pdf:put @catalog <<
  /OCProperties <<
    /OCGs [@ocg]
    /D <</BaseState/ON /Order [@ocg]>>
  >>
>>}

This is a minimal OCG example.

%add the OCG to the resources of the current page object
\special{pdf: put @resources <<
  /Properties <<
    %this maps the name ``oc1'' to the OCG object
    /oc1 @ocg
  >>
>>}

%mark someting of the page content as optional
\special{pdf: content /OC /oc1 BDC} %optional content follows

This text is optional.

\special{pdf: content EMC} %end of optional content

\bye
Related Question