Skip to content

Instantly share code, notes, and snippets.

@jplaza
Created May 18, 2018 20:37
Show Gist options
  • Save jplaza/8ddd7b0b7acfe005ad6e42f1a1bd020b to your computer and use it in GitHub Desktop.
Save jplaza/8ddd7b0b7acfe005ad6e42f1a1bd020b to your computer and use it in GitHub Desktop.
Extrae la clave de acceso de un RIDE PDF
(ns co.datil.toolbox.pdf
(:require [pdfboxing.text :as pdfbox]
[clojure.java.io :as io]
[clojure.string :as string]))
(defn -remove-trailing-slash
[url]
(string/replace #"(?<=.)/$" ""))
(defn -rand-name
[ext]
(apply str
(concat (repeatedly 8 #(char (rand-nth (range 48 91)))) "." ext)))
(defn download-pdf
[uri]
(let [file (rand-name "pdf")]
(with-open [in (io/input-stream uri)
out (io/output-stream file)]
(io/copy in out)
file)))
(defn extract-uuid
"Extrae la clave de acceso de un PDF que representa un comprobante
electrónico de Ecuador."
[pdfpath]
(->> (pdfbox/extract pdfpath)
(re-find #"\s(\d{49})\s")
last))
;; Usage
(extract-uuid "/tmp/factura.pdf")
;; 1405201801179027538800120020030000034623793289412
(extract-uuid (download-pdf "https://app.datil.co/ver/2a216513219345a7aaebfa420ddf2dde/pdf"))
;; 1405201801179027538800120020030000034623793289412
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment