Can't use on localhost subdomain

Which product are you using?

PDF.js Express Viewer

PDF.js Express Version

Value
UI version ‘8.7.0’
Core version ‘8.7.5’
webviewer.min.js ‘8.7.5’
Build ‘Ny80LzIwMjR8MzMxOTBmNGM5YQ==’

Detailed description of issue
The portal won’t allow me to create a key for mysubdomain.localhost, which is what our development environments use. It says that localhost just works, but it doesn’t, and console says I must get a license key.

Expected behaviour
It should work on all subdomains of localhost.

Does your issue happen with every document, or just one?
Every one.

Link to document
Not applicable.

Code snippet
Not applicable.

Hi there,

You can use a valid key for localhost/dev environment, but it will be in demo mode:

Note that it is expected that actions from localhost will be watermarked/mangled:

Please see this forum post for additional details:

Best regards,
Kevin Kim

That didn’t work, unfortunately. I didn’t see the console message “Development environment detected.”

Could there be a bug that’s causing this?

For reference, this is what I see in the console on my domain (https://company.localhost/some-path).

image

The only two things that might be causing an issue is that I am running on HTTPS, and the PDF I am trying to load is a blob URL (shown as part of an upload process), though there is a related warning for that where it assumes the URL is for a PDF, so perhaps not that.

If I omit the license key, it does not detect that I am running a localhost environment, and insists that I must provide a key.

Hi there,

Are you using the pdf.js express viewer or the pdf.js express package? Note that the free version will need the pdf.js express viewer package. We recommend you to uninstall all traces of the package to make sure there are no conflicts between the 2 packages.

Best regards,
Kevin Kim

I am using the viewer package via NPM.

"@pdftron/pdfjs-express-viewer": "^8.7.5"

There are definitely no conflicts as this is the only package I have tried using.

Hi there,

Have you tried the method suggested here?

Best regards,
Kevin Kim

Please could you be more specific? There are a number of methods going on there, none of which look applicable to my use case. We cannot use different ports, and we cannot change to .local. None of these things should matter anyway. We also cannot use IPs.

We use app.subdomain.localhost on port 443. Why can the library not detect that I am running on localhost? And why can I not create a special license key for my localhost subdomain? The way I see it is that either of these processes should be happening, not none of them.

Some more information:

A request to https://auth.pdfjs.express/?key=MYKEY is made, and this comes back with an HTTP 200 OK response containing an encrypted value in the key field of the JSON payload.

After this, the library fetches the PDF data – in my case, it is a blob (before doing this, it does do a HEAD request, which fails because you cannot make such a request for a blob:.

After this, a POST request is made to https://pi.pdfjs.express/events, containing the following:

I note at this point that it does not send a license key in this request. This request returns a 200 OK response, with OK in the body.

The PDF does not display. There is a loading circle thingy in the middle and the rest of the viewer chrome is faded out.

I’d appreciate some assistance with this. Thanks in advance.

Hi there,

Have you tried using 127.0.0.1 as an alternative to localhost being the domain?

In addition, the request to https://pi.pdfjs.express/events is gathering tele-metrics, and isn’t used to check the license key.

If the PDF isn’t loading after making the correct request to the auth server, there may be something wrong with the PDF. Are you able to load this in the demo?

Is there any console error messages and any failed network requests?

In addition, there may be some errors in how your keys are setup, please see this forum post for more information:

As noted before, we cannot do this. We have different services running independently of one another, and they need to have a particular domain structure to function and, in the case of the primary frontend, share sessions with other subdomains.

No PDFs are working in my local environment.

No, except for the ones already noted above.

This appears to be related to watermarks, which isn’t my problem at all.

Your own documentation states that it will just work in localhost, but it doesn’t. So I tried to create a key to see if that would work, and it didn’t let me create the key. So I created a key for our production TLD, and that doesn’t work in localhost.

I find it really frustrating that I’m being given the run-around here. The way I see it: I have pointed out that your code is not correctly detecting my localhost environment. Regardless of whether or not there is a license key in the picture, it should just work in localhost environments. What could prevent this from happening?

2 Likes

We currently having the exact same issue.

1 Like

Hi all,

Similar to this forum post here:

If you are using a localhost domain, they will display a watermark and will not need a key.
If you are using a subdomain for localhost, you will need to change this via a similar method here:
It talks about running a web server with a name other than localhost: asp.net - How to configure web server to run with another name instead of ‘localhost’ - Stack Overflow

Best regards,
Kevin Kim

Again, I’m being given the runaround, and I don’t think you are reading my messages properly.

You say I will not need a key, but it is insisting that I provide one.

I don’t care about watermarks.

I just want it to render a PDF on app.subdomain.localhost.

If it can render on normal localhost without a key, why can it not render on any other form of localhost without a key?

If I had purchased one of your premium products, would this have happened?

If not, why not?

Apologies for the above,

But unfortunately, subdomains of localhost is not currently supported with pdf.js express.

We have also deprioritized our development resources on pdf.js to our sister product Apryse WebViewer: Apryse WebViewer Pricing | Flexible Plans for Powerful Document Viewing which will receive constant updates and support.

Best regards,
Kevin Kim