def make_barcode_pdf(self, isbn, pdf, corner='br'): """Put an ISBN barcode in a corner of a single blank page.""" product_code = bookland.makeProductCode(str(isbn)) if product_code.type in ("ISBN10", "ISBN13", "ISMN"): b = bookland.Bookland(product_code) elif product_code.type in ("EAN13", ): b = bookland.EAN13Symbol(product_code) else: raise bookland.ProductCodeError( "what kind of product code is this?") position = (corner, float(self.width), float(self.height), float(self.side_margin), float(self.bottom_margin)) epslines = b.eps(position=position) cmd2 = [ 'ps2pdf', '-dFIXEDMEDIA', '-dDEVICEWIDTHPOINTS=%s' % self.width, '-dDEVICEHEIGHTPOINTS=%s' % self.height, '-', pdf ] p2 = Popen(cmd2, stdin=PIPE, stdout=PIPE, stderr=PIPE) out, err = p2.communicate(epslines)
def clean_isbn(self): isbn = self.cleaned_data["isbn"] if isbn: try: product_code = bookland.makeProductCode(str(isbn)) except bookland.ProductCodeError: product_code = None msg = u"Invalid ISBN." if not product_code or product_code.type not in ("ISBN10", "ISBN13", "ISMN"): raise forms.ValidationError(msg) return isbn
def make_barcode_pdf(self, isbn, pdf, corner='br'): """Put an ISBN barcode in a corner of a single blank page.""" product_code = bookland.makeProductCode(str(isbn)) if product_code.type in ("ISBN10", "ISBN13", "ISMN"): b = bookland.Bookland(product_code) elif product_code.type in ("EAN13", ): b = bookland.EAN13Symbol(product_code) else: raise bookland.ProductCodeError("what kind of product code is this?") position = (corner, float(self.width), float(self.height), float(self.side_margin), float(self.bottom_margin)) epslines = b.eps(position=position) cmd2 = ['ps2pdf', '-dFIXEDMEDIA', '-dDEVICEWIDTHPOINTS=%s' % self.width, '-dDEVICEHEIGHTPOINTS=%s' % self.height, '-', pdf] p2 = Popen(cmd2, stdin=PIPE, stdout=PIPE, stderr=PIPE) out, err = p2.communicate(epslines)