How to open PDF from web using JavaScript?
Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan
-
- User
- Posts: 7
- Joined: Thu Jun 10, 2021 4:47 am
How to open PDF from web using JavaScript?
Hi,
I've been playing with the JavaScript console, and love it. I've been successfully able to manipulate pages, deleting, inserting and duplicating pages as needed – powerful stuff.
I'm banging my head against the wall trying to do something super basic, though: how to open a PDF file in PXE from the web using JavaScript?
I can open a local PDF without problem, using app.openDoc. I can open a web PDF using app.launchURL, but that opens in the default browser, not PXE. I figure I ought to be able to open a web PDF using Doc.getURL, which should append the pages from the web PDF file to the currently open PDF in PXE, but the following doesn't seem to do anything:
this.getURL("https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf");
When run from the console it returns "undefined", which typically indicates success. All my experimentation has been via the console, so I don't think I'm running into security/privilege issues.
So – how does one open a PDF in PXE from the web, using JavaScript?
Thanks!
-jim.
I've been playing with the JavaScript console, and love it. I've been successfully able to manipulate pages, deleting, inserting and duplicating pages as needed – powerful stuff.
I'm banging my head against the wall trying to do something super basic, though: how to open a PDF file in PXE from the web using JavaScript?
I can open a local PDF without problem, using app.openDoc. I can open a web PDF using app.launchURL, but that opens in the default browser, not PXE. I figure I ought to be able to open a web PDF using Doc.getURL, which should append the pages from the web PDF file to the currently open PDF in PXE, but the following doesn't seem to do anything:
this.getURL("https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf");
When run from the console it returns "undefined", which typically indicates success. All my experimentation has been via the console, so I don't think I'm running into security/privilege issues.
So – how does one open a PDF in PXE from the web, using JavaScript?
Thanks!
-jim.
-
- User
- Posts: 2395
- Joined: Wed Jan 18, 2006 12:10 pm
Re: How to open PDF from web using JavaScript?
Just out of curiosity I have run some tests.
The following syntax seems to work:
app.openDoc("https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf");
but it takes a while before the document opens (+/- 25 seconds). No idea why.
The following syntax seems to work:
app.openDoc("https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf");
but it takes a while before the document opens (+/- 25 seconds). No idea why.
-
- Site Admin
- Posts: 8613
- Joined: Wed Jan 03, 2018 6:52 pm
Re: How to open PDF from web using JavaScript?
Hi, Willy Van Nuffel
Thanks for providing the solution for PiXiE here, I tested what you reported about the delay, and could not reproduce it. In my tests, using that JS, it took under 3 seconds to open the file here.
Kind regards,
Thanks for providing the solution for PiXiE here, I tested what you reported about the delay, and could not reproduce it. In my tests, using that JS, it took under 3 seconds to open the file here.
Kind regards,
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Tracker Software Products (Canada) LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
-
- User
- Posts: 7
- Joined: Thu Jun 10, 2021 4:47 am
Re: How to open PDF from web using JavaScript?
And works for me, too! Delay is only a few seconds.
For some reason I thought that openDoc was for local file system only – the API reference says the cPath parameter "target document must be accessible in the default file system", which I read as local. That along with getURL saying "This method roughly corresponds to the “open a web page” action" made me think one was for local file system, the other for web docs…
Regardless, I'm thrilled to have an answer. I knew there must be a simple solution! Thanks for finding it for me, Willy.
BTW, really impressed with this forum – active users helping each other out, and a lot of Tracker participation. Really great.
-jim.
For some reason I thought that openDoc was for local file system only – the API reference says the cPath parameter "target document must be accessible in the default file system", which I read as local. That along with getURL saying "This method roughly corresponds to the “open a web page” action" made me think one was for local file system, the other for web docs…
Regardless, I'm thrilled to have an answer. I knew there must be a simple solution! Thanks for finding it for me, Willy.
BTW, really impressed with this forum – active users helping each other out, and a lot of Tracker participation. Really great.
-jim.
-
- User
- Posts: 461
- Joined: Tue Sep 05, 2017 4:56 pm
Re: How to open PDF from web using JavaScript?
Hi All!
I get error message:
Am I missing something?
I get error message:
Code: Select all
Console:Exec:1: NotAllowedError: NotAllowedError: Security settings prevent access to this property or method.
App.openDoc:1:Console:Exec
It's impossible to lead us astray for we don't care even to choose the way.
PDF-XChange PRO, 10.1.1 (Build 381) / W7 SP1 x64
PDF-XChange PRO, 10.1.1 (Build 381) / W7 SP1 x64
-
- User
- Posts: 2395
- Joined: Wed Jan 18, 2006 12:10 pm
Re: How to open PDF from web using JavaScript?
1) Strange, but today (after a restart of my PC) the PDF from the above post opens immediately.
2) @ovg
The error message you have, seems to be bound to the following Security Option in PDF-XChange Editor:
"When document is trying to open a site"
NOTE: Even after "Apply" and "OK", PDF-XChange Editor needs to be restarted to make the changes to work.
Best regards.
Willy
2) @ovg
The error message you have, seems to be bound to the following Security Option in PDF-XChange Editor:
"When document is trying to open a site"
NOTE: Even after "Apply" and "OK", PDF-XChange Editor needs to be restarted to make the changes to work.
Best regards.
Willy
You do not have the required permissions to view the files attached to this post.
-
- User
- Posts: 461
- Joined: Tue Sep 05, 2017 4:56 pm
Re: How to open PDF from web using JavaScript?
2Willy Van Nuffel
Thanks, but it seems that in V 9.354.0 this doesn't work at all .... At least for me....
Thanks, but it seems that in V 9.354.0 this doesn't work at all .... At least for me....
You do not have the required permissions to view the files attached to this post.
It's impossible to lead us astray for we don't care even to choose the way.
PDF-XChange PRO, 10.1.1 (Build 381) / W7 SP1 x64
PDF-XChange PRO, 10.1.1 (Build 381) / W7 SP1 x64
-
- User
- Posts: 2395
- Joined: Wed Jan 18, 2006 12:10 pm
Re: How to open PDF from web using JavaScript?
Thanks for the reply.
So, I think we will have to ask for more information @Tracker Software Support.
Kind regards.
Willy.
So, I think we will have to ask for more information @Tracker Software Support.
Kind regards.
Willy.
-
- User
- Posts: 461
- Joined: Tue Sep 05, 2017 4:56 pm
Re: How to open PDF from web using JavaScript?
I think it's related to https://forum.pdf-xchange.com/viewtopic.php?f=62&t=36502&p=151055&hilit=print+all#p150625
It's impossible to lead us astray for we don't care even to choose the way.
PDF-XChange PRO, 10.1.1 (Build 381) / W7 SP1 x64
PDF-XChange PRO, 10.1.1 (Build 381) / W7 SP1 x64
-
- User
- Posts: 2395
- Joined: Wed Jan 18, 2006 12:10 pm
Re: How to open PDF from web using JavaScript?
Thanks for the information @Ovg, but I am also using build 354 and at my side it works with the given security option.
Like stated in the other topic, the JavaScript handling should still work from within the JavaScript Console.
I suppose the Mozilla JavaScript engine is incorporated in PDF-XChange Editor itself, so there is no external influence ?
Like stated in the other topic, the JavaScript handling should still work from within the JavaScript Console.
I suppose the Mozilla JavaScript engine is incorporated in PDF-XChange Editor itself, so there is no external influence ?
-
- User
- Posts: 461
- Joined: Tue Sep 05, 2017 4:56 pm
Re: How to open PDF from web using JavaScript?
May be OS/Bitness? What is your OS?
It's impossible to lead us astray for we don't care even to choose the way.
PDF-XChange PRO, 10.1.1 (Build 381) / W7 SP1 x64
PDF-XChange PRO, 10.1.1 (Build 381) / W7 SP1 x64
-
- User
- Posts: 2395
- Joined: Wed Jan 18, 2006 12:10 pm
Re: How to open PDF from web using JavaScript?
Windows 10 Home edition, version 20H2 - 32-bit.
-
- User
- Posts: 7
- Joined: Thu Jun 10, 2021 4:47 am
Re: How to open PDF from web using JavaScript?
Working for me with Windows 10 Enterprise 21H1 64-bit with PXE Plus v9.0.354.0.
-
- User
- Posts: 7
- Joined: Thu Jun 10, 2021 4:47 am
Re: How to open PDF from web using JavaScript?
Aha! Works for me, so long as no other PDFs are open in PXE. Does not work if other files are open first (except for dummy.pdf) – I get the same error as Ovg.
That explains why I passed over app.openDoc when I was searching for a way to open web PDFs – I must have tested it with other files open, then written it off when I got the error message.
That explains why I passed over app.openDoc when I was searching for a way to open web PDFs – I must have tested it with other files open, then written it off when I got the error message.
-
- User
- Posts: 7
- Joined: Thu Jun 10, 2021 4:47 am
Re: How to open PDF from web using JavaScript?
Hmm, only affected by previously opened files that were opened manually, e.g. via the PXE UI, or double clicking in Windows Explorer. Files that were opened programmatically (i.e. by previous app.openDoc calls) do not prevent future such calls. Weird.
-
- User
- Posts: 7
- Joined: Thu Jun 10, 2021 4:47 am
Re: How to open PDF from web using JavaScript?
If you have multiple files open in PXE, some which were opened manually and some programmatically, then app.openDoc will work so long as a programmatically-opened file is selected first. It fails if a manually-opened file has focus within PXE at time JS is run.
So:
So:
- No open files in PXE: app.openDoc works;
- Open files in PXE, and programmatically-opened file tab is selected: app.openDoc works;
- Open files in PXE, and manually-opened file tab is selected: app.openDoc fails.
Code: Select all
app.openDoc("https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf");
-
- Site Admin
- Posts: 3550
- Joined: Thu Jul 08, 2004 10:36 pm
- Location: Vancouver Island - Canada
Re: How to open PDF from web using JavaScript?
confirm, will be fixed in the next build.
The issue is caused not by documents opened programmatically, but by documents opened from URL.
The issue is caused not by documents opened programmatically, but by documents opened from URL.
Tracker Software (Project Director)
When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
-
- User
- Posts: 461
- Joined: Tue Sep 05, 2017 4:56 pm
Re: How to open PDF from web using JavaScript?
Yes, for local files working fine!
It's impossible to lead us astray for we don't care even to choose the way.
PDF-XChange PRO, 10.1.1 (Build 381) / W7 SP1 x64
PDF-XChange PRO, 10.1.1 (Build 381) / W7 SP1 x64
-
- User
- Posts: 7
- Joined: Thu Jun 10, 2021 4:47 am
Re: How to open PDF from web using JavaScript?
Cool, looking forward to 355.
-jim.
-jim.
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
-
- User
- Posts: 1
- Joined: Tue Aug 10, 2021 5:58 am
Re: How to open PDF from web using JavaScript?
js to your application, you'll need to execute the following steps: Download the code. Add the JavaScript code to instantiate the PDF. js library and pull the files.
Render PDFs on the browser using JavaScript
Should work cross-browser.
Should support modern(ish) platforms.
It shouldn't rely on a PDF add-in to be installed. https://vidmate-apk.in/home/ https://instasave.onl/
Render PDFs on the browser using JavaScript
Should work cross-browser.
Should support modern(ish) platforms.
It shouldn't rely on a PDF add-in to be installed. https://vidmate-apk.in/home/ https://instasave.onl/
Last edited by gonevid on Wed Aug 25, 2021 7:34 am, edited 1 time in total.
-
- User
- Posts: 461
- Joined: Tue Sep 05, 2017 4:56 pm
Re: How to open PDF from web using JavaScript?
Working fine in 9.1.356
It's impossible to lead us astray for we don't care even to choose the way.
PDF-XChange PRO, 10.1.1 (Build 381) / W7 SP1 x64
PDF-XChange PRO, 10.1.1 (Build 381) / W7 SP1 x64
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London