const filePath = path.join(pdfFolderPath, file);
// Read the PDF file
const fileData = await fs.readFile(filePath);
// Load the PDF document
const pdfDoc = await PDFDocument.load(fileData);
const arrayBuffer = await pdfDoc.save(); // Save as ArrayBuffer
// Get the file name without extension
const nameWithoutExtension = path.basename(file, path.extname(file));
// Convert to Base64 string for JSON
pdfArray.push({
name: nameWithoutExtension, // Save without .pdf
pdf: arrayBuffer.toString("base64"),
});
I have that pdf value as arrayBuffer.toString("base64")
.
const a = await pdfSearch(`${output[i]["field4"]}`, arrivalPdf);
// const arrayBuffer = await response.arrayBuffer(); // Get the PDF as an ArrayBuffer
const pdfDoc = await PDFDocument.load(a.pdf);
a.pdf is the string value that I get from converted value. I’ve been trying to convert it back to feed it to PDFDocument.load()
. Stuck for like 3 days. Tried 10 different things that I could find here.
I know that this is very redundant question but I could not work it out after trying different stackoverflow solutions again and again :/
how can I change it to something that I can load it to PDFDocument.load()
from pdf-lib
?
I tried with atob
but it did not work. Also, I am trying to do this on a browser without fetching anything. No server. Just from a plain html. I think I can use the package but many did not work too.