94
Views
3
Comments
Solved
[Reactive Html2Pdf Js] Await in javascript for reactive app
reactive-html2pdf-js
Reactive icon
Forge asset by Ryan Surjadi
Application Type
Reactive
Service Studio Version
11.13.1 (Build 53655)

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?

2021-03-18 21-03-15
Benjith Sam
 
MVP
Solution

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

2021-11-29 10-47-28
Oleg Fallmann

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

2021-03-18 21-03-15
Benjith Sam
 
MVP

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();
});

I hope this helps you!


Kind regards,

Benjith Sam

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.