4

I have a project I finished, and one requirement is adding all of the code to a Word Document, doing it manually will take hours since I have multiple Python files, each with at least 200 lines.

Is there a way to export them (with the syntax highlighting) to images so I can do it quickly, and be able to add them to the Word Document?

  • You can try taking a screenshot to keep the syntax highlighting. – RedRaptor Apr 26 '22 at 06:23
  • Yes I know but I'm trying to avoid doing so, because as I said doing it manually will take hours since I have multiple Python files, each with at least 200 lines – Noamiko2004 Apr 26 '22 at 06:24
  • Does it have to be saved as words in the word document. – RedRaptor Apr 26 '22 at 06:31
  • No, it can be photos and I think it's even preferred, but the syntax highlighting is important. (Python syntax) If the syntax wasn't important I would turn the code into a pdf file and turn that pdf file to images. – Noamiko2004 Apr 26 '22 at 06:32
  • If you take one screenshot of 30 lines in each 3 seconds, in 20 min you can take 400 screenshots containing 12000 lines of code. Is your codebase bigger than that ? – joaopfg Apr 26 '22 at 06:35
  • I cant think of any way to do what you are asking for but to take screenshots of the code and add the photos to the word document – RedRaptor Apr 26 '22 at 06:38
  • Windows 7 builtin screenshot application would work perfectly for this. – RedRaptor Apr 26 '22 at 06:43
  • I'll try a Visual Studio Code extension someone here recommended, and if that doesn't work I think I'll create an AHK script to scroll and take screenshots. – Noamiko2004 Apr 26 '22 at 06:47
  • If you copy-paste the code programmatically into a wordpad process the syntax highlight information will be retained with the exact colors. – bad_coder Apr 26 '22 at 09:17

2 Answers2

1

As I said in the comments, if you take one screenshot of 30 lines in each 3 seconds, in 20 min you can take 400 screenshots containing 12000 lines of code, which might be enough for many projects .

But if you really want to automate it, one idea can be to write a python file that read the files in your project recursively and at each fixed number of lines write the content to a .txt file with a name like file_n.txt, where n is increasing. Then, you convert all the .txt to images programatically using pillow.

joaopfg
  • 1,227
  • 2
  • 9
  • 18
  • 1
    I'll try a Visual Studio Code extension someone here recommended, and if that doesn't work I think I'll create an AHK script to scroll and take screenshots. – Noamiko2004 Apr 26 '22 at 06:47
  • Sounds like an interesting small python package to write :) you can even let it pip installable . I can try it in my free time – joaopfg Apr 26 '22 at 06:50
0

Not in pycharm but in Virsual Studio Code, there is and extension called CodeSnap, maybe just open your project from vscode then take clean screenshots of your code from there.