def generate(self, op: OrderPosition, override_layout=None, override_background=None): Renderer._register_fonts() buffer = BytesIO() if override_background: bgf = default_storage.open(override_background.name, "rb") elif isinstance(self.layout.background, File) and self.layout.background.name: bgf = default_storage.open(self.layout.background.name, "rb") else: bgf = open(finders.find('pretixpresale/pdf/ticket_default_a4.pdf'), "rb") r = Renderer( self.request.event, override_layout or self.get_current_layout(), bgf, ) p = canvas.Canvas(buffer, pagesize=pagesizes.A4) r.draw_page(p, op.order, op) p.save() outbuffer = r.render_background(buffer, 'Ticket') return 'ticket.pdf', 'application/pdf', outbuffer.read()
def _draw_page(self, layout: TicketLayout, op: OrderPosition, order: Order): buffer = BytesIO() objs = self.override_layout or json.loads(layout.layout) or self._legacy_layout() bg_file = layout.background if self.override_background: bgf = default_storage.open(self.override_background.name, "rb") elif isinstance(bg_file, File) and bg_file.name: bgf = default_storage.open(bg_file.name, "rb") else: bgf = self._get_default_background() p = self._create_canvas(buffer) renderer = Renderer(self.event, objs, bgf) renderer.draw_page(p, order, op) p.save() return renderer.render_background(buffer, _('Ticket'))
def _draw_page(self, layout: TicketLayout, op: OrderPosition, order: Order): buffer = BytesIO() objs = self.override_layout or json.loads(layout.layout) or self._legacy_layout() bg_file = layout.background if self.override_background: bgf = default_storage.open(self.override_background.name, "rb") elif isinstance(bg_file, File) and bg_file.name: bgf = default_storage.open(bg_file.name, "rb") else: bgf = self._get_default_background() p = self._create_canvas(buffer) renderer = Renderer(self.event, objs, bgf) renderer.draw_page(p, order, op) p.save() return renderer.render_background(buffer, _('Ticket'))
def generate(self, op: OrderPosition, override_layout=None, override_background=None): Renderer._register_fonts() buffer = BytesIO() if override_background: bgf = default_storage.open(override_background.name, "rb") elif isinstance(self.layout.background, File) and self.layout.background.name: bgf = default_storage.open(self.layout.background.name, "rb") else: bgf = open(finders.find('pretixplugins/badges/badge_default_a6l.pdf'), "rb") r = Renderer( self.request.event, override_layout or self.get_current_layout(), bgf, ) p = canvas.Canvas(buffer, pagesize=pagesizes.A4) r.draw_page(p, op.order, op) p.save() outbuffer = r.render_background(buffer, 'Badge') return 'badge.pdf', 'application/pdf', outbuffer.read()