I'm working on a mobile app in react-native / redux in which I have to convert an array of base64 images into a pdf in order to send the pdf to the back-end. Any idea about how to achieve it ?
Ok I finally found an easy solution with the help of react-native-image-to-pdf It is promis based. In a file I called "pdfConverter.js" I created this function
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"
});
};
and then call it where I need in another file :
import toPDF from "./pdfConverter.js";
toPDF(myBase64array)
.then(pdf => {
console.log("pdf ", pdf);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.