首页 > 解决方案 > 如何在 react native 中使用 react-native-image-to-pdf 将图像转换为 pdf

问题描述

我正在尝试使用 react-native-image-to-pdf 将图像转换为 pdf。我已经使用 react-native-view-shot 保存了该图像。但现在。我不知道为什么在下面的代码中他们使用两次像这样的 imagePaths =“imagePaths:imagePaths:[image]”。也为了名字。当我在我的 vs 代码中复制该代码时。然后由于这两个 imagePaths 和名称而出现错误。但是当我从那里删除一个 imagePaths 和名称时。然后在调用该函数后,我在空对象引用]"。请帮我。

这是图像到pdf的代码

  imageToPdf = async () => {
    try {
      const options = {
        imagePaths: imagePaths:  [this.state.imagePath],
        name: name:  "PDFName",
        maxSize: { // optional maximum image dimension - larger images will be resized
            width: 900,
            // height: Math.round(deviceHeight() / deviceWidth() * 900),
            height: 900,
        },
        quality: 0.7, // optional compression paramter
      };
      const pdf = await RNImageToPdf.createPDFbyImages(options);

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

这是状态

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


标签: javascriptreact-nativepdf

解决方案


推荐阅读