Jump to content

UniPanel's snapshot problem


55143681

Recommended Posts

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...