Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot Open Local File pdf in Ionic 2 #157

Closed
tunathoni opened this issue Sep 11, 2017 · 9 comments
Closed

Cannot Open Local File pdf in Ionic 2 #157

tunathoni opened this issue Sep 11, 2017 · 9 comments

Comments

@tunathoni
Copy link

Hello,

Sorry i want to ask about my issue, i already run with ionic serve and i try to open local pdf file, it can work properly, but after i try to check in www/ folder especially on index.html, just clicked it once, show in browser, but file is not loaded and show an error like this :

Fetch API cannot load file:///Users/toni/Documents/myApp/www/assets/files/test.pdf. URL scheme must be "http" or "https" for CORS request.

So can you help me to solve this issue ? thanks.

@tristian-me
Copy link

tristian-me commented Sep 25, 2017

The problem with this is the version of PDFJS-dist that is being used. NPM seems to ignore the pdfjs-dist version in package.json and installs version 1.9.

A quick work around:
npm install [email protected] and check your package.json for version 1.6.329.

@VadimDez
Copy link
Owner

See method onFileSelected() - this is how you can load local pdfs
https://github.com/VadimDez/ng2-pdf-viewer/blob/master/src/app/app.component.ts#L52-L64

@Yashrad
Copy link

Yashrad commented Oct 19, 2017

Im getting the same error.
I generate a pdf file and write it to the device dataDirectory , and get the same error trying to set the pdf Source. downgrading pdfjs-dist didnt help as well.

@tristian-me
Copy link

tristian-me commented Oct 19, 2017 via email

@phpepe
Copy link

phpepe commented May 14, 2018

Is there a solution for this issue ?
Im using ng2-pdf-viewer v5.0.1 and still getting this error:

"Fetch API cannot load file:///data/user/0/MY_APP/files/MY_FILE.pdf. URL scheme "file" is not supported.

My use case is try to view previously 'downloaded' pdfs on a ionic3 app
Tried other libs like pdfjs and no luck.

Any help would be appreciated
Thanks

@db-conception
Copy link

Hi, How to resolve the problem ?
I get this message :
polyfills-es2015.js:5958 Access to XMLHttpRequest at 'file:///data/user/0/io.ionic.starter/www/doc/13.pdf' from origin 'http://localhost' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, https."``

@db-conception
Copy link

db-conception commented Oct 28, 2019

This work with the file directly in asset folder and with the next url :
http://localhost:8000/assets/000000221394393_61908343.pdf
But I need to download the file and I can not download it in asset directory.

@tristian-me
Copy link

tristian-me commented Oct 29, 2019

If your having issues it's because of a the new versions of PDFjs library supplied by Mozilla.

Try working with version 1.0.2: npm i [email protected] --save

Hopefully this will help.

@shoebs115
Copy link

shoebs115 commented May 26, 2021

Im getting the same error.
I generate a pdf file and write it to the device dataDirectory , and get the same error trying to set the pdf Source. downgrading pdfjs-dist didnt help as well.

You can not open PDF file directly, first you will need to convert it to ArrayBuffer

Yo can check the solution here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants