Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Optional Content Groups #92

Closed
snorfalorpagus opened this issue Apr 22, 2014 · 9 comments
Closed

Support for Optional Content Groups #92

snorfalorpagus opened this issue Apr 22, 2014 · 9 comments
Labels
is-feature A feature request PdfReader The PdfReader component is affected

Comments

@snorfalorpagus
Copy link
Contributor

PyPDF2 does not currently have any support for Optional Content Groups (OCGs). When merging multiple documents into a single document the layers are effectively
flattened and functionality is lost.

http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf
4.10.2 Making Graphical Content Optional

@mstamy2
Copy link
Collaborator

mstamy2 commented Apr 22, 2014

Thanks - We definitely need support for layered PDFs to display correctly (and possibly support for adding/removing layers?

@snorfalorpagus
Copy link
Contributor Author

It looks like the OCG settings are stored in the 'OCProperties' dictionary in 'Root' - see dump below.

The problem here is that it uses IndirectObjects, which don't necessarily have the same ID in the input PDF to the output PDF when the page is appended. How do we get the ID of the corresponding new object in the output PDF?

{'/OCProperties': {'/D': {'/ListMode': '/VisiblePages',
                          '/Locked': [IndirectObject(8, 0),
                                      IndirectObject(9, 0)],
                          '/OFF': [IndirectObject(11, 0),
                                   IndirectObject(12, 0)],
                          '/Order': [IndirectObject(1, 0),
                                     [IndirectObject(2, 0),
                                      IndirectObject(3, 0),
                                      IndirectObject(4, 0)],
                                     [u'PDF Drawing Layer',
                                      IndirectObject(5, 0),
                                      IndirectObject(6, 0),
                                      IndirectObject(7, 0),
                                      IndirectObject(8, 0),
                                      IndirectObject(9, 0)],
                                     IndirectObject(10, 0),
                                     [IndirectObject(11, 0),
                                      IndirectObject(12, 0),
                                      IndirectObject(13, 0)]],
                          '/RBGroups': [[IndirectObject(11, 0),
                                         IndirectObject(12, 0),
                                         IndirectObject(13, 0)]]},
                   '/OCGs': [IndirectObject(7, 0),
                             IndirectObject(3, 0),
                             IndirectObject(9, 0),
                             IndirectObject(11, 0),
                             IndirectObject(1, 0),
                             IndirectObject(8, 0),
                             IndirectObject(6, 0),
                             IndirectObject(4, 0),
                             IndirectObject(12, 0),
                             IndirectObject(2, 0),
                             IndirectObject(10, 0),
                             IndirectObject(13, 0),
                             IndirectObject(5, 0)]},
 '/OpenAction': {'/D': [IndirectObject(25, 0), '/Fit'], '/S': '/GoTo'},
 '/PageLayout': '/SinglePage',
 '/PageMode': '/UseOC',
 '/Pages': IndirectObject(24, 0),
 '/Type': '/Catalog',
 '/ViewerPreferences': {'/NonFullScreenPageMode': '/UseNone'}}

@snorfalorpagus
Copy link
Contributor Author

Screenshot below of the PDF in Acrobat Reader (on Linux) that was used for the dump above.

layer_pdf

@emmama1234
Copy link

How did you get the dumped structure?

@snorfalorpagus
Copy link
Contributor Author

snorfalorpagus commented Jul 28, 2015

@emmama1234 I've got the dumped structure like this:

from PyPDF2 import PdfFileReader
reader = PdfFileReader(file('test.pdf','rb'))
reader.trailer['/Root']['/OCProperties']

@emmama1234
Copy link

@snorfalorpagus did you find any way to add/remove OCG layers to multiple pages Pdf with PyPDF2?

@snorfalorpagus
Copy link
Contributor Author

I didn't get any further than viewing the data as posted above. :(

@emmama1234
Copy link

@snorfalorpagus Thanks! i'll take a look at it to see if i can find something

@py-pdf py-pdf deleted a comment from claird Apr 16, 2022
@MartinThoma MartinThoma added is-feature A feature request and removed Feature labels Jun 22, 2022
@py-pdf py-pdf deleted a comment from emmama1234 Jul 10, 2022
@MartinThoma MartinThoma added the PdfReader The PdfReader component is affected label Jul 10, 2022
@MartinThoma
Copy link
Member

As this feature request didn't receive an update for a long time, I'm closing it.

I'm linking it in #1181 so that we don't forget about it. Please feel free to add more information (PDFs that use it; other projects that implement it; explanations how it would improve PyPDF2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is-feature A feature request PdfReader The PdfReader component is affected
Projects
None yet
Development

No branches or pull requests

4 participants