-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to convert this repo to a book/pdf #10
Comments
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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The text was updated successfully, but these errors were encountered: