[英]React-Native convert a base64 images array to a single pdf
我正在使用react-native / redux中的移動應用程序,其中我必須將base64圖像數組轉換為pdf,才能將pdf發送到后端。 關於如何實現的任何想法?
好的,我終於在react-native-image-to-pdf的幫助下找到了一個簡單的解決方案,它基於Promis。 在一個名為“ 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);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.