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. ?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Seasoned
  • 46
  • 1
  • 5

4 Answers4

3

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
  • 19,171
  • 16
  • 68
  • 83
  • AND the cute little colors (usually). They even show up in Outlook. – amischiefr Sep 18 '09 at 17:54
  • 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 Sep 19 '09 at 15:21
1

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.

Paul Jowett
  • 6,513
  • 2
  • 24
  • 19
1

You can just copy and then paste it to the word document. I am using OS X as well. I just works fine. I am uploading the screenshot of how it looks in word.

enter image description here

Subash
  • 7,098
  • 7
  • 44
  • 70
0

I'm using Easy Code Formatter as called out here: How do you display code snippets in MS Word preserving format and syntax highlighting?

It's an Office add-in. You can select multiple themes, enable / disable line numbering / highlight lines in rectangles. It allows you to select the coding style / and has a quick formatting button. Pretty neat.

Requires you to have Office 2013 or beyond.

enter image description here

Mavi Domates
  • 4,262
  • 2
  • 26
  • 45