簡體   English   中英

如何使用 ClojureScript 從 pdf 文件創建字節向量?

[英]How to create a vector of bytes from pdf file with ClojureScript?

我想使用 ClojureScript 將 pdf 文件轉換為字節向量,例如:[1 23 4 43.....]。 請問,有什么想法嗎?

非常感謝!

我寫了這個快速示例,它應該可以為您提供 web 版本和 HTML5 文件 API 所需的大部分內容:

(defn handle-files [fs]
  (let [file  (aget (.-files fs) 0) ;; the first file
        slice (.slice file 0 100)]  ;; a slice with the first 100 bytes

    ;; The API to get the file contents returns a promise, so we'll update
    ;; the atom when the data is available
    (-> slice .text (.then #(swap! file-info assoc-in [:contents] %)))

    ;; Most of the file info is available right away
    (reset! file-info {:name (.-name file)
                       :size (.-size file)
                       :type (.-type file)})))

;; App initialization

(defn mount-root []
  (rdom/render [example-app] (.getElementById js/document "app"))

  ;; register fn to check on the file[s] we want the browser to scan
  (-> (.getElementById js/document "input")
      (.addEventListener "change" #(handle-files (.-target %)) false)))

您可以在此 repo 上找到一個工作示例: https://github.com/dfuenzalida/cljs-files-api

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM