Source

vanhoek / vanhoek / backends / pdf_writer.py

import cairo
from .backend_base import BackendBase

class PDFWriter(BackendBase):
    _surface = None
    def __init__(self, filename = "output.pdf"):
        self.filename = filename

    def draw(self, slide, i):
        surface = BackendBase.draw(self, slide, i)
        surface.flush()

    @property
    def surface(self):
        if self._surface is None:
            self._surface = cairo.PDFSurface(self.filename, 1024, 768)
        else:
            self._surface.show_page()
        return self._surface