Add PDF generation
This commit is contained in:
parent
46afde26d6
commit
6c6121a849
|
@ -1,6 +1,7 @@
|
||||||
#!python
|
#!python
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import pdfkit
|
||||||
from markdown2 import markdown
|
from markdown2 import markdown
|
||||||
|
|
||||||
input_ = 'input_files'
|
input_ = 'input_files'
|
||||||
|
@ -44,14 +45,20 @@ for root, dirs, files in os.walk(input_, topdown=True):
|
||||||
|
|
||||||
with open(outfile, 'w') as f:
|
with open(outfile, 'w') as f:
|
||||||
content = markdown(content)
|
content = markdown(content)
|
||||||
|
pdf = basename + '.pdf'
|
||||||
|
|
||||||
pretty_name = basename.replace('_', ' ')
|
pretty_name = basename.replace('_', ' ')
|
||||||
|
|
||||||
new_file = render_template(file_template,
|
new_file = render_template(file_template,
|
||||||
title=pretty_name,
|
title=pretty_name,
|
||||||
path=outroot.replace('_', ' ') + '/' + pretty_name,
|
path=outroot.replace('_', ' ') + '/' + pretty_name,
|
||||||
|
pdf=pdf,
|
||||||
content=content)
|
content=content)
|
||||||
|
|
||||||
|
content += '<style>body { text-align: justify; }</style>'
|
||||||
|
|
||||||
|
pdfkit.from_string(content, outroot + '/' + pdf)
|
||||||
|
|
||||||
f.write(new_file)
|
f.write(new_file)
|
||||||
|
|
||||||
index_html = '<ul>'
|
index_html = '<ul>'
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
<h1 id="cabinet">Cabinet file manager</h1>
|
<h1 id="cabinet">Cabinet file manager</h1>
|
||||||
<a id="back" href="Files/index.html">Explore</a>
|
<a class="button" id="back" href="Files/index.html">Explore</a>
|
||||||
</header>
|
</header>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
markdown2
|
markdown2
|
||||||
|
pdfkit
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
<h1 id="cabinet">Cabinet file manager</h1>
|
<h1 id="cabinet">Cabinet file manager</h1>
|
||||||
<a id="back" href="../index.html">← Back</a>
|
<a class="button" id="back" href="../index.html">← Back</a>
|
||||||
<span id="path">${path}</span>
|
<span id="path">${path}</span>
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
|
|
|
@ -8,11 +8,13 @@
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
<h1 id="cabinet">Cabinet file manager</h1>
|
<h1 id="cabinet">Cabinet file manager</h1>
|
||||||
<a id="back" href="index.html">← Back</a>
|
<div>
|
||||||
|
<a class="button" id="back" href="index.html">← Back</a>
|
||||||
<span id="path">${path}</span>
|
<span id="path">${path}</span>
|
||||||
|
<a class="button" id="pdf" href="${pdf}">↓ PDF</a>
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
<h1>${title}<h1>
|
|
||||||
${content}
|
${content}
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -14,11 +14,27 @@ a {
|
||||||
color: #3b7fdd;
|
color: #3b7fdd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
padding: .4em;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pdf {
|
||||||
|
background-color: red;
|
||||||
|
color: white;
|
||||||
|
right: 0;
|
||||||
|
bottom: -.4em;
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
header div {
|
||||||
|
display: block;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
#back {
|
#back {
|
||||||
background-color: #3b7fdd;
|
background-color: #3b7fdd;
|
||||||
color: black;
|
color: black;
|
||||||
padding: .4em;
|
|
||||||
border-radius: 3px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#path {
|
#path {
|
||||||
|
|
Loading…
Reference in New Issue