How do I easily write and syntax hightlight PHP (or any other language really) code in a Word 2009 document?
feedback
|
|
You can use Notepad++ to accomplish this in three ways. Just so you know, Notepad++ is a more advanced version of Notepad, which supports syntax highlighting of different code files "out of the box" - PHP included! Download & install it, fire it up, and load up your PHP file. You should automatically see it beautifully coloured (if not, because the file extension is something other than If you need to change any of the colours, you can easily do so - just go to Settings -> Styler Configurator. From that menu, you can change the various highlighting and font options, to suit your needs - although the default usually suffices for most. Then, go to Plugins -> NppExport. From there, you have three options you can consider:
Start with the last one - "Copy all formats to clipboard" - which will copy the entire file with the highlighted syntax to the clipboard. Once you click it, then open Microsoft Word, and just hit paste! You should see the beautifully syntax-highlighted code. If something goes wrong, then you can try one of the other options (export to RTF/HTML), although I've never had a problem with the clipboard method. | |||||||||||||
feedback
|
|
Send your code to an online syntax highlighting website, this one for example (select the langage yourself, Autodetect doesn't work very well). There is a list of other online syntax highlighting site here. Copy the highlighted code and paste it into Word. | |||||||||
feedback
|
|
You could install the .PHPS file type into Apache then copy the output from your browser into Word. in your http.conf
| |||||
|
feedback
|
|
Without manually creating character styles for each element of the language and applying them manually, you can't. Your best bet is to take a screenshot in a editor that does do syntax highlighting and insert that into your document, or copy-and-paste the already colourful code from another program (perhaps a paste bin) and paste it into Word and hope that the colour formatting gets preserved. | |||
feedback
|
|
Syntax highlighting many languages in Word documents: http://www.planetb.ca/2008/11/syntax-highlight-code-in-word-documents/ | |||
|
feedback
|