I’m trying to allocate a buffer for a PDF file. I get an error using the function like that:
(in my backend file)
import Buffer from ‘buffer’ ;
export function FillPDF (dataURI, fields)
{ var pdf_buffer = Buffer. from (dataURI, ‘base64’ ); var out_buf = pdfform().transform(pdf_buffer, fields);
uploadPDF( out_buf); //Step after will be to upload the filled pdf file to UploadFolder…*/
}
J.D thank you, you’re helping me a lot in the last few days! Do you mean that my function doesn’t return any value? So yes, actually it looks like that, but I wanted to make it simple to understand…:
export function FillPDF (dataURI, fields)
{ var pdf_buffer = Buffer. from (dataURI, ‘base64’ ); var out_buf = pdfform().transform(pdf_buffer, fields); return mediaManager.upload(
“/myUploadFolder” ,
out_buffer,
“NewPDF.pdf” ,
{
“mediaOptions” : {
“mimeType” : “application/pdf” ,
“mediaType” : “document”
},
})
.then( (upload) => { return upload.fileUrl})
}
And the error I get in preview mode is:
“_buffer2.default.from is not a function”
but I guess it means that I’m not using buffer.from properly…
In publish mode the error is:
" Error: Unable to handle the request, contact site administrator"
@jonatandor35 The concept is to take a regulatory PDF file that needs to be sent to the authorities and to fill it automatically with the customer data saved in the data collection (name, address, facility details…).
So my algorithm is to create in the frontend the fields data array, send it to the FillPDF function in the backend, in the FillPDF function I’ll get the pdf file in a buffer, call the pdfform().transform function, and save the output pdf file in the mediaManager.
And yes, I imported PdfForm: import {pdfform} from ‘pdfform.js’ ; (need to add ‘.js’)
@osnat_po This is interesting. But the PDF link you posted above doesn’t have real PDF fields (like this ). It’s a scan. I’m wondering how you think to fill it in.
@osnat_po No. I haven’t had a chance and I probably won’t get to it soon.
It requires some research and trial & error process (and it’s mostly non-Corvid issue).
But if you figure out how to do it, please post it here.
Maybe I (or others) will need it one day. Thanks.
@jonatandor35 If you have any idea for me how and where can I found a developer to do that for me, I’ll be glad to hear. I tried in fiver but no luck, and I send a request to Wix marketplace and yet no found…