-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
[WebView] Error trying to display PDF in web view component #1846
Comments
TEMPORARY SOLUTION: I have modified the class RCTWebView and method initWithEventDispatcher to have something like this:
the key to solve the problem it has been the line: _webView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen]bounds]]; previously it was something like this: _webView = [[UIWebView alloc] initWithFrame:self.bounds]; I guess there is some issue getting the bounds of the webview, that's why I have specified the main screen bounds. |
@JavierM84 you are a champion! Been struggling with this for days and today thought to put this as an issue and you already have a work around and it works! :) |
Great job! |
thx for the compliment, I was struggling with this issue too and I thought that maybe this could help to more people temporarily |
Hmm, the issue I have with this is that the webview may not be the full size of the screen, so using If I understand correctly, the problem is that self.bounds is {0,0,0,0} when the view is first created, and the webview doesn't like trying to display a PDF when it's size is zero. I guess the solution is either to defer setting the content until the webview has been sized correctly, or to init the webview with some temporary nonzero size, and then set it correctly later. |
yes totally agree this is not a correct solution, we should provide the correct size of the webview. I guess it works because somehow the value is adjusted properly later, but definitively it needs a value at the beginning |
I agree with @nicklockwood's assessment - if you are using |
Finally, how to solve? I also meet the questions... 😂 #2188 |
If this is still an issue you can just inject the html and open the file with javascript eg. var html = '<body style="margin:0;padding:0;width:100%;height:100%;">' +
'<div class="">Opening PDF</div>' +
'<script type="text/javascript">window.location.href="' + this.props.url + '"</script>' +
'</body>';
var options = {
automaticallyAdjustContentInsets: false,
html: html,
style: {
flex: 1,
marginTop: 55
}
};
return React.createElement(WebView, options);``` |
@JavierM84 Thank you for your help Javier! |
Removing the |
Thanks @julianacipa for the follow up! |
@julianacipa Thank you for help 👍 |
Does this work on Android? I can show the pdf in iOS but not in Android. |
great job! |
I also am not able to get this working in Android. |
I can't even get this to work on iOS. I must be missing something in the source attribute now the URL is deprecated.
That fails with Unable to resolve module. Can anyone point me in the right direction? |
Okay, for future generations, here's how I solved this problem: iOS only
The trick is that you need to include Just copying it into your React Native project folder wasn't enough. It had to be part of the Xcode project itself. |
@BOMaley the require(./foobar.pdf) version should work if the pdf file is located in the same folder as your js. It's possible I forgot to add pdf to the packager whitelist though, if so let me know and I'll fix it. |
@nicklockwood The require syntax did not work for me. It worked if I wanted to load an html file, but replace |
@brentvatne The only way I have been able to get this to work is using the hack method that @JavierM84 originally posted. Just wondering if you could elaborate on your solution of adding an onLayout callback. My code is like this
I know it will work if I remove |
@bomalley The fix is just to add the "pdf" file extension in all the places where I added "html" and other extensions in this PR: 81fb985#commitcomment-15932047 If you want to put up a PR for that, I'll accept it. |
Summary:The WebView component in iOS currently does not support displaying PDFs without providing a remote URI or manually including the assets in the xcodeproj itself. This is because the packager has not whitelisted the 'pdf' extension. I've gone ahead and whitelisted the 'pdf extension according to the recommendation by nicklockwood GH comment: #1846 (comment) Closes #7004 Differential Revision: D3196019 Pulled By: nicklockwood fb-gh-sync-id: 10a86a9232095f98f277506141de0b8af5b21ab4 fbshipit-source-id: 10a86a9232095f98f277506141de0b8af5b21ab4
Summary:The WebView component in iOS currently does not support displaying PDFs without providing a remote URI or manually including the assets in the xcodeproj itself. This is because the packager has not whitelisted the 'pdf' extension. I've gone ahead and whitelisted the 'pdf extension according to the recommendation by nicklockwood GH comment: facebook#1846 (comment) Closes facebook#7004 Differential Revision: D3196019 Pulled By: nicklockwood fb-gh-sync-id: 10a86a9232095f98f277506141de0b8af5b21ab4 fbshipit-source-id: 10a86a9232095f98f277506141de0b8af5b21ab4
Summary:The WebView component in iOS currently does not support displaying PDFs without providing a remote URI or manually including the assets in the xcodeproj itself. This is because the packager has not whitelisted the 'pdf' extension. I've gone ahead and whitelisted the 'pdf extension according to the recommendation by nicklockwood GH comment: facebook#1846 (comment) Closes facebook#7004 Differential Revision: D3196019 Pulled By: nicklockwood fb-gh-sync-id: 10a86a9232095f98f277506141de0b8af5b21ab4 fbshipit-source-id: 10a86a9232095f98f277506141de0b8af5b21ab4
Summary:The WebView component in iOS currently does not support displaying PDFs without providing a remote URI or manually including the assets in the xcodeproj itself. This is because the packager has not whitelisted the 'pdf' extension. I've gone ahead and whitelisted the 'pdf extension according to the recommendation by nicklockwood GH comment: facebook#1846 (comment) Closes facebook#7004 Differential Revision: D3196019 Pulled By: nicklockwood fb-gh-sync-id: 10a86a9232095f98f277506141de0b8af5b21ab4 fbshipit-source-id: 10a86a9232095f98f277506141de0b8af5b21ab4
@JavierM84 thanks, your temp fix fixed the intermittent |
Summary:The WebView component in iOS currently does not support displaying PDFs without providing a remote URI or manually including the assets in the xcodeproj itself. This is because the packager has not whitelisted the 'pdf' extension. I've gone ahead and whitelisted the 'pdf extension according to the recommendation by nicklockwood GH comment: facebook/react-native#1846 (comment) Closes facebook/react-native#7004 Differential Revision: D3196019 Pulled By: nicklockwood fb-gh-sync-id: 10a86a9232095f98f277506141de0b8af5b21ab4 fbshipit-source-id: 10a86a9232095f98f277506141de0b8af5b21ab4
I still seem to be getting this error in RN 0.44, although it's intermittent |
for anyone looking to fix this with layoutChanged, this worked for me:
|
@brentvatne online PDFs not loading with |
Same here |
With |
I need to render a pdf online which is why An example workaround for this is as follows:
Using |
Sometimes the PDF don't open and it just shows a white screen. Is this a react-native problem or an iOS Webview problem? Any news? I think this issue should be reopened. |
We are experiencing the same issue as reported by @brunoti. PDFs fail to load for no obvious reason. |
Hello,
I am trying to display a pdf file from the app bundle but I could not do it, this is what I have done:
localFile.pdf is obviously included in the bundle but when I try to display this webview it doesn't show it properly.
From xcode I have got these error messages:
[85869:8794860] DiskImageCache: Could not resolve the absolute path of the old directory.
[85869] : CGAffineTransformInvert: singular matrix.
[85869] : CGAffineTransformInvert: singular matrix.
[85869] : CGAffineTransformInvert: singular matrix.
And I can't see it
The text was updated successfully, but these errors were encountered: