Example #1
0
  def get(self, doc_id):
    doc = scan_data.read_document(doc_id, db)
    page = scan_data.Page(db, document=doc)
    page.filename = "static/%s.png" % page.key()

    img_pipe = start_scan(page.filename)
    self.set_header("Content-Type", "image/png")
    for chunk in img_pipe:
      self.write(chunk)

    scan_data.write_document(doc, db)
Example #2
0
    def get(self, doc_id):
        doc = scan_data.read_document(doc_id, db)
        page = scan_data.Page(db, document=doc)
        page.filename = "static/%s.png" % page.key()

        img_pipe = start_scan(page.filename)
        self.set_header("Content-Type", "image/png")
        for chunk in img_pipe:
            self.write(chunk)

        scan_data.write_document(doc, db)
Example #3
0
  def get(self, doc_key, format=None):
    "get a document in a specific format"
    doc = scan_data.read_document(doc_key, db)

    if not os.path.isdir(exported_base_dir):
      os.mkdir(exported_base_dir)

    if not format:
      format = self.get_argument("format")
      self.redirect("/export/%s.%s" % (doc_key, format))
      return

    output_path = "%s/%s.%s" % (exported_base_dir, doc_key, format)

    if not os.path.exists(output_path):
      if format == "zip":
        zip = zipfile.ZipFile(output_path, "w")

        for num, page in enumerate(doc.pages()):
          zip.write(page.filename, "page_%d.png" % (num+1))

        zip.close()
      elif format == "big.pdf":
        cmd = ["convert"]
        cmd.extend([ page.filename for page in doc.pages() ])
        cmd.append(output_path)
        subprocess.Popen(cmd).communicate()
      elif format == "mid.pdf":
        cmd = ["convert", "-scale", "50%x50%"]
        cmd.extend([ page.filename for page in doc.pages() ])
        cmd.append(output_path)
        subprocess.Popen(cmd).communicate()
      elif format == "low.pdf":
        cmd = ["convert", "-scale", "30%x30%"]
        cmd.extend([ page.filename for page in doc.pages() ])
        cmd.append(output_path)
        subprocess.Popen(cmd).communicate()
      else:
        raise Exception("Format %s is not supported" % format)

    self.set_header("Content-Disposition", "attachment")
    self.set_header("Content-Type", "application/octet-stream")
    self.set_header("Content-Transfer_encoding", "binary")
    result = open(output_path)
    self.write(result.read())
Example #4
0
    def get(self, doc_key, format=None):
        "get a document in a specific format"
        doc = scan_data.read_document(doc_key, db)

        if not os.path.isdir(exported_base_dir):
            os.mkdir(exported_base_dir)

        if not format:
            format = self.get_argument("format")
            self.redirect("/export/%s.%s" % (doc_key, format))
            return

        output_path = "%s/%s.%s" % (exported_base_dir, doc_key, format)

        if not os.path.exists(output_path):
            if format == "zip":
                zip = zipfile.ZipFile(output_path, "w")

                for num, page in enumerate(doc.pages()):
                    zip.write(page.filename, "page_%d.png" % (num + 1))

                zip.close()
            elif format == "big.pdf":
                cmd = ["convert"]
                cmd.extend([page.filename for page in doc.pages()])
                cmd.append(output_path)
                subprocess.Popen(cmd).communicate()
            elif format == "mid.pdf":
                cmd = ["convert", "-scale", "50%x50%"]
                cmd.extend([page.filename for page in doc.pages()])
                cmd.append(output_path)
                subprocess.Popen(cmd).communicate()
            elif format == "low.pdf":
                cmd = ["convert", "-scale", "30%x30%"]
                cmd.extend([page.filename for page in doc.pages()])
                cmd.append(output_path)
                subprocess.Popen(cmd).communicate()
            else:
                raise Exception("Format %s is not supported" % format)

        self.set_header("Content-Disposition", "attachment")
        self.set_header("Content-Type", "application/octet-stream")
        self.set_header("Content-Transfer_encoding", "binary")
        result = open(output_path)
        self.write(result.read())
Example #5
0
    def get(self, doc_key=None):
        "retrieve a specific document"

        if not doc_key:
            return self.single_get()

        doc = scan_data.read_document(doc_key, db)
        doc_name = doc.name
        pages = doc.pages()
        pages_html = []
        for page in pages:
            pages_html.append(
                "<a href=\"/page/%s\"><img src=\"/thumbnail/%s\" /></a>" %
                (page.key(), page.key()))
        pages_html = "\n".join(pages_html)

        controls = """
    <a href="/documents">Back To All Documents</a><br/>
    <form action="/export/%(doc_key)s">
    <select name="format">
    <option value="zip">Download as zip</option>
    <option value="big.pdf">Download as full quality PDF</option>
    <option value="mid.pdf">Download as reasonable quality PDF</option>
    <option value="low.pdf">Download as low quality PDF</option>
    </select>
    <input type="submit" value="Download" />
    </form>
    <form method="post">
      <input type="submit" value="Scan a Page" />
    </form>
    """ % locals()

        self.set_header("Content-Type", "text/html")
        self.write("""
    <html><head><title>Document: %(doc_name)s</title></head>
    <body>
    <h1>%(doc_name)s</h1>
    %(controls)s
    <hr/>
    %(pages_html)s
    <br/>
    %(controls)s
    </html>""" % locals())
Example #6
0
  def get(self, doc_key=None):
    "retrieve a specific document"

    if not doc_key:
      return self.single_get()

    doc = scan_data.read_document(doc_key, db)
    doc_name = doc.name
    pages = doc.pages()
    pages_html = []
    for page in pages:
      pages_html.append("<a href=\"/page/%s\"><img src=\"/thumbnail/%s\" /></a>" % (page.key(), page.key()))
    pages_html = "\n".join(pages_html)

    controls = """
    <a href="/documents">Back To All Documents</a><br/>
    <form action="/export/%(doc_key)s">
    <select name="format">
    <option value="zip">Download as zip</option>
    <option value="big.pdf">Download as full quality PDF</option>
    <option value="mid.pdf">Download as reasonable quality PDF</option>
    <option value="low.pdf">Download as low quality PDF</option>
    </select>
    <input type="submit" value="Download" />
    </form>
    <form method="post">
      <input type="submit" value="Scan a Page" />
    </form>
    """ % locals()

    self.set_header("Content-Type", "text/html")
    self.write("""
    <html><head><title>Document: %(doc_name)s</title></head>
    <body>
    <h1>%(doc_name)s</h1>
    %(controls)s
    <hr/>
    %(pages_html)s
    <br/>
    %(controls)s
    </html>""" % locals())