christopherdro / react-native-html-to-pdf

Convert html strings to PDF documents using React Native
MIT License
434 stars 264 forks source link

Images not showing up in API Level 30 #243

Closed Tarunpreetsingh16 closed 2 years ago

Tarunpreetsingh16 commented 2 years ago

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

MarcoRhayden commented 2 years ago

@Tarunpreetsingh16 Some problem here, did you find any solution?

Tarunpreetsingh16 commented 2 years ago

@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

MarcoRhayden commented 2 years ago

@Tarunpreetsingh16 Worked, thank you!

yuhui-zhao commented 2 years ago

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);