55143681 Posted March 26, 2020 Share Posted March 26, 2020 I can use js to snapshot uniPanel to a image, and my test demo works well, but when I add the code to my project, that do not work, what 's the problem maybe? The demo is: 1.add files/html2canvas.min.js to UniServerModule->CustomFiles 2.add code to MainForm->Script function canvasSaveAs(uri, filename) { var link = document.createElement('a'); if (typeof link.download === 'string') { link.href = uri; link.download = filename; document.body.appendChild(link); link.click(); document.body.removeChild(link); } else { window.open(uri); } } 3.add Unibutton click event void __fastcall TMainForm::UniButton1Click(TObject *Sender) { String fName; fName = "capture" + FormatDateTime("yyyyMMddhhnnss", Now()); UniPanel1->JSInterface->JSCode( "html2canvas(document.querySelector(\"#"+ UniPanel1->JSId +"\")).then(function(canvas) {" +" canvasSaveAs(canvas.toDataURL(), \""+ fName +"\");" + "});" ); } html2canvas.min.js Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.