Request for local printing


#1

i’ve posted here before inquiring about local printing (Printing on a local printer) and gotten a helpful response, but it would be SO much better if the facility were easily available in the workspace IDE. Just my (request for) 2 cents…david


Print Function for the IDE?
#2

See my suggestion at this post: Printing on a local printer


#3

Sometime ago there was a similar request for ace https://github.com/ajaxorg/ace/issues/1480#issuecomment-20201314, if you want to print highlighted code to pdf the code for a plugin or init script is very simple

services.commands.addCommand({
    name: "print",
    isAvailable: function(editor) {
        var tab = services.tabManager.focussedTab
        return tab && tab.editor.ace
    },
    exec: function() {
        var tab = services.tabManager.focussedTab;
        require("ace/config").loadModule("ace/ext/static_highlight", function(m) {
            var editor = tab.editor.ace
            var result = m.renderSync(
                editor.getValue(), 
                editor.session.getMode(),
                editor.renderer.theme
            )
            document.body.style.display="none"
            var d = document.createElement("div")
            d.innerHTML=result.html
            document.documentElement.appendChild(d)
            require("ace/lib/dom").importCssString(result.css)

            setTimeout(function() {window.print()}, 10)

            function restore() {
               window.removeEventListener("focus", restore, false)
               d.parentNode.removeChild(d)
               document.body.style.display= ""
               editor.resize(true)
            }
            window.addEventListener("focus", restore, false)
            d.onclick = restore
        })
    }
}, plugin)

#4

thanks very much, this looks very promising, but i have absolutely no idea how this works. I tried cutting the snippet that you list here and executing it in my chrome browser console, but got an error “services undefined”…

where the heck does this snippet go and what specifically will it do? thanks for any context you can provide… :slightly_smiling: …david


#5

add it to init script https://cloud9-sdk.readme.io/docs/customizing-cloud9#section-quick-personal-hacks
then after reloading page open commands panel and choose print


#6

AWESOME…you made my day! because not only did you solve my immediate problem, but you pointed out a whole aspect of Cloud9 of which i hadn’t been aware. I have only been using C9 for a few days and have found it to be great, but this is even better! thanks again…david


#7

For future readers check out this plugin: https://github.com/shadowcodex/c9.ide.print


#8