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

How to write JavaScript that launches immediately when user opens PDF file

Community Beginner ,
Oct 14, 2021 Oct 14, 2021

We want to introduce new features with JS to our customers in our bills, offers, etc made in .pdf to leave feedback and use other interactive features.

I m new with both JS and Acrobat Pro too.

For testing purpose for myself and for now I want to acieve to get an alert (message box) immediately after opening my .pdf file.

Any advice how to do it in JavaScript Editor is welcome.

TOPICS
Create PDFs , How to , JavaScript
2.1K
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
1 ACCEPTED SOLUTION
Community Expert ,
Oct 14, 2021 Oct 14, 2021

Try this:

app.alert("Hello!");

 

Capture_103.pngexpand image

 

"init" is a sample, you can use every name you like (using the web syntax).


PDF Acrobatic, InDesigner & Photoshoptographer

View solution in original post

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 ,
Oct 14, 2021 Oct 14, 2021

You can use the document open event for this.

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 ,
Oct 14, 2021 Oct 14, 2021

Thanks for quick answer.

I tried:

 

function test()
{
    document.addEventListener ('open',() => {
    alert('Hello');
});
}

in Javascript Editor but didnt work. Doesnt work with load event too.

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 ,
Oct 14, 2021 Oct 14, 2021

You can't use web browser javascript in Acrobat.

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 ,
Oct 14, 2021 Oct 14, 2021

Can you please correct below code for Acrobat for the purpose I wrote in my post?

 

//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------

//<Document-Level>
//<ACRO_source>test</ACRO_source>
//<ACRO_script>
/*********** belongs to: Document-Level:test ***********/
function test()
{
    document.addEventListener ('open',() => {
    alert ('Hello');
});
}
//</ACRO_script>
//</Document-Level>

 

 

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 ,
Oct 14, 2021 Oct 14, 2021

Try this:

app.alert("Hello!");

 

Capture_103.pngexpand image

 

"init" is a sample, you can use every name you like (using the web syntax).


PDF Acrobatic, InDesigner & Photoshoptographer
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 ,
Oct 14, 2021 Oct 14, 2021

Thanks bro!

that does the job.

function test()
{
    app.alert("Hello");
}
test();

After the function definition you ve to call it, so it works, but I got the answer.

Thanks again

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 ,
Oct 14, 2021 Oct 14, 2021
LATEST

Sorry, comments cannot be edited in this community...

You are right, if you dont define function, of course you dont have to call it. Sorry for confusion

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