Cannot open links inside PDF on ios.
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:
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?
Yes, in iOS version, not support link now.
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!!
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.
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.
I had release v5.0.0 and it supports links.
Its working like a charm!! Thanks @wonday :)
@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 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.
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?
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 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.
@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...
@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.
@vaibhavk98
open pdf with browser and in browser shows content://com.android.download.Filename/763?
it seems not support opening pdf.
To be exact, its this one - content://com.android.providers.downloads.documents/document/764, the link after opening downloaded pdf from app in browser
Thanks for the reply will check.
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 :-)
You can add a link with your app schema like yourapp://local host/message/xxx
and catch link by Linking module.
@wonday I got this , How can I open this pdf?
Could not open URL 'file:///storage/emulated/0/prophet_app/fileOne.pdf'
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)?