dotemacs / pdfboxing

Nice wrapper of PDFBox in Clojure
BSD 3-Clause "New" or "Revised" License
180 stars 38 forks source link

Less strict `merge-pdfs` #66

Closed Akeboshiwind closed 1 year ago

Akeboshiwind commented 1 year ago

Expected Behavior

I have a couple of input-streams containing PDFs that I want to merge into an output-stream.

The current merge-pdfs function requires that all inputs are files, but PDFBox supports adding InputStreams.

Same with the output, merge-pdfs requires that the output is a filename, but PDFBox supports both filenames and OutputStreams.

Potential Solution

To solve this in my codebase I've updated merge-pdfs to be less strict:

(defn merge-pdfs [& {:keys [input output]}]
  (let [merger (PDFMergerUtility.)]
    (doseq [source input]
      (.addSource merger source))
    (cond
      (instance? java.io.OutputStream output)
      (.setDestinationStream merger output)

      :else
      (.setDestinationFileName merger output))
    (.mergeDocuments merger)))

But I wanted your feedback before submitting a PR. Is this something you'd be interested in?

dotemacs commented 1 year ago

Hey @Akeboshiwind

If you can get this to work and also ensure that there are no broken tests, I'd be happy to merge this in.

Thank you