begins md to pdf conversion
This commit is contained in:
parent
96eddbf8db
commit
7f01692124
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
https://letchap.github.io/2014/03/06/creer-un-fichier-pdf-avec-python-et-reportlab/
|
|
@ -1,5 +1,8 @@
|
|||
from django.db import models
|
||||
|
||||
from markdown import Markdown
|
||||
import pdfkit
|
||||
|
||||
from dms.models import Document
|
||||
|
||||
|
||||
|
@ -15,3 +18,25 @@ class Section(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
def to_pdf():
|
||||
x = ''
|
||||
for section in Section.objects.all():
|
||||
x += '# ' + section.title
|
||||
x += '\n'
|
||||
x += section.content
|
||||
x += '\n'
|
||||
html = Markdown().convert(x)
|
||||
|
||||
options = {
|
||||
'page-size': 'Letter',
|
||||
'encoding': "UTF-8",
|
||||
'custom-header': [
|
||||
('Accept-Encoding', 'gzip')
|
||||
],
|
||||
'no-outline': None,
|
||||
'footer-right': '[page]/[topage]'
|
||||
}
|
||||
|
||||
pdfkit.from_string(html, 'out.pdf', options=options)
|
||||
|
|
Loading…
Reference in New Issue