Skip to main content
Participating Frequently
May 29, 2020
Question

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

  • May 29, 2020
  • 1 reply
  • 1228 views

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.

    This topic has been closed for replies.

    1 reply

    Adobe Employee
    May 30, 2020

    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!

    r002Author
    Participating Frequently
    June 1, 2020

    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:

     

    -----

     

    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:

     

     

    Can you please advise?  Thank you!

    Adobe Employee
    June 1, 2020

    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