Pdf.js: Feature request for the future: PDF layers

Created on 17 Jul 2011  ·  32Comments  ·  Source: mozilla/pdf.js

That is all.

The code looks really promising!

1-core 2-feature

Most helpful comment

Also expect this feature. Get layers info/showing layer/hiding layer.

All 32 comments

Not clear what this means. User is no longer active on Github. Can reopen if asked.

Let me Google that for You.

http://www.google.com/search?q=site:adobe.com+pdf+layer
http://www.google.com/search?q=site:adobe.com+pdf+%22optional+content+group%22

Standard since PDF specification 1.5.
http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf
section 8.11.3 "Making Graphical Content Optional"

Present in the UI of every Adobe PDF viewer for about a billion years now.
PDF layers usefully correspond to Illustrator (and similar) drawing program layers, to layers in GIS output, etc.

I'd be more "active" on github (and with other free software) if I enjoyed being slapped about more. (I've stopped using Firefox since the "upgrade" that killed off the truly useful http://code.google.com/p/firefox-mac-pdf/ plugin, which also lacked PDF layer support but otherwise worked very nicely indeed. Browser with no PDF viewing = useless. Safari at least manages that, for all its other crapitude.)

Hey there, didn't mean to insult you! We're doing an issue clean-up, so please forgive closing the issue on you.

And thanks for the detailed response - it definitely clarified what you meant.

Second-guessing terse user requests is a tough thing to do -- did the user mean "layers" at the UI/viewer level, or spec level (optional content), etc? I thought about inquiring here, but I wrongly assumed the odds of a response were low given that your only activity on Github was this comment (we're flattered! :)).

As I said, reopening is definitely an option - consider it done.

Thanks again.

I've uploaded a tiny file here that demonstrates broken rendering behavior for optional content groups and/or clipping paths (I'm not sure which thing is actually causing the bad behavior). If you try adding #textLayer=visible to the url, you can see that pdf.js is correctly finding and rendering the text, but is just not handling the rest of the rendering correctly.

(This particular PDF came about due to my working on this approach to rendering links in LaTeX using highlighting instead of boxes. The text is rendered into the current clipping path (7 Tr) rather than as normal text (0 Tr), then the clipping path is filled with the normal text color and, within an optional content group, filled again using the highlight color. IIRC, canvas.js#L982 already has some support for adding text to the clipping path, but it doesn't seem to be working here... As a result, this comment may not be 100% applicable to t his bug; feel free to redirect me to a more appropriate one if it exists ;-))

@blerner I think this issue is different than what you're asking about. Can you open a new issue with your comment above?

I'm looking for OCG functionality as well... is this on the plans? Can someone point me to the roadmap?

Any news on supporting layers? Would be incredible useful. Getting object names would be useful too (as in object and group names you can set in Illustrator)

I'm also interested in knowing when layers will be supported (specifically showing/hiding them).

There is no implementation for this yet and as far as I know no-one is working on this. If someone wants to work on this, feel free to create a pull request.

Files with OCGs:
http://ims.er.usgs.gov/images/USTopo/
(not all, only the huge ones)

Also expect this feature. Get layers info/showing layer/hiding layer.

Hi, also expect OCGs (layer) supports. Any schedule?
@timvandermeij The attachment is a pdf file exported from a architectural drawing containing hundreds of layers.
OCGs_demo.PDF

Currently this feature is not planned to be implemented. If someone wants to work on this, please let us know. If you can attach more example PDF files here, that would help to get people started and verify their work.

Here's a simple one:
PDFBOX-4103-OCG.pdf

an old example with transparency and ocgs, it'd be nice if the ocgs were selectable from within a browser/ page
_myChessboardv1.2_mockup_ImageArray_beta0.7 - public.pdf

I'm trying to identify some content from PDF.
I understand that I can't use the layers because they are not supported.
Is that corect ?
And is there another way ?

I'm also expect this feature. Get layers info/showing layer/hiding layer. This will be very usefull for Solidworks/Inventor usage.

Hi, I realize this issue is 8 years old, but would just like to add to the case that this would be a very useful feature to have. Perhaps things have changed in 2 years?

Please update the status if someone have worked on this issue and resolved it.

Thankyou

+1

+1

Please don't post individual "+1" comments, but give the original comment (https://github.com/mozilla/pdf.js/issues/269#issue-1238154) a thumbs up using GitHub's reaction mechanism. This prevents needless bumps on this issue and allows us to filter based on priority from the community.

Hallo, is there any update of the priority of this future request? :)
It seems like a lot of duplicated posts referencing the same issue, which might not be explained and shown in a good example in this post?

Nobody is currently working on this. If anyone wants to contribute, we're always happy to review pull requests.

The reason that this isn't implemented yet is most likely because it happens to be a fairly complicated subject, given the way that all of this is described in the PDF specification.
Ignoring a lot of the other specifics surrounding OCGs, section "8.11.3.1 General" of the specification states (note the second point):

When a piece of optional content in a PDF file is determined that it shall be hidden, the following occurs:

  • The content shall not be drawn.
  • Graphics state operations, such as setting the colour, transformation matrix, and clipping, shall still be applied. In addition, graphics state side effects that arise from drawing operators shall be applied; in particular, the current text position shall be updated even for text wrapped in optional content. In other words, graphics state parameters that persist past the end of a marked-content section shall be the same whether the optional content is visible or not.

Hey there, I've been trying to find a solution for this issue during the last week and was hoping someone can point me in the right direction.
For my use-case, it would not be necessary to toggle additional layers, I would simply need to hide them in my viewer.

So far I was able to identify the "hidden" layers inside document.js like this:

const hiddenLayers = this.xref.root._map.OCProperties._map.D.get("OFF");

But I could not draw the connection between the layers and the actual content that is rendered by pdf.js. So if anyone could give me a hint how to figure out which data is supposed to be hidden, I'd rellay love to put it to use.

@brendandahl how does the new API works? What is "Optional Content"? Can't we simply scan existing layers and hide them? Thanks!

What is "Optional Content"?

See https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G7.3858031

Can't we simply scan existing layers and hide them?

Unfortunately it's really quite difficult to understand what you're asking here.
Note: This functionality has not yet been integrated into the default viewer, however that'll be addressed in #12170.

Sorry, I meant detecting them and having the option to manipulate them (hide, remove, etc...)

I tried the feature and it works as expected, which is that instead of displaying all layers, it only displays the ones for viewing.

@brendandahl how does the new API works? What is "Optional Content"? Can't we simply scan existing layers and hide them? Thanks!

The full API still needs a bit more work, but you can pdfDoc.getOptionalContentConfig then iterate over the various optionalContentConfig.groups and set which ones you want to hide/show (optionalContentGroup.visible). Then pass that config into your call to render a page.

Useful links:
https://github.com/mozilla/pdf.js/blob/63e33a5895bb730ce0e6a65e4d0de12ed043b649/src/display/api.js#L779

https://github.com/mozilla/pdf.js/blob/63e33a5895bb730ce0e6a65e4d0de12ed043b649/src/display/optional_content_config.js#L25

https://github.com/mozilla/pdf.js/blob/63e33a5895bb730ce0e6a65e4d0de12ed043b649/src/display/api.js#L958

@brendandahl oh, this looks very interesting! I will give it a go. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Rob--W picture Rob--W  ·  34Comments

oddjobz picture oddjobz  ·  46Comments

collinanderson picture collinanderson  ·  29Comments

zhyi picture zhyi  ·  15Comments

ousia picture ousia  ·  29Comments