Hi, I'm trying to receive a result of an asynchronous function.
As soon as I apply an await, I get an error.
Does anybody know, how I could solve this problem?
Hi Oleg,
If I understood your use case correctly, I would suggest using the below-mentioned JS to get the binary content of pdf.
See this sample screen: HTML2Pdf Reactive
html2pdf().set(opt).from(element).outputPdf().then(function(pdf) { //output base64 $parameters.Base64url = btoa(pdf); // output binary $parameters.binary = $parameters.Base64url; $resolve(); });
Documentation Link: Defining_Asynchronous_JavaScript_Code
I hope this helps you!
Kind regards,
Benjith Sam
Hey Benjith,
indeed it helps, thank you a lot. I came several times across the documentation you refer to, however I didn't get that it would solve my problem. I have still a small problem to understand why I need to code to Base64 in order to get the binary of the pdf, but this would be a different topic.
Best regards,
Oleg
You're welcome, Oleg.
As I understand, the pdf parameter is a binary string value, which can't be assigned to the Binary data type variable (Sorry! I don't know the exact technical reason). However, I have another approach to suggest to get the pdf blob (which eliminates the Base64 conversion) that can be assigned to the output binary variable.
JS Snippet:
html2pdf().set(opt).from(element).outputPdf('blob').then(function(pdf) { // output binary $parameters.binary = pdf; $resolve(); });