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}
Best Answer
2nd Update
Package
ocgx2
, and Ghostscript releases >=9.15 allow for creating PDF layers (OCGs) withlatex
+dvips
+ps2pdf
.1st Update (obsolete)
The package combination
, together with the recent Ghostscript release 9.15 allows for creating PDF layers (OCGs) withocgx
+fixocgx
latex
+dvips
+ps2pdf
.In order to create layers in PDFs using OCGs (optional content groups), the content in the page stream that is to be made optional must be enclosed in a
/OC ... BDC
-EMC
bracket.Unfortunately, the/BDC
and/EMC
pdfmarks, which serve this purpose, are not supported by Ghostscript'sps2pdf
(according togdevpdfm.c
in the Ghostscript sources).Currently, only Adobe Distiller supports them.As of Ghostscript-9.15,
/BDC
and/EMC
pdfmarks and thus OCGs are fully supported.The corrected code example from the original posting using the low-level
pdfmark
implementation, to be run throughlatex
->dvips
->ps2pdf
or Distiller, reads: