christopherdro / react-native-html-to-pdf

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

Support to targetSdkVersion 30 android 11 #229

Closed Guillecaba closed 2 years ago

Guillecaba commented 3 years ago

I was updating my project to React native 0.64.2 and my sdk is pointing to version 30, in preparation for the request from the playstore for November, but I am having problems with this library with devices with android 11 Error: RNHTMLtoPDF error: Could not create folder structure. is the error that is giving me.

Before to support sdk 29 i used android: requestLegacyExternalStorage = "true" but this will no longer be a solution for android 11, what would be the solution now for android 11 target sdk30?

gabrielhdgb commented 3 years ago

Same problem, any solution?

NourAliAbdou commented 3 years ago

I'm trying to use app private storage to store the pdf and then open it! it works properly on android 10 and below, but can't be accessed with API_30 devices, Even the action RNHTMLtoPDF.convert(options) doesn't work when I call it!

mindira5 commented 3 years ago

Same problem. Any update on supporting this library for target sdk version 30

RemyLivewall commented 3 years ago

I had a similar problem, but not using the documents folder (because this is the system's documents folder) as mentioned in the documentation fixed the issue for me. This was mentioned in another issue here: https://github.com/christopherdro/react-native-html-to-pdf/issues/185.

If you need to store the file for a longer period of time, you could use another library such as https://github.com/itinance/react-native-fs to store it in your app's local folders to comply with Android 11.

mindira5 commented 3 years ago

@RemyLivewall , Removing directory from options will store the pdf file in apps internal cache folder. This will not allow to view the document. As per my requirement, I have to store pdf document in external folder like downloads/documents so Users can view file from Device's Path.

RaniXavier commented 3 years ago

Same problem. How to use this library to comply with Android 11?

NourAliAbdou commented 3 years ago

Setting directory to Documents works for me. :D

RaniXavier commented 3 years ago

Setting directory to Documents works for me. :D

@NourAliAbdou - Not working in Android 11

mindira5 commented 2 years ago

Any update on this

UsamaAltaf commented 2 years ago

Any Update? :(

Guillecaba commented 2 years ago

Has anyone found a workaround or an alternative library for this situation?

ozzfelipe commented 2 years ago

Removing directory parameter works for me. I was using directory as "documents".

SohelKabir commented 2 years ago

Hey I was facing the same issue in target SDK 30 and gladly found a solution. First look at my code

async function createPDF(params) {
  const html = getHTMLPage(params);
  const options = {
    html,
    fileName: getFileName(params.entryType),
    directory: 'Documents',
    // height: 792,
    // width: 612,
  };
  const file = await RNHTMLtoPDF.convert(options);
  RNFetchBlob.android.actionViewIntent(file.filePath, 'application/pdf');
}

I was saving the file to Documents directory and it was just saving fine (log the file after save) but when i was viewing the file with RNFetchBlob that's where I was getting the error. So my problem was with viewing the file with RNFetchBlob. If your problem is same try to add these lines in AndroidManifest.xml

    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:mimeType="*/*" />
        </intent>
    </queries>

Hope it solves your problem.

aliMurtaja commented 2 years ago

Hey I was facing the same issue in target SDK 30 and gladly found a solution. First look at my code

async function createPDF(params) {
  const html = getHTMLPage(params);
  const options = {
    html,
    fileName: getFileName(params.entryType),
    directory: 'Documents',
    // height: 792,
    // width: 612,
  };
  const file = await RNHTMLtoPDF.convert(options);
  RNFetchBlob.android.actionViewIntent(file.filePath, 'application/pdf');
}

I was saving the file to Documents directory and it was just saving fine (log the file after save) but when i was viewing the file with RNFetchBlob that's where I was getting the error. So my problem was with viewing the file with RNFetchBlob. If your problem is same try to add these lines in AndroidManifest.xml

    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:mimeType="*/*" />
        </intent>
    </queries>

Hope it solves your problem.

I have used this before, and it has fixed the issue. but the problem what I am facing is that when I reinstall the app and use convert function, app are crashed. but when I clear the all download content that were download using old same app, working fine...

sundardsTechMind commented 2 years ago

Does anyone find the solution?

mindira5 commented 2 years ago

Any update on this?

sundardsTechMind commented 2 years ago

Does anyone find the solution or any alternative library?

Tharunvarshanth commented 2 years ago

same here also does anyone have solution