Add two new parameters for creating pdf

* PDF_STYLE - name of custom style to use when generating pdf
* PDF_STYLE_PATH - path where custom style is located
This commit is contained in:
Wladislaw Merezhko 2012-09-08 18:24:15 +03:00
commit 8b44fa6a2d

View file

@ -454,13 +454,20 @@ class PdfGenerator(Generator):
"""Generate PDFs on the output dir, for all articles and pages coming from """Generate PDFs on the output dir, for all articles and pages coming from
rst""" rst"""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(PdfGenerator, self).__init__(*args, **kwargs)
try: try:
from rst2pdf.createpdf import RstToPdf from rst2pdf.createpdf import RstToPdf
pdf_style_path = os.path.join(self.settings['PDF_STYLE_PATH']) \
if 'PDF_STYLE_PATH' in self.settings.keys() \
else ''
pdf_style = self.settings['PDF_STYLE'] if 'PDF_STYLE' \
in self.settings.keys() \
else 'twelvepoint'
self.pdfcreator = RstToPdf(breakside=0, self.pdfcreator = RstToPdf(breakside=0,
stylesheets=['twelvepoint']) stylesheets=[pdf_style],
style_path=[pdf_style_path])
except ImportError: except ImportError:
raise Exception("unable to find rst2pdf") raise Exception("unable to find rst2pdf")
super(PdfGenerator, self).__init__(*args, **kwargs)
def _create_pdf(self, obj, output_path): def _create_pdf(self, obj, output_path):
if obj.filename.endswith(".rst"): if obj.filename.endswith(".rst"):