How to use pdf.js on desktop/mobile to display a PDF

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

How to use pdf.js on desktop/mobile to display a PDF

Post by Klaus » Tue Apr 12, 2022 6:47 pm

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.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to use pdf.js on desktop/mobile to disply a PDF

Post by Klaus » Tue Apr 12, 2022 6:48 pm

Forgot the URL to the package: https://github.com/mozilla/pdfjs-dist

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to use pdf.js on desktop/mobile to disply a PDF

Post by Klaus » Tue Apr 12, 2022 7:14 pm

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.

stam
Posts: 2682
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to use pdf.js on desktop/mobile to disply a PDF

Post by stam » 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...)

stam
Posts: 2682
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to use pdf.js on desktop/mobile to disply a PDF

Post by stam » 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.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to use pdf.js on desktop/mobile to disply a PDF

Post by Klaus » Wed Apr 13, 2022 9:00 am

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

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to use pdf.js on desktop/mobile to disply a PDF

Post by Klaus » Wed Apr 13, 2022 9:04 am

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?! ;-)

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to use pdf.js on desktop/mobile to display a PDF

Post by Klaus » 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... :(

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9837
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How to use pdf.js on desktop/mobile to display a PDF

Post by FourthWorld » Wed Apr 13, 2022 2:56 pm

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?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to use pdf.js on desktop/mobile to display a PDF

Post by Klaus » Wed Apr 13, 2022 3:56 pm

No idea, Richard, if it does, it does not help me. :D

In any case it works online, I've seen many examples of it.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9837
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How to use pdf.js on desktop/mobile to display a PDF

Post by FourthWorld » Wed Apr 13, 2022 9:09 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to use pdf.js on desktop/mobile to display a PDF

Post by Klaus » Thu Apr 14, 2022 8:44 am

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!?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9837
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How to use pdf.js on desktop/mobile to display a PDF

Post by FourthWorld » Fri Apr 15, 2022 1:59 am

What does this do on your system?:

Code: Select all

launch url ("file:/path/to/my.pdf")
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to use pdf.js on desktop/mobile to display a PDF

Post by Klaus » Fri Apr 15, 2022 9:00 am

Same as:

Code: Select all

launch url ("/path/to/my.pdf")
I launches "Preview" (macOS) with the PDF.

What are you trying to tell me, Richard? :D

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9837
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How to use pdf.js on desktop/mobile to display a PDF

Post by FourthWorld » Fri Apr 15, 2022 10:49 am

"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."
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”