'Reactive Native Web: Open linked PDF from Webview within the App
Is there an easy way to open/display a PDF which is linked on a website shown via WebView within react-native-webview within the App or at least within the default PDF app on the phone?
How to "change" behaviour of the website, right now a linked PDF (e.g. <a href="http://www.example.com/bla.pdf">Link</a> is opened in the normal browser and than downloaded... instead it should just open up.
I found react-native-pdf and react-native-view-pdf but they seem to simply open local PDFs... How to actually inject and modify links ON the website to have that behaviour?
Thanks
EDIT: What I tried is:
import Pdf from 'react-native-pdf';
showPdf(pdfurl) {
const source = {uri: pdfurl,cache:true};
//const source = require('./test.pdf'); // ios only
//const source = {uri:'bundle-assets://test.pdf'};
//const source = {uri:'file:///sdcard/test.pdf'};
//const source = {uri:"data:application/pdf;base64,..."};
return (
<View style={styles.container}>
<Pdf
source={source}
onLoadComplete={(numberOfPages,filePath)=>{
console.log(`number of pages: ${numberOfPages}`);
}}
onPageChanged={(page,numberOfPages)=>{
console.log(`current page: ${page}`);
}}
onError={(error)=>{
console.log(error);
}}
style={styles.defaults.pdf} />
</View>
)
}
Within the Webview config:
onShouldStartLoadWithRequest={(event) => {
if (event.url.includes('.pdf')) {
this.showPdf(event.url);
return false;
}
return true;
}}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
