Q:
What I want to do is set the layers visible to false or true from the java code and re-save the new document .
Do you have a sample code to set the existing layers in PDF to visible true or false .
A:
In this case you want to call the following code.
Config init_cfg = doc.getOCGConfig();
/**/
for (i=0; i<sz; ++i)
{
Group ocg = new Group(ocgs.getAt(i));
ocg.setInitialState(init_cfg, false); // Will be off (not visible) NEXT time document is opened.
}
doc.save(...);