Hello,
I am using 2018.1 CLR 4.5 WebHtmlEditor with IE 11. Does anyone know a way to print just the contents of the HTMLEditor control without printing the entire webpage?
I have a WebHtmlEditor within a WebSplitterPaine. The content of the editor is loaded dynamically from a database field. When using the print from the menu bar the entire web page is printing displaying the WebSplitter and all.
Any advice or suggesting are greatly appreciated.
Thank you for posting in our community!
In general, the browser knows how to render correctly the HTML Editor content. If you obtain the content prior to rendering in the browser, it will differ from what you would expect as an end result. Printing will require for the browser to render the HTML Editor first. If it is an option for you, it is possible to render the HTMLEditor only in a “print preview” page (separate popup browser window) and let your users print directly from there using the standard browser printing capabilities, so when printing a webpage only the required data will be printed.
For example a quick illustration, navigate to one of our online samples like this one, enter some content in the editor and click the “Preview In Browser” button from the HTMLEditor’s Toolbar. A Print preview window will appear, with the HTMLEditor’s only content. You can access the browser's print options as well as more detailed print preview from the context menu after a right click on the page.
Thank You,
I did figure that out. I know a marked this question as answered but to make thing easier for the application users, I would like to go strait to the browser's print preview command after when clicking the "Preview in Browser" button. can you point me to script that executes that command?
Thank you for your feedback!
Please notice,browsers do not allow for printing without going through a print preview first, as it is somewhat a security issue. If you search through the web, you may find a suitable hack to achieve this, and yet I strongly suggest not taking such an approach.
Thank you for your response Milko,
I actually need the script code that performs the "Preview In Browser" command. Similar to the browser command bleow: My objective is when the user clicks the "Preview in Browser" button from the editor's toolbar is to have the new browser window go directly to print preview without having to use the right-click browser commands.
<script type="text/javascript" id="igClientScript"> <!-- function WebHtmlEditor1_BeforeAction(oEditor, actID, oEvent, p4, p5, p6, p7, p8, act) { //Add code to handle your event here. if (actID == "Print") { var editortext = oEditor.getText(); if (editortext.length > 0) { oEvent.cancel = true; var OLECMDID = 7; /* OLECMDID values: * 6 - print * 7 - print preview * 1 - open window * 4 - Save As */ var PROMPT = 1; // 2 DONTPROMPTUSER var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'; document.body.insertAdjacentHTML('beforeEnd', WebBrowser); WebBrowser1.ExecWB(OLECMDID, PROMPT); WebBrowser1.outerHTML = ""; } else { oEvent.cancel = true; alert("Nothing to Print!"); } } else if (actID = "Preivew") { var event = oEvent; //Somehow use the browser command above go straight to Print Preview //After new window is open... } } // --> </script>
Hi,
If I understand you correctly what you need is to add a button allowing your end users to print directly on the printer what is in the editor. You can achieve this using the WebHtmlEditor’s Client-Side Object Model (CSOM) function print. To do so add a button to your application and on click event execute this code:
var editor = iged_getById("YouWebHtnlEditorID"); if (editor) { editor.print(); }
More information about CSOM of WebHtmlEditor you may find at the following topic in our documentation “WebHtmlEditor Object”.
Please let us know if any additional questions on this matter arise.