mirror of
https://github.com/Llewellynvdm/pdflayers.git
synced 2024-11-28 14:26:30 +00:00
Avoid accessing keys in /Usage
Shouldn't have any issues with excpetions anymore at least. Need to read the PDF reference manual properly to see if this is the right thing to do... Fixes #2
This commit is contained in:
parent
79bbdaab05
commit
26e1f6a543
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