I need to write a report which may contain some Java code pieces. I need the code to appear colored and line numbered. How can I do this ?
5 Answers
Go to http://hilite.me/ and copy from the preview pane directly to word (tested with MS Word2007). Supports line numbering, but not well. Quite good for snippets.

- 707
- 10
- 14
One way is to copy & paste directly from Eclipse. It preserves all the color formatting.

- 158,255
- 15
- 216
- 276
-
But what about line numbering ? – Jury A Aug 11 '12 at 12:46
-
Sadly Eclipse displays but does not copy line numbers. – Reimeus Aug 11 '12 at 12:52
-
I initially try Selecting All the contents from my Java file in Eclipse and didnt work. I copied only class information and no imports (Like around ~100 lines) and it worked. Microsoft Word 2011 – gogasca May 03 '16 at 08:24
-
Works for Intellij IDEA too :) – Mate Šimović Mar 25 '17 at 15:02
- Well you can directly copy the things from an IDE
to your Word Document
.
- And please make sure that you have switched on the Line Numbering
of the Editor in the IDE
before copying the code.

- 33,294
- 6
- 48
- 75
try to use this: http://quickhighlighter.com/
select with the line numbers copy and paste
You can also use another online formatting tools, (http://stackoverflow.com/questions/206441/online-code-beautifier-and-formatter) but if you want the coloring to work after inserting to a word document, the highlihted source code html source must be inline styled.

- 3,927
- 3
- 18
- 14
You can copy with colors, but first you have to open all fold otherwise colors gone.
Line numbering copy is not working from Eclipse.
Explanation with example: https://cmanios.wordpress.com/2012/03/08/copypaste-source-code-from-eclipse-to-microsoft-word/

- 7,254
- 5
- 39
- 54