【问题标题】:React-Native convert a base64 images array to a single pdfReact-Native 将 base64 图像数组转换为单个 pdf
【发布时间】:2018-03-11 03:20:48
【问题描述】:

我正在使用 react-native / redux 开发一个移动应用程序,我必须将一组 base64 图像转换为 pdf,以便将 pdf 发送到后端。 关于如何实现它的任何想法?

【问题讨论】:

  • 看看这是否有助于你到达目的地medium.com/@dschmidt1992/…
  • 感谢您的链接,我在看到您的评论之前找到了解决方案;)

标签: image pdf react-native base64


【解决方案1】:

好的,我终于在react-native-image-to-pdf 的帮助下找到了一个简单的解决方案 它是基于承诺的。在一个名为“pdfConverter.js”的文件中,我创建了这个函数

import RNImageToPdf from "react-native-image-to-pdf";

export default base64Arr => {
  // It is a promise based function
  // Create an array containing the path of each base64 images
  let base64Paths = [];
  base64Paths.length = 0; // re-initialize the array for further re-use

  base64Arr.forEach(base64 => {
    base64Paths.push(`data:image/jpeg;base64,${base64}`);
  });

  // Convert base64 images to pdf from the paths array
  return RNImageToPdf.createPDFbyImages({
    imagePaths: base64Paths,
    name: "PDF_Name"
  });
};

然后在另一个文件中我需要的地方调用它:

import toPDF from "./pdfConverter.js";

toPDF(myBase64array)
.then(pdf => {
  console.log("pdf ", pdf);
});

【讨论】:

  • 酷,你可能想给作者投个 github 星来表达爱意。到目前为止,他只有 1 颗星github.com/JonasLaux/react-native-image-to-pdf
  • 太棒了,尤其是因为他仅在 3 天前发表。就在您需要的时候:D。我相信他不会介意这种鼓励。
  • 哈哈!完美的时机
  • 这里什么都不会发生 mergeImage(){ RNImageToPdf.createPDFbyImages({ imagePaths: this.state.myarr, name: "PDF_Name" }).then(pdf => { console.log("pdf " , pdf); }).catch(err => console.log("error catch search:", err)); }
  • 有人调查吗?
猜你喜欢
  • 2022-10-17
  • 2021-01-08
  • 2019-07-12
  • 2021-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-13
相关资源
最近更新 更多