Search code examples
javascriptgoogle-chromepdfgoogle-chrome-extensionjspdf

How do I access local PDF files in my Chrome Extension app?


Google Chrome allows you to preview local PDF files in the browser like pictured below:

enter image description here

I am working on an extension that takes whatever PDF is in the browser preview and opens it in my custom editor/markup tool.

I have been successful in loading PDFs from remote URLs because I can just send the remote URL to my server, download it there, and open the PDF in my app using PDFjs.

How can I accomplish the same functionality for local PDF files?

I have looked into possibly using javascript to create a File object from local PDF files but Chrome doesn't allow access to the local file system.

I am hoping to accomplish this functionality by the user just clicking my extension icon, similar to the popular extension, Kami.


Solution

  • you need to add permissions to your extension:

    "permissions": ["file://*/*"]
    

    to ensure that you have permissions for local files, use:

    chrome.extension.isAllowedFileSchemeAccess
    

    P.S. have a good day and do not use upwork for these type of questions :-D