Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Can an HTML event trigger a PDF JavaScript event with HostContainer?

Community Beginner ,
Jan 22, 2025 Jan 22, 2025

I have a PDF in an HTML OBJECT container and I want to have an HTML onmouseover event send a string to the PDF's JavaScript that will show the layer specified by the string and then hide that layer on an HTML onmouseout event. So, my question is is HostContainer the object to use to do this, accept an HTML message and then pass the string to the PDF's JavaScript?

TOPICS
Acrobat SDK and JavaScript , Windows
304
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 24, 2025 Jan 24, 2025

To define a document global function, you need a document level script.

https://www.pdfscripting.com/public/Document-Level-Scripts.cfm

 

 

Translate
Community Expert ,
Jan 22, 2025 Jan 22, 2025

Communication between the browser host container and the PDF is through the HostContainer Object.  This object posts and receives messages to message handlers that are setup on both sides. See the reference:

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#hostcontainer-p...

 

However, as far as I know, this functionality hasn't been supported in many years, i.e., the brower side host container isn't supported. 

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 22, 2025 Jan 22, 2025

So, the brower side host container is no longer supported. Great. 

 

It seems that I need to use a form. I assume that I can add text fields to my map PDF to which I can attach a:

  • mouse enter event to show a layer
  • mouse exit event to hide a layer
  • mouse click event to go to a detail page

I've read:

While neither discusses show/hide layers, JavaScript should provide that function with Text fields, correct? Or, do I need to use another form field?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2025 Jan 22, 2025

The HostContainer support was very brief. It was introduce in Acrobat 7. Shortly after this the internet started getting dangerous, and all kinds of things were getting hacked, and then support dissappeared. 

 

So, here's an article on scripting with layers:

https://acrobatusers.com/tutorials/create_use_layers/

 

And here's more info on scripting form fields:

https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 24, 2025 Jan 24, 2025

I do have one more question in order to get started. I've read your Where does JavaScript Go article (https://acrobatusers.com/tutorials/so-where-does-javascript-go-in-acrobat/) and I see where to add a JavaScript routine in tht text field properties window, but can't figure out how I'd add a JavaScript function that is used by all scripts, such as:

function find(ocgname){
    var layers = this.getOCGs();
    for(var i=0; i < layers.length; i++) { 
        if(layers[i].name == ocgname) return layers[i];
    }
    return null;
}

that would be used by all scripts entered in a text field's properties window, each text field's script would pass its specific argument to find(). How would function scripts be added to a PDF to be called by each function? Or, is the intent of Adobe to NOT have universally available functions, treat each text field as a stand alone field?

 

Can you point me to an article about that? I'll keep searching in the meantime.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2025 Jan 24, 2025

To define a document global function, you need a document level script.

https://www.pdfscripting.com/public/Document-Level-Scripts.cfm

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 24, 2025 Jan 24, 2025
LATEST

Thank you very much for that link!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines