反应式本机 Web:从应用程序内的 Webview 打开链接的 PDF
有没有一种简单的方法可以打开/显示通过应用程序内的react-native-webview中的WebView显示的网站上链接的PDF,或者至少在手机上的默认PDF应用程序中?
如何“更改”网站的行为,现在是链接的 PDF(例如 Link
在普通浏览器中打开并下载...相反,它应该只是
打开react-native-pdf和react-native-view-pdf,但它们似乎只是打开本地PDF...如何实际注入。并修改网站上的链接以实现这种行为?
谢谢
编辑: 我尝试的是:
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>
)
}
在 Webview 配置中:
onShouldStartLoadWithRequest={(event) => {
if (event.url.includes('.pdf')) {
this.showPdf(event.url);
return false;
}
return true;
}}
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;
}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论