mirror of
https://github.com/Llewellynvdm/pdflayers.git
synced 2024-12-18 15:11:58 +00:00
Merge pull request #4 from SimonSegerblomRex/fix-2
Avoid accessing keys in /Usage
This commit is contained in:
commit
48f9730d0f
13
pdflayers.py
13
pdflayers.py
@ -31,14 +31,12 @@ def set_layer_visibility(pdf, layers_to_show):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
ocgs_on = []
|
ocgs_on = []
|
||||||
ocgs_off = []
|
|
||||||
for ocg in ocgs:
|
for ocg in ocgs:
|
||||||
if ocg.Name in layers_to_show:
|
if ocg.Name in layers_to_show:
|
||||||
logging.info("Layer %s will be visible.", ocg.Name)
|
logging.info("Layer %s will be visible.", ocg.Name)
|
||||||
ocgs_on.append(ocg)
|
ocgs_on.append(ocg)
|
||||||
else:
|
else:
|
||||||
logging.info("Layer %s will be hidden.", ocg.Name)
|
logging.info("Layer %s will be hidden.", ocg.Name)
|
||||||
ocgs_off.append(ocg)
|
|
||||||
|
|
||||||
ocgs_config = pikepdf.Dictionary(
|
ocgs_config = pikepdf.Dictionary(
|
||||||
BaseState=pikepdf.Name('/OFF'),
|
BaseState=pikepdf.Name('/OFF'),
|
||||||
@ -52,12 +50,11 @@ def set_layer_visibility(pdf, layers_to_show):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Needed for the PDF viwer in google-chrome (at least):
|
# Needed for the PDF viwer in google-chrome (at least):
|
||||||
# TODO: Set PrintState and ExportState too..? Exception+ handling...
|
for ocg in ocgs:
|
||||||
# Check PDF reference. Maybe better to just delete ViewState..?
|
if '/View' in ocg.Usage:
|
||||||
for ocg in ocgs_on:
|
del ocg.Usage.View
|
||||||
ocg.Usage.View.ViewState = pikepdf.Name('/ON')
|
if '/Print' in ocg.Usage:
|
||||||
for ocg in ocgs_off:
|
del ocg.Usage.Print
|
||||||
ocg.Usage.View.ViewState = pikepdf.Name('/OFF')
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
Loading…
Reference in New Issue
Block a user