file format not supported error in react native image To pdf and react native view shot

689 Views Asked by At

I have take image of screen view in by using view shot library. and after that I convert that image to pdf using react-native-image-to-pdf library. file saved successfully but. when I try to open that file its saying file format not supported. and also it has no .pdf extension. please help.

here is my state

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

here is my function

 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:[email protected]?subject=SendMail&body=${this.state.pdf}`
      );

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

here is my View Shot and Entire View


   <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>


0

There are 0 best solutions below