Jump to content

Recommended Posts

Posted

I want to print the contents of the htmlmemo, but when I replace any text {{NAME}} with what was typed in the edit, the print preview doesn't do what is in the htmlmemo, only when I click the button for the second time. Watch the video.

 

The button code is this:

I replace the {{NAME}} variable with what was typed in the edit window.

UniHTMLMemo1.Text := StringReplace(UniHTMLMemo1.Text, '{{NAME}}', UniEdit1.Text, [rfReplaceAll, rfIgnoreCase]);
 

Here I print the contents of the HtmlMemo, but it only prints the second time I run the code.

UniSession.AddJs(UniHTMLMemo1.jsname+'.iframeEl.dom.contentWindow.print();');

Posted
On 14/09/2025 at 12:30, Sherzod said:

Ok, mas pelo menos compartilhe o código completo do seu botão.

UniHTMLMemo1.Text := StringReplace(UniHTMLMemo1.Text, '{{NAME}}', UniEdit1.Text, [rfReplaceAll, rfIgnoreCase]);UniSession.AddJs(UniHTMLMemo1.jsname+'.iframeEl.dom.contentWindow.print();');

Posted

Hello @eduardosuruagy

On 9/14/2025 at 5:52 AM, Sherzod said:

Use Ext.defer

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniHTMLMemo1.Text := StringReplace(UniHTMLMemo1.Text, '{{NAME}}', 'testvalue', [rfReplaceAll, rfIgnoreCase]);
  UniSession.AddJs('Ext.defer(function(){' + UniHTMLMemo1.JSName + '.iframeEl.dom.contentWindow.print()}, 500);');
end;

 

On 9/14/2025 at 6:57 PM, eduardosuruagy said:

or JSCallDefer instead of AddJS

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniHTMLMemo1.Text := StringReplace(UniHTMLMemo1.Text, '{{NAME}}', 'testvalue', [rfReplaceAll, rfIgnoreCase]);
  UniHTMLMemo1.JSInterface.JSCallDefer('iframeEl.dom.contentWindow.print', [], 500);
end;

 

Posted
10 hours ago, Sherzod said:

Hello @eduardosuruagy

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniHTMLMemo1.Text := StringReplace(UniHTMLMemo1.Text, '{{NAME}}', 'testvalue', [rfReplaceAll, rfIgnoreCase]);
  UniSession.AddJs('Ext.defer(function(){' + UniHTMLMemo1.JSName + '.iframeEl.dom.contentWindow.print()}, 500);');
end;

 

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniHTMLMemo1.Text := StringReplace(UniHTMLMemo1.Text, '{{NAME}}', 'testvalue', [rfReplaceAll, rfIgnoreCase]);
  UniHTMLMemo1.JSInterface.JSCallDefer('iframeEl.dom.contentWindow.print', [], 500);
end;

 

It worked perfectly. Thank you so much!!

Another question: is it possible to add text at the end of the document? As shown in the image.

Sem título.png

Posted
1 hour ago, eduardosuruagy said:

Another question: is it possible to add text at the end of the document? As shown in the image.

You need to handle this with CSS. For example, add a footer <div> and style it with position: fixed; bottom: 0; inside a @media print rule, so it will appear at the bottom of the printed page.

Posted
33 minutes ago, Sherzod said:

Você precisa lidar com isso com CSS. Por exemplo, adicione um rodapé <div> e estilize-o com position: fixed; bottom: 0; dentro de uma regra de impressão @media, para que apareça na parte inferior da página impressa.

Thanks, I'll try...

Posted
11 hours ago, Sherzod said:

Você pode procurar soluções no fórum, isso já foi discutido muitas vezes, e adaptá-lo ao seu caso.

Before trying to get help here on the forum, I usually research the component I want and even try to use some AI to help me, as a last resort I open a message on the forum. Thanks anyway!!

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