CMS Development

Kavya
Member

Download the template(html) as PDF on click

Hey all,

I have a template(HTML) and using html2pdf (script tag) written a function to download the whole page as pdf but getting a warning in the chrome console as mentioned below:

Download is disallowed. The frame initiating or instantiating the download is sandboxed, but the flag ‘allow-downloads’ is not set. See https://www.chromestatus.com/feature/5706745674465280 for more details.

Have tried the same thing in HTML file it's working perfectly and able to download the file.

Also tried to add iframe tag inside HTML file but could not able to solve it.

Function to download the HTML as pdf:

function getPDF(){
console.log("Download");
var element = document.getElementById('text');

// Define optional configuration
var options = {
margin: 10,
filename: 'myfile.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2, logging: true, dpi: 192, letterRendering: true },
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
};

// Create instance of html2pdf class
var exporter = new html2pdf(element, options);
exporter.getPdf(true).then((pdf) => {
console.log('pdf file downloaded');
});
exporter.getPdf(false).then((pdf) => {
console.log('doing something before downloading pdf file');
pdf.save();
});
options.source = element;
options.download = true;
html2pdf.getPdf(options);
};

can anybody help me to solve this or any other way to download the HTML in Hubspot?.

FYI giving same error with jspdf 

0 Upvotes
4 Replies 4
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

Download the template(html) as PDF on click

Hey @Kavya 

Thanks @dennisedson 

 

Without digging too far I found this.

Maybe has something to do with it?

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
Kavya
Member

Download the template(html) as PDF on click

Hey Thanks, Kevin-C, have found that earlier and also tried to set the sandbox flag within in iframe but not solved the issue.

Appreciate your time for replying

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Download the template(html) as PDF on click

Hello @Kavya 

Going to throw a couple people at this

@prosa , @Kevin-C , @piersg  any of you all work with jspdf?

0 Upvotes
Kavya
Member

Download the template(html) as PDF on click

Thanks for the reply, but I also tried with JSpdf, HTML2canvas and then now using html2pdf, but all giving the same warning.

But its works absolutely fine with HTML using js script tag

0 Upvotes