This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
md-pdf/md_pdf/build/pdf.py

39 lines
872 B
Python
Raw Normal View History

2017-03-27 09:17:49 +01:00
import pdfkit
2017-03-28 21:59:11 +01:00
from md_pdf.utils import PROJECT_DIR
from md_pdf.build.cover import OUTPUT_COVER_FILE
import os
2017-03-27 09:17:49 +01:00
2017-03-28 21:59:11 +01:00
STYLE_FILE = os.path.join(PROJECT_DIR, 'assets', 'style.css')
HEADER_FILE = os.path.join(PROJECT_DIR, 'assets', 'header.html')
FOOTER_FILE = os.path.join(PROJECT_DIR, 'assets', 'footer.html')
PDF_OPTIONS = {
2017-03-27 09:17:49 +01:00
"quiet": "",
"no-pdf-compression": "",
"margin-top": '0.6in',
"margin-bottom": '0.6in',
"margin-left": '0.4in',
"margin-right": '0.4in',
2017-03-28 21:59:11 +01:00
"header-html": HEADER_FILE,
"footer-html": FOOTER_FILE,
2017-03-27 09:17:49 +01:00
"footer-spacing": 5,
"header-spacing": 5,
"title": "Title thing",
"replace": [
]
}
2017-03-28 21:59:11 +01:00
def export_pdf(content, out_dir):
2017-03-27 09:17:49 +01:00
return pdfkit.from_string(
content,
2017-03-28 21:59:11 +01:00
os.path.join(out_dir, 'output.pdf'),
options=PDF_OPTIONS,
css=STYLE_FILE,
cover=OUTPUT_COVER_FILE
2017-03-27 09:17:49 +01:00
)