我想要 pdf 版本的 TensorFlow 文档,因为 pdf 更方便阅读和注释。
有similar question这已经过时了。
这是source file TF 文档。我还没有找到 pdf 生成脚本。我们可能会尝试将 md/ipynb/html 转换为 pdf,这有点麻烦。
有没有更直接、方便的方法呢?谢谢!
最佳答案
我写了一个可以生成pdf的脚本,但仍然存在一些问题,例如TOC。
结果 pdf 在这里:https://github.com/hxsnow10/tensorflow_doc_pdf
HTML 生成
# change a diractoy of md and ipynb to html
import os
import pdfkit
import markdown
in_dir = 'site/en/tutorials' # this will be relative_path"
out_dir = os.path.join("html", in_dir)
out_html_path = os.path.join(out_dir, "index.html")
out_images_path = os.path.join(out_dir, "inages")
cmd = "rm -rf {} ; mkdir -p {}".format(out_dir, out_images_path)
os.system(cmd)
cmd = "echo '' > {}".format(out_html_path)
os.system(cmd)
files_txt = []
for root, subFolders, files in os.walk(in_dir):
# copy image to prevent relative path miss
if 'images' in subFolders:
path = os.path.join(root, 'images')
m_files1 = os.listdir(out_images_path)
m_files2 = os.listdir(path)
if set(m_files1) & set(m_files2):
print 'BADLLY IMGES', m_files1, m_files2
# better to recursive merge
cmd = "cp -rf {}/* {}".format(path, out_images_path)
os.system(cmd)
nb_file_paths = [os.path.join(root,filename) for filename in files if filename.endswith('.ipynb')]
md_file_paths = [os.path.join(root,filename) for filename in files if filename.endswith('.md')]
print "md_files = " , md_file_paths
for file_path in md_file_paths:
out_path = file_path[:-3]+'.html'
markdown.markdownFromFile(
input=file_path,
output=out_path,
encoding='utf8'
)
cmd = "cat {} >> {}".format(out_path, out_html_path)
os.system(cmd)
print "nb_files = " , nb_file_paths
if nb_file_paths:
ss = ''
for f in nb_file_paths:
ss = ss + ' "' + f + '"'
cmd = 'jupyter nbconvert ' + ss + ' --to html --stdout >> {}'.format(out_html_path)
os.system(cmd)
PDF生成
- pdfkit.from_file 无法保存图像,但 https://html2pdf.com/做好事。
- 手动添加目录,例如https://github.com/yutayamamoto/pdfoutline TODO:TOC 应该通过 pypdf2 合并、自动获取页码更好地解决。
- TODO:TOC人类组织首先要准备合并。
如果有时间我可能会尝试更多。
链接
关于tensorflow - 如何获取tensorflow文档的pdf格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71931340/