Show or hide elements in PDF via Javascript
In PDF files it is quite easy to interact with form fields via the Javascript API.
Is it possible to do this (specifically showing/hiding) to arbitrary elements on a page? Say, not just form fields, but text, graphical elements, embedded images... Is there an开发者_如何学运维 API to interact with those?
If yes, how do I identify an object?
Much of this depends on how "flattened" the document is. You can easily get access to links, page titles, icons, etc., but so far as I know you are not dealing with a document that parallels the HTML DOM, in which everything is able to be referenced in some way.
When a PDF is created, even from a layered application like Illustrator, parts of the document are merged (flattened) to keep the file size small. Each new presentation layer may contain what, to the original designer, may have been unrelated and/or discontiguous elements. Something up in the top right corner of a page may be merged with something seemingly unrelated in the bottom left.
It all depends on what settings the creator of the document used. Bear in mind that whoever created it may even have chosen not to convert items to PDF format at all — for example, it is allowable to import whole pages as single image files. Where elements are able to be addressed, you often have to loop through like items looking for a named element (like a page, or a title, or an icon).
You can't assume that the user is using the mediocre and insecure Adobe PDF plugin.
精彩评论