Created
July 26, 2012 14:49
-
-
Save jackrusher/3182488 to your computer and use it in GitHub Desktop.
Fetching PDF text with attributes in Clojure using PDFBox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns pdfbox.core | |
(:import [org.apache.pdfbox.pdmodel PDDocument] | |
[org.apache.pdfbox.util PDFMarkedContentExtractor TextPosition] | |
[java.util ArrayList])) | |
(defn parse-pdf [filename] | |
(let [pages (.getAllPages (.getDocumentCatalog (PDDocument/load filename))) | |
textpool (ArrayList.) | |
extract-text (proxy [PDFMarkedContentExtractor] [] | |
(processTextPosition [text] | |
(.add textpool text)))] | |
(doseq [page pages] | |
(when-let [contents (.getStream (.getContents page))] | |
(.processStream extract-text page (.findResources page) contents))) | |
textpool)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment