Just to note, Atom does not print, neither does Visual Studio Code or Adobe Brackets, Vim does not print natively, neither does Emacs. So, Sublime Text is not that unique in not supporting printing.
Printing from sublime
I used Sublime Text as my single text editor. It also lets me code, but I donât only use it for that. If I open it to quickly write down a grocery list, instructions for something I need to do, or any other .txt document I have saved with similar content, I want to be able to print that out and take it with me. Like every other text editor in existence. Sublime Text shouldnât be a coding only utility when everything else about it makes it an excellent text editor - aside from this. Up until now, Iâve had to copy / paste between ST and Word.
Iâm taking a look at some alternatives now. But if ST is meant to not be a text editor in any way, it should advertise itself as only a programming tool. Alternatively, if the authors want it to be used as a text editor also, they need to include this basic feature thatâs part of every text editor.
I bought ST, as a text editor+, because I had stupidly assumed it would have the ability to print. I was completely shocked when I discovered it didnât.
Hereâs my solution, based on all of the posts I read. I couldnât get any of the plugin methods to work, but ended up with something âsimpleâ anyway. Iâm using Windows and I only care about direct text printing, without any kind of formatting - I just want to print the straight text from ST to my default printer.
- I downloaded DOSPrinter.
- I created Print.sublime-build in my Packages\User directory:
{
"cmd":
"C:\\Tools\\DOSPrinter.exe",
"$file"]
}
When I want to print, I just make sure Iâm using âPrintâ as my Build System and hit Ctrl-B.
Iâve been using Sublime Text 3 for over a year, and I think itâs great. The lack of the ability to print, however, is crazy for a high-quality commercial text editor. Iâd like to add a vote for âadd the ability to print in the next version in Sublime Text.â
Export To HTML works so well that this feature really isnât even needed anymore. I requested this years ago but ctrl-shift-p, typing export to html (or as many of those letters as you need before the command shows up) and hitting return isnât difficult.
I didnât know about the ExportToHTML extension. I just tried it, and it is indeed very good. It certainly makes a built-in print function seem like less of a priority for Sublime Text.
However, it still feels clunky compared to a simple File > Print (or cmd + P), and it generates temporary files every times you use it. And I think most people do expect a simple print feature in a text editor.
Someone above listed several free editors that canât print, and said that therefore a lack of printing is not unprecedented. However, many of the free editors people use before seeking out a more professional editor can print: OS Xâs TextEdit, Windows Notepad, Notepad++, or Linuxâs GEdit. Furthermore, I donât know of any paid editor in the price range of Sublime Text that canât print (for example, UltraEdit, which is also cross platform). Thus, most people are surprised to find they need to seek out a plugin to do something seemingly simple. Even though ExportToHTML is nice, I still think a $70 text editor should be able to print out-of-the box. It would feel so much more professional.
I have a similar feeling about having to manually edit the JSON settings files. Why isnât there a proper UI for settings?
Despite the long post, I consider these minor complaints. Sublime Text is awesome, which is why I went ahead and paid for it.
That is an assumption.
I have never had the desire to print text with Sublime Text, or any other âtext editorâ for that manner, and I am sure that I donât stand alone with this.
Youâre correct that I made an assumption. I havenât polled every user of text editing software to find out if more than half expect to be able to print. I apologize.
However, based on the number of people who have mentioned it in this thread, and the existence of numerous other threads about the feature, I think itâs fair to say that many people expect it, and I was simply adding my vote. I agree that itâs not a top priority; like most people, Iâd rather see bug fixes or performance enhancements, as I donât often print.
There have been a few times where I wanted to print, but it is honestly a pretty minor thing. The export to HTML feature is more than enough for my purposes.
I vote for printing from the file menu. I do use Export HTML, but I couldnât get it to work at first.
I had to resort to Ctrl-A, right-click, copy, bring up Notepad++, right-click, paste, then print.
I got tired of this, so I went back to Export HTML and finally got it to work. But itâs still a kludge.
I tried another printing package as well, but I never did get it to work.
I want the real thing. If UltraEdit and Visual Studio (et alia) have it, then Sublime Text should have it also.
Went to purchase, stopped when I realized no printing.
I hardly ever print, but heck if Iâm going to buy something that canât do it.
Given time Iâll implement one of the solutions posted here, butâŚ
I did the same thing as you. I was going to purchase this text editor because it has a good look and feel but then I saw that thereâs still no print option.
To the owners and operators of SublimeText, youâve left money on the table today and some other company that is willing to confront the difficulty of cross-platform printing is about to pick it up. Think about that the next time you look at your bank balance.
You played yourself!
I heartily agree that sublime needs this!
I bought it and use it to compose texts.
Having to copy to a second editor
to get a hard copy seems quite unreasonable.
It seems unhelpful to debate whether printing is a necessary feature, since the people who need it need it and the people who donât donât. But it does seem debatable whether the lack of a built-in printing capability is a good reason not to purchase Sublime Text. ExportHtml is described by many on this forum as an excellent plugin for exporting printable code to a browser while preserving syntax formatting. For those who primarily use Sublime Text for prose, I think the SublimePrint plugin is also very good.
It is worth remembering that plain text printing is an old problem with many solutions, at least in the unix world. Because Sublime Text is so easily extensible, it is not difficult to write a plugin that seamlessly transfers the job of printing, previewing and formatting to one of these tools. Examples of linux printing tools include enscript, gtklp, evince, okular, xpp.
Enscript - used in the SublimePrint plugin - transforms plain text to postscript with options for fonts, margins, headers, etc. Okular, evince, gtklp and xpp use a print dialog similar to that in a word processing program. You select a printer, choose duplex or single-sided, which pages to print, number of pages per sheet, etc. Evince and Okular also provide page preview before printing. Okular can convert your output to pdf and can then add annotations, color highlighting and underlining.
Hereâs an example of a simple experimental plugin - ExternalPrintPreview.py - that formats a text file with enscript and sends it to evince for previewing and printing. It may help those who need a print/preview capability in Sublime. (Let me know!) To run it, use a keybinding to trigger the âexternal_print_previewâ command:
import sublime
import sublime_plugin
import subprocess
import tempfile
class ExternalPrintPreviewCommand(sublime_plugin.TextCommand):
def run(self, view):
File_To_Print=self.view.file_name()
if not File_To_Print:
sublime.error_message("Oops!\n You need to save the file \n before you can print it.")
return
if self.view.is_dirty():
if not sublime.ok_cancel_dialog("Oops!\nUnsaved changes won't print. \nDo you want to cancel print?", "PrintAnyway"):
return
Tmp_File_Name = tempfile.NamedTemporaryFile(delete=False).name
try:
p=subprocess.Popen(["enscript", File_To_Print, ("--output="+Tmp_File_Name),
"--header=$n|%W|$%", "--header-font=Times-Roman10", "--font=Times-Roman12",
"--margins=40:40:70:70", "--word-wrap"], shell=False)
except:
sublime.error_message("Error running enscript")
return
p.communicate()
# evince below could be replaced by okular, xpp, or gtklp
try: subprocess.Popen(["evince", Tmp_File_Name], shell=False)
except: sublime.error_message("Error launching print preview")
This plugin requires that enscript and evince are installed (in directories on your PATH) and it complains if you havenât saved your document. It stores a temporary file. In the example above, Iâve hard-coded my enscript preferences for margins, fonts, headers and word-wrap; you can substitute whatever values you prefer. (âman enscriptâ for options.) While the above example uses evince for print preview, you can easily substitute âokularâ or one of the other programs. (Of course you need to install them first!)
If you want to start okular with a print dialog box - rather than in preview/viewer mode - the syntax is:
try: subprocess.Popen(["okular", "--print", Tmp_File_Name], shell=False)
If you donât want a print preview capability at all and just want a print dialog box, you can experiment with xpp or gtklp:
try: subprocess.Popen(["xpp", Tmp_File_Name], shell=False)
Or,
try: subprocess.Popen(["gtklp < "+ Tmp_File_Name], shell=True)
[See note below about shell=true]
Experiment with these options and you may find a choice that fits your needs and integrates seamlessly with Sublime.
Obviously these are linux-centric solutions. Enscript and evince are also available for Windows, but you should be aware that pythonâs Popen() wonât be able to launch these programs after you install them unless you explicitly specify their full paths. (So, instead of just using âevinceâ with Popen() as in the example above, you would need something like âc:\program files\a bunch of other stuff\users\etcetera\why is windows like this\evince.exeâ). You can use the Windows âwhereâ command to determine the full paths and names for these exeâs after installing enscript and evince.
If printing and previewing plain text files is a more or less trivial problem - at least under linux!- it shouldnât be an obstacle to purchasing what is an otherwise excellent product.
[Note about shell=true: gtklp wonât open a file specified on the command line unless the filename is piped to it, and that requires shell=true. This wonât create a good feeling in those who care about security, but the shell is being used here only with a temporary filename supplied by tempfile, so it should be safe. It would not be safe however to use shell=true in the first use of Popen above, where enscript is sent the name of the userâs text file. The problem is that you can create a file in Sublime with a name like âblah.txt |rm -f *â. Dangerous filenames like these include injected commands the shell can be induced to execute.]
Yes, but itâs âsophisticated.â We know this because the developer says it on their website. Therefore, itâs worth $70 premium over the free competition.
As someone who came from Notepad++ (as you mentioned you were moving to in your other post), a cross platform, easily extendable, feature rich (minus printing), fast editor is well worth $70 dollars to me. Notepad++, while fine, I find clunky, more difficult to extend, and Windows specific. As someone who codes on multiple platforms, one license to run on my different machines is amazing.
To each their own though, but we get it, printing is your deal breaker.
copy con > lpt1
hmm oops cannot do that anymore âŚ
yes, +1, please add printing feature.
Count me in for wanting printing as well. Is this something an intern can implement over summer?