Jump to content

Print Screen


freedowsRoO

Recommended Posts

8 hours ago, Sherzod said:

Hello,

Maybe this is not what you are looking for, but look at this demo example too:


\FMSoft\Framework\uniGUI\Demos\Desktop\HTML2Image

 

That's will work! 

BUT i have only one question. Is there a way to get the HTML of an especific component?

Link to comment
Share on other sites

Hi @Sherzod

how do i call this function in a uniButton? Note that in the place of #CAPTURE i need to insert the ID of the element that i want to take a screenshot.

function screenshot(){
    html2canvas(document.querySelector("#capture")).then(
    canvas => {  
    var a = document.createElement('a');
    a.href = canvas.toDataURL("image/jpeg",1.0).replace("image/jpeg", "image/octet-stream");
    a.download = 'somefilename.jpg';
    a.click();                    
    });
}

 

i'm trying to do something like this in the ExtEvent of the button but no succes

function click(sender, e, eOpts){ '+
	html2canvas(document.querySelector( UniTabSheet1.JSName )).then( 
	canvas => { 
	var a = document.createElement("a"); 
	a.href = canvas.toDataURL("image/jpeg",1.0).replace("image/jpeg", "image/octet-stream"); '
	a.download = "somefilename.jpg"; 
	a.click(); 
	}); 
  }'
);

 

 

Link to comment
Share on other sites

Hi,

Can you try these steps?

1. CustomFiles:

files/html2canvas.min.js

2. 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. How to use, for example:

procedure TMainForm.UniButton2Click(Sender: TObject);
var
  fName: string;
begin
  fName := 'capture' + FormatDateTime('ddmmyyyyhhnnss', Now);
  UniPanel1.JSInterface.JSCode(
    'html2canvas(document.querySelector("#'+ UniPanel1.JSId +'")).then(function(canvas) {'+
    '    canvasSaveAs(canvas.toDataURL(), "'+ fName +'");'+
    '});'
  );
end;

html2canvasFrm.png.7e024012d6bf894e78d202b984bb260f.png

capture13092019101010.png.cf503316569051aa119f74de49ec231e.png

  • Like 3
Link to comment
Share on other sites

3 minutes ago, Sherzod said:

Hi,

Can you try these steps?

1. CustomFiles:


files/html2canvas.min.js

2. 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. How to use, for example:


procedure TMainForm.UniButton2Click(Sender: TObject);
var
  fName: string;
begin
  fName := 'capture' + FormatDateTime('ddmmyyyyhhnnss', Now);
  UniPanel1.JSInterface.JSCode(
    'html2canvas(document.querySelector("#'+ UniPanel1.JSId +'")).then(function(canvas) {'+
    '    canvasSaveAs(canvas.toDataURL(), "'+ fName +'");'+
    '});'
  );
end;

html2canvasFrm.png.7e024012d6bf894e78d202b984bb260f.png

capture13092019101010.png.cf503316569051aa119f74de49ec231e.png

OMG it's work perctly!! Thanks a lot!! You are the best! 

  • Like 1
Link to comment
Share on other sites

8 hours ago, freedowsRoO said:

If i create i new project your code works fine but when i paste the same code in my real project i receive the message: " html2canvas is not defined" any ideia?

Hi,

Can you add this code to MainForm.Script and test?

Ext.onReady(function() {
    Ext.Loader.loadScript('files/html2canvas.min.js'); // please correct your path
});

 

  • Like 1
Link to comment
Share on other sites

16 hours ago, freedowsRoO said:

I found the problem, did several tests and found that the problem occurs when using the 'UniSyntaxEditEx' component. I dont know wy but thats it.

Hello,

Can you make a simple testcase with UniSyntaxEditEx for reproduce this?

Thank you.

  • Like 1
Link to comment
Share on other sites

  • 6 months later...

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...