Fork me on GitHub
#clojure
<
2020-05-30
>
lloydshark06:05:12

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

=

💯 28
jaihindhreddy15:06:22

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

didibus09:05:18

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

martinklepsch20:05:38

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]

vemv20:05:24

maybe sth like

(eval `(foo [email protected]))
?

martinklepsch21:05:37

Actually with enlive/transform it seems relatively straightforward

martinklepsch21:05:58

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

kwladyka22:05:55

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.

jrychter10:06:13

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

kwladyka11:06:25

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?

mdiin08:06:34

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. https://github.com/mdiin/pdf-stamper

seancorfield22:05:36

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.

kwladyka22:05:55

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

kwladyka22:05:38

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

kwladyka22:05:16

last release was in 2018 if I remember

pmonks22:05:44

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.

pmonks22:05:08

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

kwladyka22:05:07

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

pmonks22:05:44

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

pmonks22:05:27

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

pmonks22:05:32

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.

kwladyka22:05:57

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

didibus09:05:05

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

seancorfield23:05:21

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.

kwladyka12:05:56

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

lukasz17:05:08

We're using browserless https://www.browserless.io 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

kwladyka17:05:13

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

kwladyka17:05:32

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

kwladyka17:05:47

but I totally agree this is the less painful option

kwladyka14:06:19

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?

kwladyka14:06:38

Maybe convert to jpg and compare and some crazy stuff

kwladyka14:06:50

I have no idea how to automate this

kwladyka14:06:37

@U04V70XH6 Do you know any trick for this?

kwladyka14:06:51

How developers test PDF generation in ci/cd?

kwladyka14:06:33

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

kwladyka15:06:17

I found this https://github.com/red6/pdfcompare but maybe you know something battle tested

seancorfield15:06:08

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.

lukasz16:06:47

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

kwladyka16:06:42

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

lukasz16:06:45

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

lukasz16:06:03

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

mdiin08:06:49

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. https://github.com/mdiin/pdf-stamper

lukasz14:06:07

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

kwladyka16:06:56

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.

kwladyka16:06:40

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

mdiin08:06:49

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. https://github.com/mdiin/pdf-stamper