I want to generate a ps file with layers. Ocg.sty does not support ps, so I want to write a simple example by myself to see if its possible. I took a pdf version from here and tried to change the commands to generate a ps version (code is appended here).
Well, the ps file is generated, but it seems to be corrupt. When I use ps2pdf there are errors reported. If the part with "AddToShipoutPicture" is removed ps2pdf reports no errors, so it seems the error is there to find. But maybe more is wrong. Maybe someone can help to make a simple working solution.
\documentclass{article}
\RequirePackage{eso-pic}
\RequirePackage{ifpdf}
\newcommand{\setupOCG}{
\special{ps: mark /_objdef {@ocg1} /type/dict /OBJ pdfmark}
\special{ps: mark {@ocg1} <</Type/OCG /Name (My first layer)>> /PUT pdfmark}
\special{ps: mark /_objdef {@ocg2} /type/dict /OBJ pdfmark}
\special{ps: mark {@ocg2} <</Type/OCG /Name (My second layer)>> /PUT pdfmark}
%register it and configure its default behaviour
%\special{ps: mark /_objdef {{@ocg1} {@ocg2}} /type/array /OBJ pdfmark}
\special{ps:mark {Catalog} <<
/OCProperties <<
/OCGs [{@ocg1} {@ocg2}]
/D <</BaseState/ON /Order [{@ocg1} {@ocg2}] /OFF [{@ocg1}] >> %first layer invisible
>>
>> /PUT pdfmark}
%add the OCG to the resources of the current page object
\AddToShipoutPicture{%
\special{ps:mark {Resources} <<
/Properties <<
%this maps the name to the OCG object
/oc1 {@ocg1} /oc2 {@ocg2}
>>
>> /PUT pdfmark}
}
}
\newcommand{\myocg}[2]{%
\special{ps: mark /OC /#1 /BDC pdfmark}#2\special{ps: mark /EMC pdfmark}% ok
%\special{ps: mark {ocgname\the\ocnum} <</OC {/@oc\the\ocnum}>> /PUT pdfmark}
}
\setupOCG
\begin{document}
\myocg{oc1}{I am NOT visible on the first layer.}
\myocg{oc2}{I am visible on the second layer.}
\end{document}
/OC ... BDC
-EMC
bracket around page content to be made optional must be inserted directly into the page stream. Ghostscript implements only a subset of pdfmarks,/BMC
and/EMC
not being amongst these (according togdevpdfm.c
in the Ghostscript sources).