makerjackie
I find that nbviewer.jupyter.org can convert .jpynb to html, but it only support single jpynb file. So how can I convert the whole repo into a pdf which is more easy to read.
#10 · closed · 2 comments
I find that nbviewer.jupyter.org can convert .jpynb to html, but it only support single jpynb file. So how can I convert the whole repo into a pdf which is more easy to read.
```python import os import nbconvert from future import print function folders = ['01-python-tools', '02-python-essentials', '03-numpy', '04-scipy', '05-advanced-python', '06-matplotlib', '07-interfacing-with-other-languages', '08-object-oriented-programming', '09-theano', '10-something-interesting', '11-useful-tools', '12-pandas' ] mdtxt = open("README.md", encoding="utf8").read() i = 0 for folder in folders: for file in os.listdir(folder): if file.endswith(".png"): open(file.replace(".png", "temp.png"), "wb").write(open(os.path.join(folder, file), "rb").read()) if not file.endswith(".ipynb"): continue i += 1 path = os.path.join(folder, file) print(path) converted = nbconvert.export(nbconvert.MarkdownExporter, path) markdown = converted[0].replace(".png", "temp.png") pics = converted[1]["outputs"] for pic_name in pics: picpath = pic_name.replace(".png", "temp.png") if (os.path.exists(picpath)): markdown.replace(picpath, picpath.replace("temp.png", str(i) + "temp.png")) picpath = picpath.replace("temp.png", str(i) + "temp.png") with open(picpath, "wb") as p: p.write(pics[pic_name]) mdtxt += markdown open("final.md", "w", encoding="utf8").write(mdtxt) # open Atom markdown-preview and save as html # open html in chrome and print to pdf # or other method to convert md to pdf ``` ```python os.remove("final.md") for file in os.listdir("."): if file.endswith("temp.png"): os.remove(file) ```
thx! it works. But in final.md, it have lots of lines of "hello world", so I delete it. I used vscode extension "Markdown PDF" to convert markdown to pdf