Printing PHP with Eclipse

18.09.2009 | PHP

Printing with Eclipse can be very annoying, mostly fonts are too big and syntax highlighting is not available yet.

A simple solution is to configure enscript as an external tool. Since it took an annoying time-consuming process to make enscript print "pretty" php pages out of my macbook, I want to share my work here so it may help you saving time.

Fortunately MAC OS X 10.5+ comes with enscript ready to go. Though the default settings are not sufficient to print php with syntax highlighted, you need to install a php.st file first. Then it is recommended to adjust the colour settings in enscript.st.On my printer (Canon IP4200) it took some trial and errors to produce pages with readable colours.

Download my php.st file

 with the syntax highlighting definition and copy it to the location:


/usr/share/enscript/hl

If you run into problems with the default colours, you may try my enscript.st file or copy my colour definitions into your enscript.st.

/* RGB definitions for colors. These are borrowed from X's rgb.txt file. */

define_color ("black",   0, 0, 0);
define_color ("gray25",   64, 64, 64);
define_color ("gray50",   127, 127, 127);
define_color ("gray75",   191, 191, 191);
define_color ("gray85",   217, 217, 217);
define_color ("gray90",   229, 229, 229);
define_color ("gray95",   242, 242, 242);
define_color ("blue",   0, 0, 255);
define_color ("cadet blue",  95, 158, 160);
define_color ("dark goldenrod",  184, 134, 11);
define_color ("dark olive green", 85, 107, 47);
define_color ("firebrick",  255, 31, 37);
define_color ("forest green",  34, 139, 34);
define_color ("green",   0, 255, 0);
define_color ("orchid",   218, 112, 214);
define_color ("purple",   160, 32, 240);
define_color ("red",   255, 0, 0);
define_color ("rosy brown",  188, 143, 143);
define_color ("magenta",  128, 0, 128);

define_color ("DarkSeaGreen",  143, 188, 143);
define_color ("DarkSeaGreen1",  193, 255, 193);
define_color ("DarkSeaGreen2",  180, 238, 180);
define_color ("DarkSeaGreen3",  155, 205, 155);
define_color ("DarkSeaGreen4",  105, 139, 105);
define_color ("Goldenrod",  237, 218, 116);
define_color ("Aquamarine",  67, 183, 186);
define_color ("SeaGreen2",  7, 170, 44);
define_color ("Coral",   247, 101,  65);
define_color ("DarkSlateGray1",  154, 254, 255);
define_color ("LightGrey",  211, 211, 211);

I changed the default colour style (style_emacs.st) as well.

Now, configure eclipse to print with enscript: Run->External Tools -> External Tools ConfigurationsThen click on the "New"-button to create a new configuration.Name it "Enscript Print PHP" or something like this. Fill out the form like shown below.

You may adjust the arguments section to fit your needs,


-f=Courier@8
-C
-Ephp
--color
-PCanonIP4200
${resource_loc}

-f <your font settings>-P<your Printer>-C //prints line numbers-Ephp //prints with php syntax hightlighting--color //enables coloured syntax highlighting${resource_loc} // an eclipse variable to tell enscript to print the current eclipse file

Hope this helps.