Closed Tarunpreetsingh16 closed 2 years ago
@Tarunpreetsingh16 Some problem here, did you find any solution?
@MarcoRhayden Just to make it work for now I am converting the file to base64 and setting img src to that. https://github.com/christopherdro/react-native-html-to-pdf/issues/66
@Tarunpreetsingh16 Worked, thank you!
I faced a similar issue, The root cause of it may be the file access permission. read this, https://developer.android.com/reference/android/webkit/WebSettings#setAllowFileAccess(boolean). I fixed my issue by calling setAllowFileAccess(true)
in PdfConverter.java.
WebSettings settings = mWebView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
mWebView.loadDataWithBaseURL(mBaseURL, mHtmlString, "text/HTML", "utf-8", null);
to
WebSettings settings = mWebView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
settings.setAllowFileAccess(true);
mWebView.loadDataWithBaseURL(mBaseURL, mHtmlString, "text/HTML", "utf-8", null);
The moment I changed the sdk version to 30, the images stopped showing up in the pdf. It just shows the empty space, like it was not able to find that picture. I can confirm that picture is there, but it does not show up in the pdf. If I revert back the sdk version to 29, it works fine.
I am using the local file path to set as the img src, like
file:///storage/emulated/0/Documents/FolderName/FileName.jpg