Skip to main content
Participant
April 18, 2024
Question

Formatted Java and Python code in a document?

  • April 18, 2024
  • 3 replies
  • 660 views

Does anybody have a good workflow for getting code from github into a printed document with InDesign? We really need to preserve:

  • Syntax colors
  • Tabulation
  • Line numbers

 

I am hoping somebody has solved this problem, because my Google searches have come up empty.

 

E.g. This Python from github. https://github.com/jamesabela/Python-RPG-Tutorial/blob/master/Object%20Oriented%20Monsters.py  Will also need to do the same for Java too.

This topic has been closed for replies.

3 replies

pixxxelschubser
Community Expert
Community Expert
April 21, 2024

A few years ago I tried to create a "Photoshop javascript formatting" in InDesign CS 5 using grepstyles, but never finished. It's quite complex, but it should be possible.

 

 

 

leo.r
Community Expert
Community Expert
April 20, 2024

In addition to Robert's suggestions, you may want to try to open the code in a dedicated developer tool - Xcode, VS, GitHub Desktop etc. - and export/print to PDF, then place PDF in InDesign. 

Participant
April 21, 2024

This is the best solution I've found so far! Thank you. 

James Gifford—NitroPress
Legend
April 21, 2024

If you need something like live text — e.g. not a snapshot of the best display you can get, capture and crop from a code editor — it seems like one of the many code formatter/highlighters could be adapted to make their output 'stable' — that is, actually apply a color span to certain elements instead of doing it only as a realtime display highlight.

 

That could be a tool/asset worth developing beyond your own needs, as well.

Robert at ID-Tasker
Legend
April 18, 2024

It's dynamically formatted by CSS - so there is no "physical" formatting info...

 

You could probably use GREP Styles option in the ParaStyle definition - or apply CharStyles to specific words / characters.

 

Found this:

https://github.com/Microsoft/vscode/issues/3518#issuecomment-253674097

 

For those who want an interim solution, look at Notepad++'s NppExport plugin (Copy HTML to clipboard)

 

Participant
April 21, 2024

Thanks, I'll give this a go.