I think that it would be well worth your time to explore the Python Sphinx-Doc infrastructure but for just what you asked for you could simply use Pygments & rst2pdf:
With a python 3 installation you can simply pip install rst2pdf Pygmments rst2pdf will also install ReportLab.
Pygments is a syntax highlighting package written in Python.
It is a generic ...
have you tried : FreePDF for Windows - A simply and free virtual PDF printer
I have been using this for >10 years.
It will install a printer service(i.e. virtual printer) and if you click on menu-> printer(e.g. word or any), it will pop-up as a real printer and print your content ...
A home rolled solution using Python 3.8 & ReportLab (with thanks to Michael Driscoll for his book ReportLab: PDF Processing with Python which I referred to to do this):
Once you have python installed, if it isn't already, pip install pillow reportlab to get the required libraries then, in a python shell or a script:
You can use the command line tool, docx2pdf to batch convert word documents to pdf on Windows or macOS: https://github.com/AlJohri/docx2pdf
pip install docx2pdf
Disclaimer: I wrote this tool.