Esempio n. 1
0
def pdf_split():
    stor = request_files().next()
    LOG.debug('pdf_split(%s)' % stor)
    return send_file(
        pack_files(
            (('%03d.pdf' % i, page)
             for i, page in enumerate(pdf.split_pdf(stor.stream))),
            fmt='zip'), mimetype='application/zip', as_attachment=True,
        attachment_filename=stor.name)
Esempio n. 2
0
def image_convert(files=None, dest_typ=None):
    if not dest_typ:
        dest_typ = best_dest_type()
    ext_ = ext(dest_typ)
    image_fmt = dest_typ.split('/', 1)[1]
    LOG.debug('image_convert dest=%s files=%s', dest_typ, repr(files)[:100])
    for stream, mimetype, name in request_files(files):
        if 'application/pdf' == mimetype:
            # n = len(pdf.get_pages(stream))
            for i, part in enumerate(pdf.split_pdf(stream)):
                try:
                    yield (image.convert(part, image_fmt, 'application/pdf'),
                           dest_typ, name + ('-page_%02d' % (i + 1)) + ext_)
                except Exception, exc:
                    LOG.error("error converting %s (%s) to pdf: %s",
                              repr(part)[:100], image_fmt, exc)
        else:
            try:
                yield (image.convert(stream, image_fmt, mimetype),
                       dest_typ, name + ext_)
            except Exception, exc:
                LOG.error("error converting %s (%s) to pdf: %s",
                          repr(stream)[:100], image_fmt, exc)