erich.wanker Posted June 28, 2017 Share Posted June 28, 2017 Hello Folks :-) i try to print the content of a UniHTMLFrame .. but find no solution .. i tried out: extevent: window.print UniSession.AddJs(UniHTMLFrame1.jsname+'.iframeEl.dom.contentWindow.print();'); and var frm = BERICHT.UniHTMLFrame1.iframe; if (frm) { printIframe(frm); any ideas? THANX Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 28, 2017 Share Posted June 28, 2017 Hi Erich, Can you make a simple testcase for this ?! Best regards, Quote Link to comment Share on other sites More sharing options...
Tokay Posted August 16, 2017 Share Posted August 16, 2017 Hi! I have an issue with printing too. I'm using the Chrome brouser and try to print a TUniHTMLFrame. The code is simple: procedure TMainForm.UniButton1Click(Sender: TObject); begin UniHTMLFrame1.HTML.Text := '<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' + '<title>HTML Document</title> </head> <body> <p> <b> This text is bold,<i>and this one is also italic</i></b></p></body></html>'; UniSession.AddJs(UniHTMLFrame1.jsname + '.iframeEl.dom.contentWindow.print();'); end; Dpr: object UniHTMLFrame1: TUniHTMLFrame Left = 8 Top = 8 Width = 785 Height = 465 Hint = '' end And I get the ajax error: Cannot read property 'dom' of undefined O17.iframeEl.dom.contentWindow.print();O17.update(" <!DOCTYPE html> <html> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>HTML Document</title> </head> <body> <p> <b> This text is bold,<i>and this one is also italic</i></b></p></body></html>\n",true); Any suggestions? Quote Link to comment Share on other sites More sharing options...
delagoutte Posted August 16, 2017 Share Posted August 16, 2017 For print html, i'm using uniHtmlMemo but i think it must work with unihtmlframe. i have a dedicated unimemo for print working . in memoExport.Clientsevent.extevents function dirtychange(sender, isDirty, eOpts) { ajaxRequest(sender, "changeforprint", []); } memoexport.onAjaxevent : if EventName = 'changeforprint' then begin if MemoExport.Text<>'' then begin UniSession.AddJs( 'var browserName = navigator.userAgent.toLowerCase(); '+ 'if ( browserName.indexOf("msie") != -1) '+ '{'+ MemoExport.jsname+'.iframeEl.dom.contentWindow.focus();'+ MemoExport.jsname+'.iframeEl.dom.contentWindow.print();'+ '} '+ 'else '+ '{'+ 'if(browserName.indexOf("trident") != -1) '+ '{'+ MemoExport.jsname+'.iframeEl.dom.contentWindow.focus();'+ MemoExport.jsname+'.iframeEl.dom.contentWindow.document.execCommand(''print'', false, null);'+ '}'+ 'else '+ '{'+ MemoExport.jsname+'.iframeEl.dom.contentWindow.focus();'+ MemoExport.jsname+'.iframeEl.dom.contentWindow.print();'+ '};'+ '};'); MemoExport.Text:=''; end; if you want print a html, i load it in memoexport MemoExport.Text:= GetHtmlPrint; Important : the uniMemoHtml must be visible = true if you don't want see it set top = -1000; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 16, 2017 Share Posted August 16, 2017 Hi, Also you can try to use this: UniHTMLFrame1.JSInterface.JSCode('Ext.defer(function(){'#1'.iframe.contentWindow.print()}, 100);'); Best regards, Quote Link to comment Share on other sites More sharing options...
Tokay Posted August 16, 2017 Share Posted August 16, 2017 Sorry, this code doesn't works: UniHTMLFrame1.JSInterface.JSCode('Ext.defer(function(){'#1'.iframe.contentWindow.print()}, 100);'); Message from browser console: VM265:1 Uncaught TypeError: Cannot read property 'contentWindow' of undefined at eval (eval at AjaxSuccess (ext-unicommon-min.js:8), <anonymous>:1:33) Quote Link to comment Share on other sites More sharing options...
delagoutte Posted August 16, 2017 Share Posted August 16, 2017 for test, could you try with 2 button. Button1click : UniHTMLFrame1.HTML.Text :='<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' +'<title>HTML Document</title> </head> <body> <p> <b> This text is bold,<i>and this one is also italic</i></b></p></body></html>'; button2click : UniHTMLFrame1.JSInterface.JSCode('Ext.defer(function(){'#1'.iframe.contentWindow.print()}, 100);'); O17.iframeEl.dom.contentWindow.print();O17.update(" <!DOCTYPE html> <html> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>HTML Document</title> </head> <body> <p> <b> This text is bold,<i>and this one is also italic</i></b></p></body></html>\n",true); it seems unigui launch print before load html. so if there is no html in frame, there is no dom/content but maybe i am wrong Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 16, 2017 Share Posted August 16, 2017 for test, could you try with 2 button. Button1click : UniHTMLFrame1.HTML.Text := '<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' + '<title>HTML Document</title> </head> <body> <p> <b> This text is bold,<i>and this one is also italic</i></b></p></body></html>'; button2click : UniHTMLFrame1.JSInterface.JSCode('Ext.defer(function(){'#1'.iframe.contentWindow.print()}, 100);'); O17.iframeEl.dom.contentWindow.print();O17.update(" <!DOCTYPE html> <html> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>HTML Document</title> </head> <body> <p> <b> This text is bold,<i>and this one is also italic</i></b></p></body></html>\n",true); it seems unigui launch print before load html. so if there is no html in frame, there is no dom/content but maybe i am wrong Yes, you are right. For this case need to use OnFrameLoaded event, like this: http://forums.unigui.com/index.php?/topic/8811-switch-between-url-and-html-of-urlframe/&do=findComment&comment=45422 Quote Link to comment Share on other sites More sharing options...
Tokay Posted August 17, 2017 Share Posted August 17, 2017 Thank you! All works great. I changed TUniHTMLFrame to TUniURLFrame. Quote Link to comment Share on other sites More sharing options...
kalilxd11 Posted May 22, 2019 Share Posted May 22, 2019 On 8/16/2017 at 4:27 PM, delagoutte said: For print html, i'm using uniHtmlMemo but i think it must work with unihtmlframe. i have a dedicated unimemo for print working . in memoExport.Clientsevent.extevents function dirtychange(sender, isDirty, eOpts) { ajaxRequest(sender, "changeforprint", []); } memoexport.onAjaxevent : if EventName = 'changeforprint' then begin if MemoExport.Text<>'' then begin UniSession.AddJs( 'var browserName = navigator.userAgent.toLowerCase(); '+ 'if ( browserName.indexOf("msie") != -1) '+ '{'+ MemoExport.jsname+'.iframeEl.dom.contentWindow.focus();'+ MemoExport.jsname+'.iframeEl.dom.contentWindow.print();'+ '} '+ 'else '+ '{'+ 'if(browserName.indexOf("trident") != -1) '+ '{'+ MemoExport.jsname+'.iframeEl.dom.contentWindow.focus();'+ MemoExport.jsname+'.iframeEl.dom.contentWindow.document.execCommand(''print'', false, null);'+ '}'+ 'else '+ '{'+ MemoExport.jsname+'.iframeEl.dom.contentWindow.focus();'+ MemoExport.jsname+'.iframeEl.dom.contentWindow.print();'+ '};'+ '};'); MemoExport.Text:=''; end; if you want print a html, i load it in memoexport MemoExport.Text:= GetHtmlPrint; Important : the uniMemoHtml must be visible = true if you don't want see it set top = -1000; Thank you, your example worked for me! Quote Link to comment Share on other sites More sharing options...
delagoutte Posted May 23, 2019 Share Posted May 23, 2019 i have a new method if you want : add uses ExtPascalUtils; Add a TuniHtmlMemo (MemoExport) on your form and set "top" to -1000 to hide it (don't use visible property) on ClientEvent.Extevents add this code in "push" : function push(sender, html, eOpts) { if ((html.trim() != "")&&(html.trim() != "​")){ var browserName = navigator.userAgent.toLowerCase(); if ( browserName.indexOf("msie") != -1) { sender.iframeEl.dom.contentWindow.focus(); sender.iframeEl.dom.contentWindow.print(); } else { if(browserName.indexOf("trident") != -1) { sender.iframeEl.dom.contentWindow.focus(); sender.iframeEl.dom.contentWindow.document.execCommand('print', false, null); } else { sender.iframeEl.dom.contentWindow.focus(); sender.iframeEl.dom.contentWindow.print(); }; }; } } Now all is ready. for printing html do this : procedure TMainForm.PrintText(Sender: TObject; aValue : string); begin UniSession.AddJS('if (!'+MemoExport.JSName+'.initialized){'+MemoExport.JSName+'.initialized=true;};');// i must add this for chrome at some users. sometimes the component is not initialized UniSession.AddJS(MemoExport.JSName+'.textareaEl.dom.value='+ StrToJS(aValue)+';'+MemoExport.JSName+'.pushValue();') end; .. procedure TMainForm.BtnPrintSelClick(Sender: TObject); begin PrintText(Sender,GetExportHtml); end; 1 Quote Link to comment Share on other sites More sharing options...
eduardosuruagy Posted August 24, 2019 Share Posted August 24, 2019 Can I print straight from UniHTMLFrame? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 25, 2019 Share Posted August 25, 2019 4 hours ago, eduardosuruagy said: Can I print straight from UniHTMLFrame? Please clarify the question. Have you tried the solutions above, or what problems do you have with these solutions? Quote Link to comment Share on other sites More sharing options...
eduardosuruagy Posted August 26, 2019 Share Posted August 26, 2019 On 24/08/2019 at 23:41, Sherzod said: Por favor, esclareça a questão. Você já tentou as soluções acima, ou quais problemas você tem com essas soluções? I am testing the TinyMCE demo example and would like to have a button to print UniHTMLFrame content. www.unigui.com.br-TinyMCEdemo.rar Quote Link to comment Share on other sites More sharing options...
eduardosuruagy Posted August 30, 2019 Share Posted August 30, 2019 On 8/24/2019 at 11:41 PM, Sherzod said: Please clarify the question. Have you tried the solutions above, or what problems do you have with these solutions? As I print what is in this project TinyMCE, I tried to use the examples above but I was not successful. Can you help me? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 30, 2019 Share Posted August 30, 2019 4 hours ago, eduardosuruagy said: As I print what is in this project TinyMCE, I tried to use the examples above but I was not successful. Can you help me? Sorry, I haven't looked into the above testcase yet. Quote Link to comment Share on other sites More sharing options...
eduardosuruagy Posted August 30, 2019 Share Posted August 30, 2019 6 hours ago, Sherzod said: Desculpe, eu não procurei no testcase acima ainda. But you can help me? Quote Link to comment Share on other sites More sharing options...
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.