Source

sphinx-rst2pdf-builder / sphinx / writers / pdf.py

Full commit
# -*- coding: utf-8 -*-
"""
    sphinx.writers.pdf
    ~~~~~~~~~~~~~~~~~~

    rst2pdf writer.

    :copyright: Copyright 2007-2009 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

from StringIO import StringIO
from docutils import writers
from rst2pdf import createpdf

class PDFWriter(writers.Writer):
   def __init__(self, builder, stylesheets, language, breaklevel, fontpath, fitmode, compressed):
      writers.Writer.__init__(self)
      self.builder = builder
      self.output = ''
      self.stylesheets = stylesheets
      self.language = language
      self.breaklevel = int(breaklevel)
      self.fontpath = fontpath
      self.fitmode = fitmode
      self.compressed = compressed

   supported = ('pdf')
   config_section = 'pdf writer'
   config_section_dependencies = ('writers',)

   def translate(self):
      sio=StringIO('')
      createpdf.RstToPdf(sphinx=True,
                         stylesheets=self.stylesheets,
                         language=self.language,
                         breaklevel=self.breaklevel,
                         fitMode=self.fitmode,
                         fontPath=self.fontpath
                        ).createPdf(doctree=self.document,
                                    output=sio,
                                    compressed=self.compressed)
      self.output=unicode(sio.getvalue(),'utf-8','ignore')

   def supports(self, format):
      """This writer supports all format-specific elements."""
      return 1