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

Javascript to Open PDF in browser

New Here ,
Dec 09, 2020 Dec 09, 2020

As soon as I open this PDF, i want the file to open in the browser. What Javascript code can i use?

TOPICS
Edit and convert PDFs , How to , JavaScript
2.9K
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
2 ACCEPTED SOLUTIONS
Community Expert ,
Dec 09, 2020 Dec 09, 2020

First, set your default web browser in your system. Once you've done that open the JavaScript tool, and create a document level function with this line of code:

 

 

function openWebPage() {

app.launchURL("https://community.adobe.com", true);

}

 

 

In my example above, I created a function named "openWebPage".

 

Then call the function from a text field as a custom format script.

 

To do so open the "Prepare Form" tool, right-click on the text field and select "Properties" from the context menu. Go to the "Format" tab and choose from the provided dropdown menu "Custom".

 

Place this line of code in the "Custom Format Script" section :

 

 

openWebPage();

 

 

Last, set the text field as hidden and/or readonly.

 

This will launch your hardcoded URL every time you open this document using the app.launchURL() method.

 

I am pretty sure there are other ways to accomplish this via JavaScript scripting, but in my case, I found out that calling the function as a custom format script doesn't interfere with other field object in your PDF document when you continue to work in the PDF document. Such would be the case if you place the script as custom calculation script, which will continuously iterate or loop itself every time you change something in other field objects.

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 ,
Dec 10, 2020 Dec 10, 2020
LATEST

Do you mean the PDF file itself? Unless it's hosted online, and you know the URL for it (in which case use the solution provided by ls_rbls above), you can't do that.

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 ,
Dec 09, 2020 Dec 09, 2020

First, set your default web browser in your system. Once you've done that open the JavaScript tool, and create a document level function with this line of code:

 

 

function openWebPage() {

app.launchURL("https://community.adobe.com", true);

}

 

 

In my example above, I created a function named "openWebPage".

 

Then call the function from a text field as a custom format script.

 

To do so open the "Prepare Form" tool, right-click on the text field and select "Properties" from the context menu. Go to the "Format" tab and choose from the provided dropdown menu "Custom".

 

Place this line of code in the "Custom Format Script" section :

 

 

openWebPage();

 

 

Last, set the text field as hidden and/or readonly.

 

This will launch your hardcoded URL every time you open this document using the app.launchURL() method.

 

I am pretty sure there are other ways to accomplish this via JavaScript scripting, but in my case, I found out that calling the function as a custom format script doesn't interfere with other field object in your PDF document when you continue to work in the PDF document. Such would be the case if you place the script as custom calculation script, which will continuously iterate or loop itself every time you change something in other field objects.

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 ,
Dec 10, 2020 Dec 10, 2020
LATEST

Do you mean the PDF file itself? Unless it's hosted online, and you know the URL for it (in which case use the solution provided by ls_rbls above), you can't do that.

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