Sorted! Thank you.
On Monday, 3 September 2018 17:32:15 UTC+12, Alexander Yakushev wrote: > > I suspect the problem is with map which is lazy. If you discard the > result of the top-level expression it might not be fully completed or not > even run at all. > > To force a lazy collection (thus, triggering the side effects you desire) > you could do the following things: > > (mapv close pages) ;; mapv returns a vector, thus is eager > (dorun (map close pages)) ;; dorun walks the lazy collection and forces > the side effects > (run! close pages) ;; run! is like map for side effects - > preferred in this case > > On Monday, September 3, 2018 at 5:44:38 AM UTC+3, aboy021 wrote: >> >> I have a problem related to disposing of resources. >> >> I’m trying to retrieve portions of pdf files and combine them into a new >> pdf file. I’m using Apache PDFBox for the purpose. >> Splitting a pdf into pages creates a PDDocument for each page, and >> PDDocuments need to be explicitly closed. If you do not, there’s a log >> message that comes from the finalizer “Warning: You did not close a PDF >> Document”. >> >> I’ve prepared some naive code that demonstrates the problem. Here I’m >> splitting a pdf and recombining it. When the finalizer eventually runs >> every page in the pdf seems to produce an error message. >> >> [org.apache.pdfbox/pdfbox "2.0.11"] >> >> (import '[org.apache.pdfbox.multipdf PDFMergerUtility])(import >> '[org.apache.pdfbox.multipdf Splitter])(import '[org.apache.pdfbox.pdmodel >> PDDocument]) >> (let [pdf (PDDocument/load (File. "input.pdf")) >> splitter (Splitter.) >> pages (into [] (.split splitter pdf)) >> merger (PDFMergerUtility.) >> append (fn [x y] (.appendDocument merger x y) x) >> close #(when % (.close %))] >> (try >> (-> (reduce append (first pages) (rest pages)) >> (.save "output.pdf") >> (close)) >> (finally >> (close pdf) >> (map close pages)))) >> >> Any help would be appreciated. >> >> Also, are there any good resources online for best practice in dealing >> with sequences of disposables? >> >> Thanks, >> >> Arthur >> >> > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.