如何从 VsCode 打印文件?

我想把当前正在编辑的文件发送到打印机,就像我在记事本 + + 中做的那样。 我没有找到任何关于 print 命令的提示,这不可能吗?

67049 次浏览

It is not yet available, but I found an issue report for that feature.

It's currently in the backlog, so we can expect it soon.

https://github.com/Microsoft/vscode/issues/5953

Edit: In the meantime:

Now you can install addon for VS Code - search "PrintCode".

Note that the repository for this extension was last updated in February 2018 with numerous issues outstanding.

I found the PrintCode extension inspiring but unfinished and with a number of flaws. In particular it depends on a specific paper size to wrap and as a result does not respond well if you change paper size or orientation in the print dialog.

It's open source so I looked at the code and didn't like that either. No programmer ever likes another's coding style. So I pinched the idea of using a web-browser as platform driver for HTML printing -- my hat is off to the PrintCode author for that cunning insight -- and wrote my own.

In the process I fixed all the known bugs, added everything on my wishlist and a couple of things suggested by others. The biggest thing was figuring out the CSS required to respect print dialog paper size and orientation. This also sorts out the mysterious disappearing line numbers problem, although I'm not sure why. The next biggest thing was learning to probe for an unused port, a problem that also afflicts PrintCode causing the browser to open showing no content.

Major issues

  • PrintCode depends on a web service. You can't use it offline.
  • Many people want to be able to open a file, select a portion and print just the selection.
  • The print dialog supports changing paper size and orientation. This clashes with the way PrintCode works.
  • Some people like to run multiple VS Code windows.
  • When you print a markdown file, you probably don't want it printed like a text file when it can be rendered with fonts and proper headings and bullets etc.
  • Support is required for remote workspaces.

Because each instance of VS Code needs a different port for its embedded webserver, you can't just use a setting. Dynamic port allocation is necessary.

Remote workspaces weren't even a thing until two years after maintenance ceased on PrintCode.

If you want to survey your options, get onto https://marketplace.visualstudio.com, choose the Visual Studio Code tab and search for printing.

If you just want a link to my version, it's here http://marketplace.visualstudio.com/items?itemName=pdconsec.vscode-print.

If you like what you see but need something I haven't thought of, the marketplace page has a link to the repo on github. Create an issue and tell me what you need -- or write it yourself and submit a PR.

Poor man's answer: Copy code to Notepad2 or Notepad++ and print from there. The colour coding will be different though

Now there is an extension available for printing from the VS Code Editor. It's called VS Code Printing Free. I've tried it for a couple of days and it works fine.

You can use an Extension of VS Code: PrintCode

  1. Install extension PrintCode
  2. On Mac: command + shift + P
  3. choose command> PrintCode

I have modified the https://marketplace.visualstudio.com/items?itemName=pdconsec.vscode-print. If you change the values that I have marked in the picture in the extension settings a browser tab opens with the you can then print this also works on the Ipad. It works also with the code-server Version inside a Docker Container. I put the file on github https://github.com/chrishdx/vsc-print

enter image description here