PDF Export on Key Press

20 views
Skip to first unread message

Jason Fabris

unread,
Feb 29, 2020, 6:49:38 PM2/29/20
to clj-processing

I'd like to be able to let a sketch run, then press a key to export to pdf.

I was trying stuff like this, but it just created an empty, unparseable pdf. 

(defn save-pdf []
    (q/do-record (q/create-graphics 1400 1400 :pdf "con_squares.pdf")
                       (draw-state))
                       (q/exit))

Do you have to exit after creating a pdf? That's the way it works in processing, but I'd rather be able to export multiple pdfs without having to stop the sketch...

The docs here seem to be referring to not using fun-mode (I think?), so they don't seem to work to plug that into defsketch...

I'm happy to export as svg if that's easier, but I don't know how to hook that in either...

Any help would be appreciated!
Jason

Mikita Belahlazau

unread,
Mar 3, 2020, 7:35:30 PM3/3/20
to clj-processing
Hi Jason

Here is an example of generating 3 pdfs and svg files in the loop: http://quil.info/api/output/files#do-record You should ignore the last "(is ... )" line as it's part of the test. 

Here is an example of using it on `:mouse-clicked` with fun-mode: https://gist.github.com/nbeloglazov/0138bd788b822a93659b901d03754f6a Every time you click mouse - it will draw state in pdf and save it as out.pdf.

Hope that helps.

Mikita

--
You received this message because you are subscribed to the Google Groups "clj-processing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clj-processin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clj-processing/5a97baac-01a4-4232-8e9c-0d59f8e5e6f6%40googlegroups.com.

Jason Fabris

unread,
Mar 7, 2020, 3:08:39 PM3/7/20
to clj-processing

Amazing. As usual, thanks for the help. I didn't know you could do the mouse-clicked thing in defsketch.

In case this helps anyone, when I did this at first, it was exporting blank pdfs. The shapes were there, but with no fill or stroke. Looking at some old processing forum posts, I came across a comment that the color mode declaration had to be after the create-graphics happened. So I added it in here, and it worked. (W and H are defined outside of defsketch.)


:mouse-clicked (fn [state _]
                     (let [dt (.format (java.text.SimpleDateFormat. "yyyy-MM-dd-hhmmss") 
                                       (new java.util.Date))
                           nm (str "connected_squares_" dt ".pdf")]
                       (q/do-record (q/create-graphics W H :pdf nm)
                                    (q/color-mode :hsb 360 100 100 1)
                                    (draw-state state))
                       state))




On Tuesday, 3 March 2020 19:35:30 UTC-5, Mikita Belahlazau wrote:
Hi Jason

Here is an example of generating 3 pdfs and svg files in the loop: http://quil.info/api/output/files#do-record You should ignore the last "(is ... )" line as it's part of the test. 

Here is an example of using it on `:mouse-clicked` with fun-mode: https://gist.github.com/nbeloglazov/0138bd788b822a93659b901d03754f6a Every time you click mouse - it will draw state in pdf and save it as out.pdf.

Hope that helps.

Mikita

On Sat, Feb 29, 2020 at 3:49 PM Jason Fabris <fabu...@gmail.com> wrote:

I'd like to be able to let a sketch run, then press a key to export to pdf.

I was trying stuff like this, but it just created an empty, unparseable pdf. 

(defn save-pdf []
    (q/do-record (q/create-graphics 1400 1400 :pdf "con_squares.pdf")
                       (draw-state))
                       (q/exit))

Do you have to exit after creating a pdf? That's the way it works in processing, but I'd rather be able to export multiple pdfs without having to stop the sketch...

The docs here seem to be referring to not using fun-mode (I think?), so they don't seem to work to plug that into defsketch...

I'm happy to export as svg if that's easier, but I don't know how to hook that in either...

Any help would be appreciated!
Jason

--
You received this message because you are subscribed to the Google Groups "clj-processing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clj-pro...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages