Here is another way. I created Python code to generate a PDF file with syntax-highlighted source codes from a given folder.
python3 print_code.py --source_folder ~/Documents/model_code --output_folder ~/Documents --file_extension 'spthy' --syntax_language 'cpp'
Check the requirements to run the code at https://github.com/mohitWrangler/source-code-to-pdf