react-native-pdf icon indicating copy to clipboard operation
react-native-pdf copied to clipboard

Cannot open links inside PDF on ios.

Open captnAmericaa opened this issue 8 years ago • 20 comments

What react-native version are you using ? 0.54.2 What react-native-pdf version are you using ? 4.0.0 What platform dose your issue occur on? (android/ios/both) ios

I have a PDF which is getting loaded properly using the library. PDF has some hyperlinks embedded in it like link to privacy policy document and link to company URL. When I click those links nothing seems to happen. It stays as it is. It works on android but not on ios.

Snapshot from PDF:

screen shot 2018-07-25 at 4 36 24 pm

Code I am using is similar to example in docs. <Pdf source={webViewSource} onLoadComplete={this._onLoadEnd} onError={this._onError} style={{flex: 1, width: Dimensions.get('window').width}}/>

If someone has faced same issue or knows what is wrong with ios?

captnAmericaa avatar Jul 25 '18 06:07 captnAmericaa

Yes, in iOS version, not support link now.

wonday avatar Jul 25 '18 06:07 wonday

Hi @wonday

Thanks for quick response. It makes everything clear.

But do you know of any workaround which I can use here? I used webView and google docs solution initially and I could inject a javascript which can detect windows.click event and open links in new window. But google docs is not reliable and I shifted to react-native-pdf.

It would be great if I can make it work somehow :)

Thanks!!

captnAmericaa avatar Jul 25 '18 06:07 captnAmericaa

Only use the webview to load the pdf, it can be displayed and scrolled, can this detect link clicks or not, I have not tested. It should work.

wonday avatar Jul 25 '18 07:07 wonday

It seems WebView supports ios but not Android. Tested on many different version of Android by giving PDF URL directly. Also as mentioned here - https://github.com/facebook/react-native/issues/18592.

captnAmericaa avatar Jul 25 '18 07:07 captnAmericaa

I had release v5.0.0 and it supports links.

wonday avatar Aug 01 '18 03:08 wonday

Its working like a charm!! Thanks @wonday :)

captnAmericaa avatar Aug 07 '18 01:08 captnAmericaa

@wonday On android, webview is not working, any workaround? I just want to open the links present in pdf file inside react-native-pdf

vaibhavk98 avatar Aug 20 '18 06:08 vaibhavk98

@vaibhavk98 capture link and open it by yourself not system default app? It can not be captured now. only can be opened by system default app.

wonday avatar Aug 20 '18 07:08 wonday

extending the question from @vaibhavk98 and @captnAmericaa. I am looking for opening pdf using system default app? like it is done using native code like below. //ANDROID

val intent = Intent(Intent.ACTION_VIEW); intent.setDataAndType(FileProvider.getUriForFile(this, applicationContext.packageName + ".provider", file), "application/pdf"); startActivity(intent); webview pdf is not supported in Android, is there any other way to open?

arul-prasad avatar Aug 20 '18 10:08 arul-prasad

The last version of react-native-pdf v5.0.2 support link in pdf both android and ios, so you do not need use a webview to open pdf.

wonday avatar Aug 20 '18 10:08 wonday

@wonday yes yes you are right, what i am asking is not about the link in pdf. My question may be in another context if I have to open the pdf, not inside my app or using default app or internal browser.

arul-prasad avatar Aug 20 '18 10:08 arul-prasad

@wonday I am able to download pdf, but when I open it using browser, it shows something like content://com.android.download.Filename/763 , I just want the downloaded pdf to be opened with pdf viewer, but it gives blank document...

vaibhavk98 avatar Aug 21 '18 01:08 vaibhavk98

@arul-prasad Your needs is open pdf use default app or internal browser from your app? you can try react-native build-in module Linking.

// url is the file of pdf
Linking.canOpenURL(url).then(supported => {
  if (!supported) {
    console.log('Can\'t handle url: ' + url);
  } else {
    return Linking.openURL(url);
  }
}).catch(err => console.error('An error occurred', err));

maybe have not default app and internal browser also do not support opening pdf, so you need check it first.

wonday avatar Aug 21 '18 01:08 wonday

@vaibhavk98 open pdf with browser and in browser shows content://com.android.download.Filename/763? it seems not support opening pdf.

wonday avatar Aug 21 '18 01:08 wonday

To be exact, its this one - content://com.android.providers.downloads.documents/document/764, the link after opening downloaded pdf from app in browser

vaibhavk98 avatar Aug 21 '18 08:08 vaibhavk98

Thanks for the reply will check.

arul-prasad avatar Nov 22 '18 06:11 arul-prasad

Hello, I'm considering to use this library to show a PDF that contains some links the user can click on. I need to catch the click event and the url that was clicked, to show a custom view when the user clicks on the link.

Can you do it with this library ? I'm looking at the code right now but i don't see any onLinkClicked kind of event.

Thank you :-)

gabriel-morin-pro avatar Mar 29 '19 13:03 gabriel-morin-pro

You can add a link with your app schema like yourapp://local host/message/xxx

and catch link by Linking module.

wonday avatar Mar 29 '19 14:03 wonday

@wonday I got this , How can I open this pdf?

Could not open URL 'file:///storage/emulated/0/prophet_app/fileOne.pdf'

anastely avatar Jan 25 '20 11:01 anastely

The last version of react-native-pdf v5.0.2 support link in pdf both android and ios, so you do not need use a webview to open pdf.

The current version does not seem to support links in the PDF (iOS only, works on Android)?

snios avatar Sep 24 '24 07:09 snios