CKEditor print CSS

by oleq

HTML

<script src="http://cdnjs.cloudflare.com/ajax/libs/ckeditor/4.2/ckeditor.js"></script>
<textarea id="editor">Hello!</textarea>

JavaScript

CKEDITOR.replace( 'editor', {
    plugins: 'toolbar,wysiwygarea,sourcearea,print,basicstyles',
	on: {
		contentDom: function() {
			var doc = this.document,
				head = doc.getHead();

			// Via <link> tag.
            doc.createElement( 'link', {
            	attributes: {
                    rel: 'stylesheet',
                    type: 'text/css',
                    href: 'print.css',
                    media: 'print'
            	}
            } ).appendTo( head );

            // Via <style> tag.
            var style = doc.createElement( 'style', {
            	attributes: {
            		type: 'text/css'
            	}
            } );

            style.setText( '@media print { * { color: red } }' );

            style.appendTo( head );
		}
	}
} );