Page 1 of 2
How to use pdf.js on desktop/mobile to display a PDF
Posted: Tue Apr 12, 2022 6:47 pm
by Klaus
Hi all,
the subject says it all, I downloaded some of the variation of the above mentioned package, but could not make it work.
It even refuses to display the example PDF file included in the package and displays an error that exact that file is missing
with the complete and correct path to that namely file on my machine? I don't get it.
Any hint on what I have to do to make it work highly appreciated!
Thanks!
Best
Klaus
P.S.
The Mac can display PDF in the browser widget right out of hte box, but for Windows we need to include 170 MB (CEF browser stuff)
to our runtimes for the same (simple?) task.
Re: How to use pdf.js on desktop/mobile to disply a PDF
Posted: Tue Apr 12, 2022 6:48 pm
by Klaus
Re: How to use pdf.js on desktop/mobile to disply a PDF
Posted: Tue Apr 12, 2022 7:14 pm
by Klaus
I know that I will need to copy all these folders and their content to a writable place on the users machine.
But I have no idea what and where to change in which of these files to display a local PDF file.
Re: How to use pdf.js on desktop/mobile to disply a PDF
Posted: Tue Apr 12, 2022 10:29 pm
by stam
Klaus wrote: ↑Tue Apr 12, 2022 6:47 pm
P.S.
The Mac can display PDF in the browser widget right out of hte box, but for Windows we need to include 170 MB (CEF browser stuff)
to our runtimes for the same (simple?) task.
is that the case for the 'pro' PDF feature as well?
(I'll be devling into PDF stuff next month so just asking...)
Re: How to use pdf.js on desktop/mobile to disply a PDF
Posted: Tue Apr 12, 2022 10:40 pm
by stam
Also, you may want to look at the opensource XPDFReader :
http://www.xpdfreader.com/index.html
I've used it before to very successfully extract text from PDF files - it comes with a 'viewer' for win/linux which may be helpful if you don't need to absolutely embed the PDF. It also lets you export each page as JPG so if you wanted to could do this on the fly i guess to show the PDF as an image instead... it's got a huge number of features which i haven't really looked into so might be worth a look?
S.
Re: How to use pdf.js on desktop/mobile to disply a PDF
Posted: Wed Apr 13, 2022 9:00 am
by Klaus
Hi Stam,
stam wrote: ↑Tue Apr 12, 2022 10:29 pm
Klaus wrote: ↑Tue Apr 12, 2022 6:47 pm
P.S.
The Mac can display PDF in the browser widget right out of hte box, but for Windows we need to include 170 MB (CEF browser stuff)
to our runtimes for the same (simple?) task.
is that the case for the 'pro' PDF feature as well?
(I'll be devling into PDF stuff next month so just asking...)
no, the "Pro pack" contains a widget for all platform, so no need to include the 170 MB CEF browser stuff.
Best
Klaus
Re: How to use pdf.js on desktop/mobile to disply a PDF
Posted: Wed Apr 13, 2022 9:04 am
by Klaus
stam wrote: ↑Tue Apr 12, 2022 10:40 pm
Also, you may want to look at the opensource XPDFReader :
http://www.xpdfreader.com/index.html
I've used it before to very successfully extract text from PDF files - it comes with a 'viewer' for win/linux which may be helpful if you don't need to absolutely embed the PDF. It also lets you export each page as JPG so if you wanted to could do this on the fly i guess to show the PDF as an image instead... it's got a huge number of features which i haven't really looked into so might be worth a look?
S.
Thank you, but this is an external application, I just want to display a PDF file inside of my Livecode app.
Since the Windows "default" browser EDGE can display PDF files, I wonder why LC still "sticks" to the CEF stuff.
Maybe it is not as easy to wrap around their web engine as it may be on the Mac, but what do I know?!

Re: How to use pdf.js on desktop/mobile to display a PDF
Posted: Wed Apr 13, 2022 11:12 am
by Klaus
After some research on the net I found this:
...
Note: Due to browser security restrictions, PDF.js cannot open local PDFs using a file:// URL.
You will need to start a local web server or upload the files to your web server.
...
Well that explains why I cannot get it to work locally.
Oh my, what a hassle to simply display a PDF in LC on Windows...

Re: How to use pdf.js on desktop/mobile to display a PDF
Posted: Wed Apr 13, 2022 2:56 pm
by FourthWorld
Klaus wrote: ↑Wed Apr 13, 2022 11:12 am
After some research on the net I found this:
...
Note: Due to browser security restrictions, PDF.js cannot open local PDFs using a file:// URL.
You will need to start a local web server or upload the files to your web server.
...
Well that explains why I cannot get it to work locally.
Oh my, what a hassle to simply display a PDF in LC on Windows...
Does it work outside of LiveCode?
Re: How to use pdf.js on desktop/mobile to display a PDF
Posted: Wed Apr 13, 2022 3:56 pm
by Klaus
No idea, Richard, if it does, it does not help me.
In any case it works online, I've seen many examples of it.
Re: How to use pdf.js on desktop/mobile to display a PDF
Posted: Wed Apr 13, 2022 9:09 pm
by FourthWorld
The https library would let you "serve" the file to the browser widget from the same instance of LC. That lib is also used with Oath, for similar reasons.
Or if it works in other apps you could launch that as a sheet sort of helper app for those files, unless of course you're not just displaying them but also need to do some sort of processing on them.
Re: How to use pdf.js on desktop/mobile to display a PDF
Posted: Thu Apr 14, 2022 8:44 am
by Klaus
Ah, yes, thank you, worth to consider!
But I still have no idea where or how to pass the path to the PDF file to whatever file of pdf.js!?
Re: How to use pdf.js on desktop/mobile to display a PDF
Posted: Fri Apr 15, 2022 1:59 am
by FourthWorld
What does this do on your system?:
Code: Select all
launch url ("file:/path/to/my.pdf")
Re: How to use pdf.js on desktop/mobile to display a PDF
Posted: Fri Apr 15, 2022 9:00 am
by Klaus
Same as:
I launches "Preview" (macOS) with the PDF.
What are you trying to tell me, Richard?

Re: How to use pdf.js on desktop/mobile to display a PDF
Posted: Fri Apr 15, 2022 10:49 am
by FourthWorld
"Or if it works in other apps you could launch that as a sheet sort of helper app for those files, unless of course you're not just displaying them but also need to do some sort of processing on them."