Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 387
Boldewyn Avatar asked May 25 '10 12:05

Boldewyn


People also ask

How do I hide text fields in a PDF?

To do this, right click on the button, go to Properties, then to the Actions tab. Select the trigger of Mouse Enter and the Action Show/Hide Field. Click the Add button and select the appropriate text field to hide and then click OK.

How do I hide properties in PDF?

If you right click and choose "properties" on the . pdf, then choose the "details" tab there is an option to "Remove Properties and Personal Information". You can choose what to remove, either some or all of the properties.

How do you hide an element in JavaScript?

Style display property is used to hide and show the content of HTML DOM by accessing the DOM element using JavaScript/jQuery. To hide an element, set the style display property to “none”.

What is hide () in JavaScript?

The hide() method hides the selected elements. Tip: This is similar to the CSS property display:none. Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: To show hidden elements, look at the show() method.


1 Answers

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).

like image 112
Robusto Avatar answered Sep 29 '22 17:09

Robusto