def test_ghostscript_center_of_pixel(self): grf = GRF.from_pdf(self._read_file('pdf.pdf'), 'TEST', center_of_pixel=True)[0] output = BytesIO() grf.to_image().save(output, 'PNG') self._compare(output.getvalue(), 'pdf-image-centerofpixel.png')
def test_ghostscript_center_of_pixel(self): grf = GRF.from_pdf( self._read_file('pdf.pdf'), 'TEST', center_of_pixel=True )[0] output = BytesIO() grf.to_image().save(output, 'PNG') self._compare(output.getvalue(), 'pdf-image-centerofpixel.png')
def test_pdf_to_image_multiple_pages(self): grfs = GRF.from_pdf(self._read_file('pdf-2pages.pdf'), 'TEST') self.assertEqual(len(grfs), 2) for i, grf in enumerate(grfs): output = BytesIO() grf.to_image().save(output, 'PNG') self._compare(output.getvalue(), 'pdf-2pages-%i.png' % i)
def test_pdf_to_image_multiple_pages(self): grfs = GRF.from_pdf(self._read_file('pdf-2pages.pdf'), 'TEST') self.assertEqual(len(grfs), 2) for i, grf in enumerate(grfs): output = BytesIO() grf.to_image().save(output, 'PNG') self._compare(output.getvalue(), 'pdf-2pages-%i.png' % i)
def test_pdf_to_image_using_bindings(self): grfs = GRF.from_pdf(self._read_file('pdf-2pages.pdf'), 'TEST', use_bindings=True) self.assertEqual(len(grfs), 2) for i, grf in enumerate(grfs): output = BytesIO() grf.to_image().save(output, 'PNG') self._compare(output.getvalue(), 'pdf-2pages-%i.png' % i) grf = GRF.from_pdf(self._read_file('pdf.pdf'), 'TEST', center_of_pixel=True, use_bindings=True)[0] output = BytesIO() grf.to_image().save(output, 'PNG') self._compare(output.getvalue(), 'pdf-image-centerofpixel.png')
def test_pdf_to_image_using_bindings(self): grfs = GRF.from_pdf( self._read_file('pdf-2pages.pdf'), 'TEST', use_bindings=True ) self.assertEqual(len(grfs), 2) for i, grf in enumerate(grfs): output = BytesIO() grf.to_image().save(output, 'PNG') self._compare(output.getvalue(), 'pdf-2pages-%i.png' % i) grf = GRF.from_pdf( self._read_file('pdf.pdf'), 'TEST', center_of_pixel=True, use_bindings=True )[0] output = BytesIO() grf.to_image().save(output, 'PNG') self._compare(output.getvalue(), 'pdf-image-centerofpixel.png')
def test_pdf_to_image(self): grf = GRF.from_pdf(self._read_file('pdf.pdf'), 'TEST')[0] output = BytesIO() grf.to_image().save(output, 'PNG') self._compare(output.getvalue(), 'pdf-image.png') output = BytesIO() grf.optimise_barcodes() grf.to_image().save(output, 'PNG') self._compare(output.getvalue(), 'pdf-optimised-image.png')
def test_pdf_to_image(self): grf = GRF.from_pdf(self._read_file('pdf.pdf'), 'TEST')[0] output = BytesIO() grf.to_image().save(output, 'PNG') self._compare(output.getvalue(), 'pdf-image.png') output = BytesIO() grf.optimise_barcodes() grf.to_image().save(output, 'PNG') self._compare(output.getvalue(), 'pdf-optimised-image.png')
def get_zpl_data(self, qweb_url, printer_name=False): try: data = [] qweb_source_parts = qweb_url.split('/') report = self.search([('report_name', '=', str(qweb_source_parts[-2]))])[0] if report.use_template: report_template_id = report.report_template_id if report_template_id: template_text = report_template_id.template_text or "" model_name = report.model model_id = qweb_source_parts[-1] if model_id.find(','): model_ids = model_id.split(',') model_ids = list(map(lambda x: int(x), model_ids)) for m_id in model_ids: zpl_data = self.parse_template( template_text, model_name, m_id) data.append(zpl_data) return data reportname = qweb_source_parts[-2] docids = qweb_source_parts[-1] document = self.report_routes(reportname, docids=docids, converter="pdf") pages = GRF.from_pdf(document, 'DEMO') fd, file_name = mkstemp() with open(file_name, "w+") as f: temp = '' for grf in pages: grf.optimise_barcodes() zpl_line = grf.to_zpl() try: zpl_line = zpl_line.encode(encoding='UTF-8', errors='strict') except Exception as e: _logger.info("---------encoding--EXCEPTION---2---%r", e) finally: data.append(zpl_line) return data except Exception as e: raise Warning(e)
def test_pdf_landscape(self): grf = GRF.from_pdf(self._read_file('pdf-landscape.pdf'), 'TEST')[0] output = BytesIO() grf.to_image().save(output, 'PNG') self._compare(output.getvalue(), 'pdf-landscape.png')
def test_pdf_landscape(self): grf = GRF.from_pdf(self._read_file('pdf-landscape.pdf'), 'TEST')[0] output = BytesIO() grf.to_image().save(output, 'PNG') self._compare(output.getvalue(), 'pdf-landscape.png')