begins md to pdf conversion

This commit is contained in:
Fred Pauchet 2018-02-15 16:46:32 +01:00
parent 96eddbf8db
commit 7f01692124
3 changed files with 26 additions and 0 deletions

Binary file not shown.

1
writer/TODO.txt Normal file
View File

@ -0,0 +1 @@
https://letchap.github.io/2014/03/06/creer-un-fichier-pdf-avec-python-et-reportlab/

View File

@ -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)