Have you tried the plugin https://packagecontrol.io/packages/ExportHtml ? Why it isn’t enough for you?
Printing from sublime
Of course I tried this plugin and this is the best (and working) solution for this purpose. But this is only a workaround (printing from TEXT EDITOR through creating html file and open and print it from web browser) and this is my point.
Guys, I don’t argue with you. I am not a helpless child, I can handle text printing, even without ExportHTML plugin. Why can’t I be disappointed that the paid text editor (my favourite one!) doesn’t have printing as standard?
I agree we should be green in our practices. A “print” option to me provides a means to change the medium the text is inhabiting. I use print to PDF functionality all the time. Allows for code to be placed in a doc that may have passwords associated with it for sharing between other developers/product management/legal, and others not necessarily in the actual code changing business. (The PDF keeps the code relatively safe from being immediately called up into a .c, .tal, .cpp, … code editor and changed. Seems to me any application that produces a product should allow for said product to be “Exported” for use by other applications (other than SAVE). There are work arounds of course … Sublime is my editor of choice, its always open and use it for bulk code writing. I do find it odd the resistance to add a feature that has been done to death and pretty much standardized has been going on for over a decade. At least write a plugin that is up to the quality of the rest of the application. I have not found one to provide the typical options for printing, scaling, orientation, …
Holy Smoke - I just came to the forums looking, yet again, for any signs of development life (the last dev build I see via:
http://www.sublimetext.com/3dev
is build 3210 dated 24 September 2019.
Where are you seeing your information about build 4092?
OK - I was just too excited. I didn’t need to ask here, a simple Google search got me what I needed.
Looks like you missed the switch to v4 … Latest dev build is 4131 from 25 March 2022: http://www.sublimetext.com/dev
I cannot print from Sublime Text. What does ‘which prints via a browser’ mean? What do you have to set up?
I still don’t understand why printing is difficult to code in Sublime Text. Every other text editor can do it.
I cannot print from Sublime Text.
It has to be more descriptive. Just like you won’t be satisfied if my reply is “it works for me”. We don’t even know what you’ve tried, how you tried.
What does ‘which prints via a browser’ mean?
It generates a HTML file and then open a browser to print it.
What do you have to set up?
For me, literally nothing.
Not a direct answer but probably related.
bschaaf — 2020/06/05 00:52
If it was easy I’d have done it already It’s probably not too hard to get to the point where we’re able to print something across multiple platforms, but that’s the easy part. There’s pagination, page sizes, font sizes, margins, colors for syntax highlighting (CMYK is very different), page numbers, a preview of how the print will look and probably a laundry list of other stuff people expect from printing.
OK. Here is a maximally descriptive summary.
I have any open document. I choose Print from the File menu. Nothing happens. No browser opens and no page in any open browser appears. That’s it. Windows 11, Insider Preview build, Sublime Text version build 4143.
I can’t add anything more because there is no more to add.
I am on Win11 22H2 and it works fine with Firefox installed and setup as default browser.
ST creates a temporary HTML in %TEMP%
and opens Firefox with print dialog open.
Tried with ST4107, 4126 4143 and 4150 successfully.
Maybe something’s wrong with OS level default browser configuration?
I do not know if errors, but this is all I see:
reloading plugin Diff.diff
reloading plugin HTML.encode_html_entities
reloading plugin HTML.html_completions
reloading plugin ShellScript.ShellScript
plugins loaded
It creates temp files in %TEMP% I now see but does not open the browser, which I have set to Firefox using the Default Apps settings.
This is on Windows 11 Insider Preview. Perhaps we cannot expect it to work.
You could try setting the settings "print_using_browser"
to firefox
, but it should be using the default browser. Note we use the python webbrowser module to open a new tab.
@bschaaf Here is what I get:
Traceback (most recent call last):
File "C:\Program Files\Sublime Text\Lib\python38\sublime_plugin.py", line 1703, in run_
return self.run(edit)
File "C:\Program Files\Sublime Text\Packages\Default.sublime-package\html_print.py", line 19, in run
File "./python3.8/webbrowser.py", line 65, in get
webbrowser.Error: could not locate runnable browser
using:
"print_using_browser": "firefox"
MS does its best to force users to Edge browser. Maybe that’s involved in default browser not being found.
I have MSEdgeRedirect
installed to force Win to use Firefox. Maybe this makes a difference.
You could try to add Firefox folder to %PATH% environment variable. Maybe python’s webbrowser
module is able to locate and run it then.
Success at last. Combining ideas from all the posts, and reading up on the python webbrowser module, I added this to the preferences settings file:
"print_using_browser": "firefox"
Then I added the path for firefox to the Windows PATH variable:
C:Program Files\Mozilla Firefox
A reboot, and printing now works. I hope this may be useful to people in the future.
Print and open browser problem
DEFINITELY, I reckon it would be really useful for printing to open the printing preview to print to .pdf