1
0
mirror of https://github.com/Llewellynvdm/pdflayers.git synced 2024-11-21 11:25:09 +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:
Simon Segerblom Rex 2019-05-16 22:19:36 +02:00
parent 79bbdaab05
commit 26e1f6a543

View File

@ -31,14 +31,12 @@ def set_layer_visibility(pdf, layers_to_show):
sys.exit(1)
ocgs_on = []
ocgs_off = []
for ocg in ocgs:
if ocg.Name in layers_to_show:
logging.info("Layer %s will be visible.", ocg.Name)
ocgs_on.append(ocg)
else:
logging.info("Layer %s will be hidden.", ocg.Name)
ocgs_off.append(ocg)
ocgs_config = pikepdf.Dictionary(
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):
# TODO: Set PrintState and ExportState too..? Exception+ handling...
# Check PDF reference. Maybe better to just delete ViewState..?
for ocg in ocgs_on:
ocg.Usage.View.ViewState = pikepdf.Name('/ON')
for ocg in ocgs_off:
ocg.Usage.View.ViewState = pikepdf.Name('/OFF')
for ocg in ocgs:
if '/View' in ocg.Usage:
del ocg.Usage.View
if '/Print' in ocg.Usage:
del ocg.Usage.Print
def main():