eduardosuruagy Posted September 13, 2025 Posted September 13, 2025 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();'); Gravar_2025_09_13_16_31_12_44.mp4 Quote
Sherzod Posted September 14, 2025 Posted September 14, 2025 Hello, Use Ext.defer or JSCallDefer instead of AddJS, so the print runs after the HtmlMemo content is updated. Quote
eduardosuruagy Posted September 14, 2025 Author Posted September 14, 2025 13 hours ago, Sherzod said: Hello, Use Ext.defer or JSCallDefer instead of AddJS, so the print runs after the HtmlMemo content is updated. What would the command look like? I couldn't get it to work. Quote
Sherzod Posted September 14, 2025 Posted September 14, 2025 1 hour ago, eduardosuruagy said: What would the command look like? I couldn't get it to work. Okay, but at least share the complete code for your button. Quote
eduardosuruagy Posted September 15, 2025 Author Posted September 15, 2025 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();'); Quote
Sherzod Posted September 16, 2025 Posted September 16, 2025 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; Quote
eduardosuruagy Posted September 16, 2025 Author Posted September 16, 2025 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. Quote
Sherzod Posted September 16, 2025 Posted September 16, 2025 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. Quote
eduardosuruagy Posted September 16, 2025 Author Posted September 16, 2025 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... Quote
eduardosuruagy Posted September 16, 2025 Author Posted September 16, 2025 Is it possible to open the print screen and see when it was closed? Or open it in another browser tab? Quote
Sherzod Posted September 17, 2025 Posted September 17, 2025 You can search for solutions on the forum, this has been discussed many times, and adapt it to your case. Quote
eduardosuruagy Posted September 17, 2025 Author Posted September 17, 2025 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!! Quote
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.