-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
COSStream has been closed and cannot be read. #57
Comments
sorry about the delay with this. The issue is a bit annoying due to the following problem: The way 2ed5824#diff-4c66c23479d6f9f33283c8cf88c003d0 Which works as expected if you're only using But if you intend on passing that opened & split PDF document to a next function, like in your example with the threading macro, then the issue comes up. So I knew about this, but I'm not sure what would be the right approach to solve this. This is my current thinking: when I originally implemented those functions, I just did them all in isolation. Then somebody created a PR which allowed you to pass the opened PDF stream from one function to the next. So if I implement a solution which will allow for an open stream to be passed onto the next function, I'd probably have to introduce a breaking change. Something that tells a function, not to close the open PDF stream. Like this: (-> (split/split-pdf :input "test/pdfs/multi-page.pdf" :stream true)
(nth <some-idx>)
text/extract) Where the new change is the Since you're using this, what are your thoughts on this? Do you have some other suggestion or approach that I should consider? Thanks |
Still not very good at clojure despite loving it, as well as your wrapper library, but was really needing to just save out the split PDFs and this issue was blocking me. (defn split-pdf
"Split pdf into pages"
[& {:keys [input start end split callback]}]
(with-open [doc (common/obtain-document input)]
(let [splitter (Splitter.)]
(when start (.setStartPage splitter start))
(when end (.setEndPage splitter end))
(when split (.setSplitAtPage splitter split))
(let [result (into [] (.split splitter doc))]
(if callback
(callback result)
result))))) Then when I went to use: (split-pdf :input "big_doc.pdf"
:start 1
:end 1
:callback (fn [[result]]
(.save result (path-for folder "pg1.pdf")))) |
Hi,
This code snippet:
often throws:
Execution error (IOException) at org.apache.pdfbox.cos.COSStream/checkClosed (COSStream.java:83). COSStream has been closed and cannot be read. Perhaps its enclosing PDDocument has been closed?
Thanks for lib :)
The text was updated successfully, but these errors were encountered: