Fork me on GitHub

Yes, sometimes I wonder if I had to nominate a single feature from Clojure as a selling point then perhaps I would choose...


💯 7

+1000 to that! The great Egal by Henry Baker.


Clojure's equality semantics are an understatement. You only appreciate it a long time after the fact


How would I pass args to enlive’s at macro if I have them as a map, can’t use apply because it’s macro:

(at a-node
  [:a :selector] a-transformation)
I what to pass a seq of transformations, e.g.
[[:a :selector] a-transformation]


maybe sth like

(eval `(foo [email protected]))


Actually with enlive/transform it seems relatively straightforward


Oh! There’s enlive/at* which does exactly what I want 🙂


What is currently the best option to generate PDFs in Clojure? I was thinking about wkhtmltopdf, but I found this project is abandoned. There are other projects but looks abandoned too. I need PDFs with precision to each mm. Generating PDFs using wkthmltopdf (html->pdf) works fine and using js is very customizable. I also found using Java libraries to make PDFs is a nightmare when want to be precise to each mm and do things like fit words into size of block, so this font size should be counted and do other magic. So after all I am looking something where I can use html + js -> PDF. Do you recommend something? I can also run conversion from command line, so it doesn’t have to be Java library. PS I am looking free tool.


I use clj-pdf, it is not abandoned, and works pretty well for my (limited) use cases: invoices, reports with tables, etc.


Thanks. I think I was looking on this a few years ago but I need generate PDFs precise to each mm and text needs to fit into box, so font has to be lowered if needed but there is a minimum value and some other custom things. Does it work with this things today?


I wrote a library for just that, which as far as I know is still used in production at my previous employer. The docs are not awesome, and there have not been changes in a while, but I would consider it stable.


I haven't heard of anything better than wkhtmltopdf -- funnily enough it was [and still is] very popular with CFML (ColdFusion) developers who often seem to need to produce and manipulate very specific PDF documents.


hmm I am reading this is also possible to use things like puppeter etc. in Google Cloud Functions - just an interesting alternative


yes, wkhtmltopdf works good. But this is abandoned which is not good sign


last release was in 2018 if I remember


What makes you say it’s abandoned? IME old Clojure code usually continues to function perfectly on new versions of Clojure, so there’s just generally less need to roll new releases unless new functionality has been added.


(it’s one of the things I really like about Clojure)


wkhtmltopdf is in C++. Do you know this tool and use this?


Ah ok - sorry I thought it was a Clojure lib.


C++ code also doesn’t change much IME, but mostly because it’s rare to get anything working for very long, so it’s scary to touch something that (seems to) work…. /s


Last real PDF generation I did was using OpenOffice / LibreOffice in daemon mode from Java, which is horrendous. And this was mostly document conversion (e.g. .docx -> .pdf), which sounds like a different use case to yours.


google cloud functions (solutions based on node.js) looks very cheap for this purpose. I have to back to this topic tomorrow. Goodnight.


I was going to say, using a web driver that lets you print to PDF or export to PDF might work


If you do find good alternatives @kwladyka please report back here with them. I'd be very interested, since I still have a lot of contacts in the CFML community who would also be interested in that information.


sure, I will let you know. I know from my own experience generating precise PDFs is a hard thing.


We're using browserless with Puppeteer and PDF printing to generate PDF exports of various things that users can create in our product - you can use their hosted version or run the browserless container yourself. It's a bit crazy that the best way we found to generate a PDF is to spin up a headless browser


yes me too, I think the best one is to use web browser (chrome) to generate PDF and make templates in html + js


but there is a lot of possibilities of implementations of this solution


but I totally agree this is the less painful option


This is still in progress, but google functions or amazon lambdas with node.js looks as a good alternative. First I will finish this with wkhtmltopdf and later will work on try this solutions. But maybe you have any idea how to compare 2 PDFs if they are the same. So I can write tests and be sure PDFs looks like before. I was trying to make hash on them, but this doesn’t work good. PDF binary “string” is so different depends on local settings even using the same version of wkthmltopdf. This is too crazy. Any idea how to compare PDFs visual aspect?


Maybe convert to jpg and compare and some crazy stuff


I have no idea how to automate this


@U04V70XH6 Do you know any trick for this?


How developers test PDF generation in ci/cd?


so what is to compare not only the text, but also positions of everything


I found this but maybe you know something battle tested


No idea. I've always managed to avoid PDF work (because I hate dealing with exactly this sort of annoying thing). Most CFML shops don't do CI/CD and many of them don't even automate testing very much so I suspect they just check PDFs manually / visually.


Same, we generate our PDFs out of content authored in our app, and because it's based on user supplied content there's no real automated way of testing the generator. Since we're using Chrome as the layout engine, that task is somewhat easier as the print-optimized views can be tested just like any other part of a web application. But in the end visual inspection is still required at the end of the day


@U0JEFEZH6 why not library which I mentioned? It looks promising


Low value at this point, as we have the PDF generated as we need them. Also, the machinery required to produce a PDF is surprisingly complicated so costs outweigh benefits at this point


There's too many combinations of assets that can be used to produce a PDF so an inspection would probably be a) slow b) still wouldn't catch all the cases. But YMMV, all I wrote is based on our constraints, features etc etc etc


I wrote a library for just that some years ago, which as far as I know is still used in production at my previous employer. The docs are not awesome, and there have not been changes in a while, but I would consider it stable. The general idea is to describe the layout as an EDN template and fuse it with a PDF document, thus separating data logic from layout logic. Maybe someone finds it useful.


Really cool - I wish we could use it (our PDFs are effectively print-outs of pages built by our React app)


So far I stay with wkthmltopdf, because I already have something what work, but I will change this later. After first version on production will be released and first client will start to use this. I think I will change this to cloud functions (google) / labmda (AWS) with node.js. Much more updated solutions which from what I can read are battle tested.


From my experience only converting using chrome headless make sense. Everything else is hard to maintenance and to make very precise PDF custom things.