How to print a file from VsCode?

PrintingVisual Studio-Code

Printing Problem Overview


I want to send the file I'm currently editing to a printer, like I did in Notepad++ for example. I havn't found any hint on a print command. Is it not possible ?

Printing Solutions


Solution 1 - Printing

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:

Solution 2 - Printing

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.

Solution 3 - Printing

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.

Solution 4 - Printing

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.

Solution 5 - Printing

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

Solution 6 - Printing

You can use an Extension of VS Code: PrintCode

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

Solution 7 - Printing

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEric Bole-FeysotView Question on Stackoverflow
Solution 1 - PrintingEric Bole-FeysotView Answer on Stackoverflow
Solution 2 - PrintingSL ARTView Answer on Stackoverflow
Solution 3 - PrintingPeter WoneView Answer on Stackoverflow
Solution 4 - PrintingAndrés PeñaView Answer on Stackoverflow
Solution 5 - PrintingmosaicView Answer on Stackoverflow
Solution 6 - PrintingSilvia42View Answer on Stackoverflow
Solution 7 - PrintingChristian SchindlerView Answer on Stackoverflow