Can Buffer.from() get a URL path?

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…*/
}

This function called from the frontend of course , and ‘dataURI’ is actually URL path, like: " http://www.sviva.gov.il/subjectsenv/hazardousmaterials/waste/documents/hazardous_waste_accompanying_form.pdf"

You’re not returning promises. And you need to return them if you want it to work (even without looking into the detailed code).

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"

@osnat_po What is this line:

var out_buf = pdfform().transform(pdf_buffer, fields); 

?

@jonatandor35 this is from the pdfform.js package , the transform function return new filled pdf file

So you imported it?
Can you explain what you’re trying to do?

1 Like

@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.

@jonatandor35 Ho, you right. I changed the PDF to be fillable and upload it. This is the correct link: https://ff4066b3-fa1e-4f83-866c-5d6548bfdbe3.usrfiles.com/ugd/ff4066_85749710b488467f98302a1ec22f8708.pdf

@jonatandor35 to the rescue! Please, have you had the chance to take one more look at my code?

@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…

@osnat_po I don’t know, but I had another look at your code and I can see an error there.
You decaled a out_buf but the you use out_buffer

Also have a look at this npm:

It looks easy to use and it’s available on wix.

1 Like