Eric Bole-Feysot
Eric Bole-Feysot

Reputation: 15097

How to print a file from VS Code?

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 ?

Upvotes: 133

Views: 128052

Answers (9)

user3077654
user3077654

Reputation: 39

Install the "print" extension, then right-click and choose print.

The "printCode" extension is deprecated.

Upvotes: 0

Eric Bole-Feysot
Eric Bole-Feysot

Reputation: 15097

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

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

Support to print the editor contents #5953

Edit: In the meantime, you can use this extension:

Upvotes: 80

Peter Wone
Peter Wone

Reputation: 18739

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 Visual Studio Marketplace, choose the Visual Studio Code tab and search for printing.

If you just want a link to my version, it's here:

Print - by PD Consulting.

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.

Upvotes: 26

Audwin Oyong
Audwin Oyong

Reputation: 2556

PrintCode has been deprecated. We can now use Print extension which include a nice icon button on the file, which generates the code output with file name and line numbers, which are neat.

Upvotes: 2

Christian Schindler
Christian Schindler

Reputation: 1

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

Upvotes: 0

Silvia42
Silvia42

Reputation: 129

You can use an Extension of VS Code: PrintCode

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

Upvotes: 0

SL ART
SL ART

Reputation: 561

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.

Upvotes: 46

Andrés Peña
Andrés Peña

Reputation: 93

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.

Upvotes: 7

mosaic
mosaic

Reputation: 119

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

Upvotes: 5

Related Questions