Sublime Forum

Printing from sublime

#121

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.

3 Likes

#122

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.

0 Likes

#123

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.

  1. I downloaded DOSPrinter.
  2. 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.

0 Likes

#124

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.”

0 Likes

#125

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.

2 Likes

#126

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.

0 Likes

#127

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.

3 Likes

#128

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.

0 Likes

#129

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.

0 Likes

#130

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.

0 Likes

#131

Being able to print or print to pdf would be equally amazing :slight_smile:
You got my vote !

0 Likes

#132

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…

0 Likes

#133

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!

0 Likes

#134

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.

0 Likes

#135

I would buy if the app supported printing.

0 Likes

#136

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.]

6 Likes

#137

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.

0 Likes

#138

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.

4 Likes

#139

copy con > lpt1

hmm oops cannot do that anymore …

yes, +1, please add printing feature.

0 Likes

#140

Count me in for wanting printing as well. Is this something an intern can implement over summer?

0 Likes