Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A question regarding pptx files in react-native app

Tags:

react-native

I have an application where I need to show the .pptx and .pdf files. For pdf files I am using react-native-pdf and file is opening fine in my App but when it comes to .pptx files we have 2 libraries: 1. https://www.npmjs.com/package/react-native-doc-viewer 2. https://www.npmjs.com/package/react-native-file-viewer

react-native-doc-viewer is not being actively maintained and a lot of issues :(

But both of them were giving a prompt to select an app like Wps Office or Microsoft apps but they were not opening as Pdf files opened in my app. Whats the reason behind this? We cannot open pptx file in our app?

like image 721
Gvs Akhil Avatar asked Sep 15 '26 20:09

Gvs Akhil


1 Answers

I read the react-native-doc-viewer android native code. it is actually is to download a doc not to view it. the following is the code:

@ReactMethod
  public void openDoc(ReadableArray args, Callback callback) {
      final ReadableMap arg_object = args.getMap(0);
      try {
        if (arg_object.getString("url") != null && arg_object.getString("fileName") != null) {
            // parameter parsing
            final String url = arg_object.getString("url");
            final String fileName =arg_object.getString("fileName");
            final String fileType =arg_object.getString("fileType");
            final Boolean cache =arg_object.getBoolean("cache");
            final byte[] bytesData = new byte[0];
            // Begin the Download Task
            new FileDownloaderAsyncTask(callback, url, cache, fileName, fileType, bytesData).execute();
        }else{
            callback.invoke(false);
        }
       } catch (Exception e) {
            callback.invoke(e.getMessage());
       }
  }

it uses FileDownloaderAsyncTask to download files. if you are familiar with it.

if you want to show excels, Docx, you can use the google doc line convert it to Html, then in the webView to show it. the format like it: https://docs.google.com/gview?embedded=true&url=[doc address], the same effect as ios.

like image 52
Lenoarod Avatar answered Sep 17 '26 10:09

Lenoarod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!