Hi everyone. I've 2 problems with that code: When I click on button Get Pdf, automatically it appears up the write download (because of HTML I think); 2. I cannot download the pdf, the website always says network error. I'm working on it since 2 full days, but nothing. I hope you help me, thanks in advance. I followed step by step the tutorial: Back-end code: // Code start
import PDFGeneratorAPI from 'pdf-generator-api';
export async function pdf(nome, cognome, email) {
let Client = new PDFGeneratorAPI(
'<APIkey>',
'<APIsecret>'
);
Client.setWorkspace('<...@gmail.com>');
let obj = {
"Nome" : nome,
"Cognome" : cognome,
"Email" : email,
}
let response = await Client.output('<......>', obj , 'pdf' , 'PdfName' , {"output" : "url"} )
return response.response
}
// Code end In page code: // Code start
import { pdf } from 'backend/pdf.jsw';
$w.onReady(function () {
var base64;
$w('#Scarica').onClick(() => {
let nome = $w('#Nome').value;
let cognome = $w('#Cognome').value;
let email = $w('#Email').value;
pdf(nome, cognome, email).then(e => {
base64 = e;
base64 = 'data:application/pdf;base64,' + base64
let msg = {
"conv": true,
"dataUrl": base64
}
$w('#html1').postMessage(msg);
});
});
});
// Code end HTML code: <!-- code start --> <script> window.onmessage = event => { if(event.data.conv) { if(document.getElementById('Download') === null || document.getElementById('Download') === undefined){ var pn = document.createElement('a') pn.download = 'Download.pdf'; pn.title = 'Download pdf document'; pn.textContent = 'Download'; pn.id ='Download' var s = document.getElementsByTagName('body')[0].appendChild(pn); pn.href = event.data.dataUrl; } else { let d = document.getElementById('Download') d.href = event.data.dataUrl; } document.getElementById('Download').click() } } </script> <!-- code end -->