Jump to content

Print Screen


freedowsRoO

Recommended Posts

54 minutes ago, eduardosuruagy said:

Is it possible to leave the image on the server and send it by email? I would not like to download it.

Well then, first of all, you need to analyze how to send email...

You can find many examples on the forum, please use the search.

Link to comment
Share on other sites

On 4/13/2020 at 1:09 PM, Sherzod said:

Ok sorry, then need to send to the server, or send it by email from the client side. We will try...

Hello, any ideia about this?

 

How can i retrieve a variable in server side from this code? For example, if i want to get the 'uri' on server side, how i can do that?

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);
    }
}

 

Link to comment
Share on other sites

On 4/13/2020 at 10:03 PM, eduardosuruagy said:

I want to give a print on the screen and send it by email, this function that was placed here it downloads the image.

 

11 hours ago, freedowsRoO said:

How can i retrieve a variable in server side from this code? For example, if i want to get the 'uri' on server side, how i can do that?

One possible solution (for example, a snapshot of the button itself):

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  with UniButton1 do
    JSInterface.JSCode('html2canvas(document.querySelector("#' + JSId +'")).then(function(canvas) {ajaxRequest('#1', "getData", ["base64Data="+canvas.toDataURL()])});');
end;

 

procedure TMainForm.UniButton1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if EventName='getData' then
  begin
    // Params.Values['base64Data']
    // Here you need to decode the Base64 string
    // data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEsAAAAZ...AAAABJRU5ErkJggg==
  end;

end;

 

  • Like 1
Link to comment
Share on other sites

6 hours ago, Sherzod said:

 

One possible solution (for example, a snapshot of the button itself):


procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  with UniButton1 do
    JSInterface.JSCode('html2canvas(document.querySelector("#' + JSId +'")).then(function(canvas) {ajaxRequest('#1', "getData", ["base64Data="+canvas.toDataURL()])});');
end;

 


procedure TMainForm.UniButton1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if EventName='getData' then
  begin
    // Params.Values['base64Data']
    // Here you need to decode the Base64 string
    // data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEsAAAAZ...AAAABJRU5ErkJggg==
  end;

end;

 

Nice! Thanks a lot!

  • Like 1
Link to comment
Share on other sites

On 4/13/2020 at 11:41 AM, eduardosuruagy said:

Is it possible to leave the image on the server and send it by email? I would not like to download it.

How i do that? I save just de base64 string in my database and after that i decode de base64 string to get the img.

Link to comment
Share on other sites

  • 1 year later...
On 9/13/2019 at 6:53 AM, 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

 

Hi, this works great, it's amazing, thank you !!! Just one question: is there a way to automatically save the file to a specific path on the server without user intervention?

 

 

Link to comment
Share on other sites

  • 2 months later...
3 minutes ago, Sherzod said:

Hello,

Have you tried the approach above?

 

With your way, i can take screenshot and then download the file.

I need to save screenshot and then send by email to customer.

 

Thanks for your support,

 

Best Regards

Link to comment
Share on other sites

7 hours ago, Sherzod said:

This post may help you:

 

Thanks for the support,

 

But my problem is not send to email

My problem is take screenshot and save to the server.

There is a way to save the screenshot to the server ?

 

Thank you again for your support,

 

Best Regards,

 

Link to comment
Share on other sites

34 minutes ago, loQsoft said:

My problem is take screenshot and save to the server.

 

On 4/20/2020 at 1:06 PM, Sherzod said:
procedure TMainForm.UniButton1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if EventName='getData' then
  begin
    // Params.Values['base64Data']
    // Here you need to decode the Base64 string
    // data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEsAAAAZ...AAAABJRU5ErkJggg==
  end;

end;

Just need to try to implement it. I'll try one of these days...

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
On 12/28/2021 at 3:10 PM, loQsoft said:

My problem is take screenshot and save to the server.

Hello,

You can try this approach:

1. 

uses ... Soap.EncdDecd;

2. 

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  with UniButton1 do
    JSInterface.JSCode('html2canvas(document.querySelector("#' + JSId +'")).then(function(canvas) {ajaxRequest('#1', "getData", ["base64Data="+canvas.toDataURL()])});');

end;

3. 

procedure TMainForm.UniButton1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
var
  stream: TBytesStream;
  base64s: string;
  AUrl: string;
begin
  if EventName = 'getData' then
  begin
    base64s := Params.Values['base64Data'];
    base64s := StringReplace(base64s, 'data:image/png;base64,', '', [rfReplaceAll]);
    stream := TBytesStream.Create(DecodeBase64(base64s));
    try
      stream.SaveToFile(UniServerModule.NewCacheFileUrl(False, 'png', '', '', AUrl, True));
      UniImage1.Url := AUrl;
    finally
      stream.Free;
    end;
  end;

end;

4. CustomFiles:

files/html2canvas.min.js

 

  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...
On 1/10/2022 at 8:55 AM, Sherzod said:

Hello,

You can try this approach:

1. 

uses ... Soap.EncdDecd;

2. 

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  with UniButton1 do
    JSInterface.JSCode('html2canvas(document.querySelector("#' + JSId +'")).then(function(canvas) {ajaxRequest('#1', "getData", ["base64Data="+canvas.toDataURL()])});');

end;

3. 

procedure TMainForm.UniButton1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
var
  stream: TBytesStream;
  base64s: string;
  AUrl: string;
begin
  if EventName = 'getData' then
  begin
    base64s := Params.Values['base64Data'];
    base64s := StringReplace(base64s, 'data:image/png;base64,', '', [rfReplaceAll]);
    stream := TBytesStream.Create(DecodeBase64(base64s));
    try
      stream.SaveToFile(UniServerModule.NewCacheFileUrl(False, 'png', '', '', AUrl, True));
      UniImage1.Url := AUrl;
    finally
      stream.Free;
    end;
  end;

end;

4. CustomFiles:

files/html2canvas.min.js

 

Thank you very much, @Sherzod

 

İ will try weekend your solution proposal and will inform you

 

Best Regards,

 

  • Upvote 1
Link to comment
Share on other sites

  • 6 months later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...