Sublime Forum

Printing from sublime

#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

#141

My 2 cents: I would rather sublime stays as fast and performant as it is. To me, that is it’s key feature.

If someone could make a plugin to do this I think that would be okay, but I could do without all the possible problems and extra processing that might be associated with supporting printing to hardware,

0 Likes

#142

A low priority for you but not for your customers. Please escalate.

1 Like

#143

I was thinking of using sublime text 3 as my default editor and purchase it…
No print - nah thanks.
even kate or leafpad or whatever gui text editor on linux does print.
I tried Simple print function for Sublime Text 2 and 3… no way couldn’t make it work

0 Likes

#144

Windows solution for printing in Sublime Text

This is a simple, effective, and versatile solution that uses the Build feature. No enscripting needed!

  1. Download printText.exe. This program will print a text file whose path is specified on its command line. The program prints only saved files; unsaved changes will not be printed.

  2. Since Sublime Text cannot directly call this program, create printText.cmd as follows, but add the full path to printText.exe.

    START "Printing %1" "printText.exe" "%1"

  3. Copy the following text into \Data\Packages\User\Print2.sublime-build (a new text file that you create) in your Sublime Text directory, but add the full path to printText.cmd. When you add the full path, convert ‘’ to ‘\\’ (double backslashes) in the path.

     {
         "windows":
         {
             "cmd": ["printText.cmd", "$file"]
         }
     }
    
  4. In Sublime Text, select Tools > Build System > Print2

  5. Add the following line to the User file in Preferences > Key Bindings, so that you can print with CTRL-P.

    { "keys": ["ctrl+p"], "command": "build" },

Pressing CTRL-P will then run your new “Print2” build file, which will send the to-be-printed file’s path to printText.cmd. The CMD batch file will then send the file’s path to printText.exe, which will print the file.

That’s it!

Mike

0 Likes

#145

Why is there no print facility within Sublime?
I do not understand why this most basic feature is not included.

0 Likes

#146

because 99% of ST users don’t want the ST devs to waste their time on something they will never use, and for which plugins exist that do a decent job anyway

1 Like

#147

It seems like over the last 9+ years in spite of several requests, chime ins, +1s, this isn’t really a feature that might take any sort of priority. At least care to say, we’ll NOT implement this so it spares some time for people who are looking for it and will look for it elsewhere. Even Notepad (which imho nobody uses as a text editor) has this option.

0 Likes

#148

It has actually been stated by Jon already that this isn’t an area they wish to focus on. People just keep creating new threads.

2 Likes

#149

Note to developers:
The lack of a print feature caused my team to rule this out as an editor.
250 developer licenses lost to one bad decision.

_O_/

1 Like

#150

And how many people would have picked a different editor if we spent time on printing instead of Goto Symbol in Project, or Goto Definition popup, or decent syntax definitions, or proper support for Windows high DPI.

Saying yes to one feature means saying no to one or more other features. In this case, the work of trying to make cross platform printing “just work” is significant enough and the priority low enough that we’ve chosen to work on other aspects of the editor.

It seem we aren’t the only ones: 1, 2. Meanwhile, plenty of people have pointed to packages that provide a mechanism to allow for printing.

9 Likes

#151

No worries. Clearly, there are other companies who are more than happy to have more paying customers and provide all of the core functionality developers are looking for.

1 Like

#152

What I find “funny” in this “conversation” is that not one of the people requesting the print feature can explain why they refuse to use the Export to Html plugin which works perfectly fine …

5 Likes

#154

Here’s an explanation of why I “refuse” to use the Export to Html plugin…

I’d love to use Export to Html. I fought for a long time to get my company to buy me ST3. When I finally convinced them all the features I needed in a text editor could only be found in ST3 and it was finally installed, its was locked down for security reasons so I couldn’t install any plugins! There are a number of plugins I would love to add to my copy, but none are available to me.

I understand:

  • Some people don’t need to print
  • I could always copy the text into another editor to print
  • Adding printing to ST3 is a non-trivial process

But, being lazy and having a locked-down version of ST3, it would be nice to have basic printing.

2 Likes