【问题标题】:how to use print attribute react-native-share如何使用打印属性 react-native-share
【发布时间】:2020-06-24 07:13:52
【问题描述】:

我正在使用 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
            }
          },

【问题讨论】:

标签: android ios react-native printing share


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2022-06-28
    • 2023-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-16
    • 2018-07-08
    相关资源
    最近更新 更多