1

我正在使用 react-native-share 扩展来共享和打印 Pdf 文档。我正在尝试添加“打印”属性,但它不起作用或我无法正确使用此文档https://react-native-community.github.io/react-native-share/docs/share -open#activitytype

我在这里使用了这个例子https://react-native-community.github.io/react-native-share/docs/share-open#activityitemsources-ios-only 根据这个文档,我创建了一个像

const url = this.props.navigation.state.params.document.url
           {
            item:{
            print : url
            }
          },

在此处输入图像描述

4

1 回答 1

2

https://react-native-community.github.io/react-native-share/docs/share-remote-file

下面的代码解决了我的IOS问题。我认为存在问题,因为文档来自 url。它仍然不适用于 android

static sharePDFWithAndroid(fileUrl, type) {
  let filePath = null;
  let file_url_length = fileUrl.length;
  const configOptions = { fileCache: true };
  RNFetchBlob.config(configOptions)
    .fetch('GET', fileUrl)
    .then(resp => {
      filePath = resp.path();
      return resp.readFile('base64');
    })
    .then(async base64Data => {
      base64Data = `data:${type};base64,` + base64Data;
      await Share.open({ url: base64Data });
      // remove the image or pdf from device's storage
      await RNFS.unlink(filePath);
    });
}
于 2020-06-25T07:20:59.933 回答