1

我已经使用视图拍摄库拍摄了屏幕视图的图像。之后,我使用 react-native-image-to-pdf 库将该图像转换为 pdf。文件保存成功但是。当我尝试打开该文件时,它说文件格式不受支持。而且它没有 .pdf 扩展名。请帮忙。

这是我的状态

 this.state = {
      imagePath: "",
      pdf: "",
    };

这是我的功能

 onCapture = (uri) => {
    console.log("do something with ", uri);
    this.setState({ imagePath: uri.replace("file://", "") });
    console.log("this is " + this.state.imagePath);
  };
 

imageToPdf = async () => {
    try {
      const options = {
        imagePaths: [this.state.imagePath],
        name: "TablePdf" + ".pdf",
        maxSize: {         
          width: 900,
        },
        quality: 0.7,
      };
      const pdf = await RNImageToPdf.createPDFbyImages(options);
      this.setState({ pdf: pdf.filePath });

      Linking.openURL(
        `mailto:support@example.com?subject=SendMail&body=${this.state.pdf}`
      );

      console.log(pdf.filePath);
    } catch (e) {
      console.log(e);
    }
  };

这是我的视图拍摄和整个视图


   <ScrollView>
    <IconShare onPress={this.imageToPdf}/>
        <ViewShot
            onCapture={this.onCapture}
            captureMode="mount"
            options={{ format: "png", quality: 0.9 }}
            >

         <ScrollView horizontal={true}>
            <View></View>
            <View></View>
            <View></View>
            <View></View>
            <View></View>
            <View></View>
            <View></View>
            <View></View>
            <View></View>
         </ScrollView>

        </ViewShot>
  </ScrollView>


4

0 回答 0