mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Fixed the PDF generation
Signed-off-by: Guillaume B <guitreize@gmail.com>
This commit is contained in:
parent
750e211649
commit
31cee95b6f
3 changed files with 16 additions and 7 deletions
2
pelican/__init__.py
Normal file → Executable file
2
pelican/__init__.py
Normal file → Executable file
|
|
@ -73,7 +73,7 @@ def run_pelican(settings, path, theme, output_path, markup, delete):
|
|||
params = init_params(settings, path, theme, output_path, markup, delete)
|
||||
generators = [ArticlesGenerator, PagesGenerator, StaticGenerator]
|
||||
if params[0]['PDF_GENERATOR']: # param[0] is settings
|
||||
processors.append(PdfGenerator)
|
||||
generators.append(PdfGenerator)
|
||||
run_generators(generators, *params)
|
||||
|
||||
|
||||
|
|
|
|||
19
pelican/generators.py
Normal file → Executable file
19
pelican/generators.py
Normal file → Executable file
|
|
@ -7,7 +7,7 @@ import os
|
|||
from jinja2 import Environment, FileSystemLoader
|
||||
from jinja2.exceptions import TemplateNotFound
|
||||
|
||||
from pelican.utils import update_dict, copytree, process_translations
|
||||
from pelican.utils import update_dict, copytree, process_translations, open
|
||||
from pelican.contents import Article, Page, is_valid_content
|
||||
from pelican.readers import read_file
|
||||
|
||||
|
|
@ -252,18 +252,27 @@ class PdfGenerator(Generator):
|
|||
self.pdfcreator = RstToPdf(breakside=0, stylesheets=['twelvepoint'])
|
||||
except ImportError:
|
||||
raise Exception("unable to find rst2pdf")
|
||||
super(PdfGenerator, self).__init(*args, **kwargs)
|
||||
super(PdfGenerator, self).__init__(*args, **kwargs)
|
||||
|
||||
def _create_pdf(self, obj, output_path):
|
||||
if obj.filename.endswith(".rst"):
|
||||
self.pdfcreator.createPdf(text=open(obj.filename).read(),
|
||||
output=os.path.join(output_path, "%s.pdf" % obj.slug))
|
||||
|
||||
filename = obj.slug + ".pdf"
|
||||
output_pdf=os.path.join(output_path, filename)
|
||||
# print "Generating pdf for", obj.filename, " in ", output_pdf
|
||||
self.pdfcreator.createPdf(text=open(obj.filename), output=output_pdf)
|
||||
print u' [ok] writing %s' % output_pdf
|
||||
|
||||
def generate_context(self):
|
||||
pass
|
||||
|
||||
def generate_output(self, writer=None):
|
||||
# we don't use the writer passed as argument here, since we write our own files
|
||||
print u' Generating PDF files...'
|
||||
pdf_path = os.path.join(self.output_path, 'pdf')
|
||||
try:
|
||||
os.mkdir(pdf_path)
|
||||
except OSError:
|
||||
print "Couldn't create the pdf output folder in ", pdf_path
|
||||
pass
|
||||
|
||||
for article in self.context['articles']:
|
||||
|
|
|
|||
2
samples/pelican.conf.py
Normal file → Executable file
2
samples/pelican.conf.py
Normal file → Executable file
|
|
@ -5,7 +5,7 @@ SITEURL = 'http://blog.notmyidea.org'
|
|||
|
||||
GITHUB_URL = 'http://github.com/ametaireau/'
|
||||
DISQUS_SITENAME = "blog-notmyidea"
|
||||
PDF_PROCESSOR = False
|
||||
PDF_GENERATOR = False
|
||||
|
||||
LINKS = (('Biologeek', 'http://biologeek.org'),
|
||||
('Filyb', "http://filyb.info/"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue