A way to preview a local PDF in DC View SDK?

Community Beginner ,
May 29, 2020 May 29, 2020

Copy link to clipboard

Copied

I'm running into an issue where I cannot preview a local pdf.

I have tried:

 adobeDCView.previewFile(
       {
          content:   {location: {url: "file:///C:/my/sandbox/local_file.pdf"}},
          metaData: {fileName: "local_file.pdf"}
       }, {embedMode: "IN_LINE", showDownloadPDF: true, showPrintPDF: true});
    });

and

 adobeDCView.previewFile(
       {
          content:   {location: {url: "local_file.pdf"}},
          metaData: {fileName: "local_file.pdf"}
       }, {embedMode: "IN_LINE", showDownloadPDF: true, showPrintPDF: true});
    });

But I always just get a "File preview error".

 

In the Adobe View SDK repo, I did see the "Work with Local File" example .  But this is not what I'm looking for.  In the example, it uses a File Uploader.  For my purposes, I want to just hardcode a local file location for my PDF into my JS code (preferably relative to my index.html file).  That way I can easily work on my local machine.

 

Can you please advise?  Thank you!

 

PS.  Note that my index.html is located in "file:///C:/my/sandbox/" in the same dir as local_file.pdf.

Views

213

Likes

Translate

Translate

Report

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
Adobe Employee ,
May 29, 2020 May 29, 2020

Copy link to clipboard

Copied

Hi, Thanks for using View SDK,  Browsers generally disallow accessing files from the local file system using file path even if the HTML is also on the local file system for security reasons. 

Although there is a possible solution to your problem is to use SimpleHTTPServer

  • Make sure you have python installed in your system
  • Navigate to your sandbox directory.
  • Use "python -m SimpleHTTPServer 8000"
  • Open http://localhost:8000/index.html in the browser.

 

Below snippet will work in this case.

adobeDCView.previewFile(
       {
          content:   {location: {url: "local_file.pdf"}},
          metaData: {fileName: "local_file.pdf"}
       }, {embedMode: "IN_LINE", showDownloadPDF: true, showPrintPDF: true});


 I hope this helps!

Likes

Translate

Translate

Report

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 Beginner ,
May 31, 2020 May 31, 2020

Copy link to clipboard

Copied

Hi Shubhanshu,

 

Thank you for your help!  I tried your suggestion but am encountering issues.

Running my Python http server worked fine.  And I'm able to see:

http://localhost:8000/local_file.pdf

 

But when I try to view, I get this View SDK error:

File preview not available

This application domain (http://localhost:8000) is not authorized to use the provided View SDK Client ID.
 
And then when I try to use console.adobe.io to add "localhost" as an authorized domain, I get errors.
I've tried:
Domain localhost is invalid
Domain http://localhost:8000 is invalid

Domain http://localhost is invalid

 

Can you please advise?  Thank you!

---

 

PS.  Here are screenshots of the errors I'm receiving:

r002_1-1590989848474.png

 

r002_0-1590989806200.png

-----

 

Update (6/1):  I tried one more thing tonight that didn't work-- I tried opening index.html locally (not running on Python's http.server) and when I tried to view my PDF (that is being served on localhost:8000), I now see this error:

 

r002_0-1590991633788.png

 

Can you please advise?  Thank you!

Likes

Translate

Translate

Report

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
Adobe Employee ,
May 31, 2020 May 31, 2020

Copy link to clipboard

Copied

Hi, Ideally it should allow localhost to be added. We are working on that. 

Meanwhile, you can try generating client id by https://www.adobe.io/apis/documentcloud/dcsdk/gettingstarted.html

and provide domain as localhost

Likes

Translate

Translate

Report

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 Beginner ,
Jun 01, 2020 Jun 01, 2020

Copy link to clipboard

Copied

LATEST

Ah, okay-- I see.  Creating a "localhost" clientId (API key) works from here:

https://www.adobe.io/apis/documentcloud/dcsdk/gettingstarted.html?ref=showCreateCredentialsFormWithV...

 

but fails (is disallowed) from inside of https://console.adobe.io/

 

That's a bit confusing.  I've got my sandbox project working now though; thank you for helping!

Likes

Translate

Translate

Report

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