views:

950

answers:

2

I need to format java code to put into a Word document. Are there any programs that will do this with keyword highlighting, etc. ?

+2  A: 

When I copy/paste from my IDE (Eclipse), the formatting comes along for the ride.

You'll probably want to turn off "Mark Occurrences" first.

Jeremy Stein
AND the cute little colors (usually). They even show up in Outlook.
amischiefr
Hm. It doesn't seem to work for me, but I'm on OS X. I will have to try it on Windows.Ideally I'd like something that can do it for an entire project so I don't have to copy and paste every single file. Any suggestions there?
Seasoned
A: 

This is a late reply but since it's quite a specific requirement I'll post my comment anyway.

You can do this programmatically with Docmosis assuming you want the program to be running in Java (not just showing java in documents) and can install OpenOffice where the program runs. The process would be:

  1. Create a doc or odt file that will act as a template (setting fonts, position, tables etc) and will have a placeholder for where you want to insert the code sample
  2. Add docmosis to your java project and write the code to initialise Docmosis, register the template, then render document with your selected Java code.
  3. Currently, Docmosis FieldRenderers can underline or italicize your data as it goes, but the rendering is currently applied to the entire field. So this wouldn't let you have a single field for all your java text and individually highlight words, but there are a few other tricks that you could employ to get useful/interesting results (such as splitting your data into separate fields and letting Docmosis render the fields differently).

The "java code" text that you specify as data will be inserted into your template using the font and layout properties in the template. The renderer will have a chance to override specific formatting.

jowierun