yogthos/json-to-pdf

Image inside header.

jarey opened this issue ยท 6 comments

jarey commented

Hello,

We've come up with the neccesity of inserting an image inside the header of the generated pdf using json-to-pdf.

We tried to tweak the json in order to achieve inserting the image, but as the documentation suggest, json-to-pdf seems to only accept plain text at the moment for the header element.

I saw there's an issue open since, 2016 with something reflecting almost the same neccesity on cli-pdf:

Was wondering if any progress was made in order to achieve that use-case, or if it's possible to modify existing json-to-pdf state to at least permitt the "hack" documented by @alemedeiros on the referenced issue.

Would be glad to help if any directions are given on how the change could be accomplished (even though I doesn't know clojure at all i would do my best).

Thanks in advance and thanks for the effort put on the library.

Hi,

Unfortunately, there hasn't been any progress on this. We haven't needed this functionality in our projects at work, so it's been low priority and I have't had a chance to revisit it. I'll take a look at exposing the hack approach though. It might just be a case of bumping up the version of the clj-pdf dependency.

One thing that would help is if you could see how to accomplish this directly via iText 4 API, then I could take a look to see how to integrate that into clj-pdf.

jarey commented

Hello @yogthos ,

Thanks for your kind reply.

I will try to have a look at the posibilities to accomplish it with iText4 API. We are currently inserting the header with an image into the pdf using iText just after the pdf creation using json-to-pdf. We do it in a hardcoded way, but maybe the fundaments help to fit it into the necessity here.

Will reply here with the follow up once I can have an eye on it.

Thanks again.

jarey commented

Hello again @yogthos ,

I've put together an example of how to add an image inside every page of a pdf created with iText.
It is located here: https://github.com/jarey/itext-header-image-example

The example shows how to put an image on the header (the positioning it is not restricted, to header, the absolute positioning can be specified anywhere inside the page coordinates. What it is ensured is that the content gets inserted for each page created (on start or end of the page, using onStartPage onEndPage methods).

I've used iText 2.1.7, because it is the last full open source release (if it is not the version you wanted, since you were referring to iText4 API just let me know and i will try to addapt the code if needed to the specified version).

Don't know if the example will help, but i hope so.

Thanks in advance, anything, just let me know and i will try to help.

Regards.

PS: Late merry christmas and happy new year.

Hi,

Thanks for putting the example together. I'll take a look at incorporating it. Regarding iText, the latest LGPL/MPL release was actually v4 but the official maintainer pulled the source from the repo. There is a mirror here. From what I've seen the existing API hasn't changed much, so the example should still work.

There's also a revived version under LibrePDF, I was thinking of switching to use that at some point to keep up with the latest updates instead of maintaining my own fork.

I'll let you know once I get something working, and happy new year. :)

Just pushed out a new version 0.8.1 with support for providing an event handler. I updated the docs in the readme with an example based on your version. Let me know how things look on your end.

jarey commented

@yogthos Working perfectly. Thank you very very much!