6

How can I print source code in OS X (HTML/PHP) with number lines and without long line truncation? I was used to Gedit on Linux, but here it seems I can't obtain the same with applications such as TextWrangler or TextEdit.

9

You can print source code with line numbers and without truncation in TextWrangler, the key is Soft wrap text.

  1. Turn on "Soft Wrap Text" under Text Options.

  2. Open TextWrangler > Preferences

  3. Select "Text Printing" then check the "Print line numbers" checkbox.

  4. Print again, long lines should wrap and line numbers should be present.

Note: you may want to set up "Editor Defaults" in TextWrangler's Preferences, and have it Soft wrap text for you for each file you edit, and to a specified width too.

| improve this answer | |
4

enscript can be installed via Homebrew and used via Terminal. Start with

enscript -CG2rE -U2 my-source-file.PHP

and read the (extensive) man page for additional features.

| improve this answer | |
  • Presumably you need to find and install this, because it's not in my path on OS X. – Oliver Bock Aug 4 at 3:47
  • @OliverBock Indeed. Thanks for pointing this out. – nohillside Aug 4 at 7:34
1

Have you looked at GeSHi? http://qbnz.com/highlighter/demo.php

You didn't specify the purpose for printing out - but I use this to "prettify" any code I expect to be printed - it does line numbering and syntax highlighting for a wide range of languages.

Hope this helps!

| improve this answer | |
1

TextWranger is the best on Mac OS when it come to printing out source code.

Step 1

enter image description here

Step 2

enter image description here

Step 3

Then, there is one more settings, click on gear icon on the top left

enter image description here


Amazing Result

Color, Line numbers, just neat and clean ...

Here is a screen of my PDF to show to you guys

enter image description here

Enjoy !!!

| improve this answer | |
1

for Catalina, you must use BBedit (textWrangler is not compatible with Catalina) so:

enter image description here

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .