{"id":25806025,"url":"https://github.com/alipsa/journo","last_synced_at":"2025-10-05T22:58:59.569Z","repository":{"id":219354185,"uuid":"748840445","full_name":"Alipsa/journo","owner":"Alipsa","description":"Creates PDF documents from Freemarker markup","archived":false,"fork":false,"pushed_at":"2025-09-07T16:38:59.000Z","size":727,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-07T18:28:56.079Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Alipsa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-01-26T21:17:14.000Z","updated_at":"2025-09-07T16:38:53.000Z","dependencies_parsed_at":"2025-08-17T19:19:39.122Z","dependency_job_id":null,"html_url":"https://github.com/Alipsa/journo","commit_stats":null,"previous_names":["alipsa/htmltopdf","alipsa/journo"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/Alipsa/journo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fjourno","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fjourno/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fjourno/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fjourno/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Alipsa","download_url":"https://codeload.github.com/Alipsa/journo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fjourno/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278532353,"owners_count":26002346,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-27T19:52:44.197Z","updated_at":"2025-10-05T22:58:59.534Z","avatar_url":"https://github.com/Alipsa.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Journo - a pdf creation library converting Freemarker markup to pdf\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/se.alipsa/journo-runtime/badge.svg)](https://maven-badges.herokuapp.com/maven-central/se.alipsa/journo-runtime)\n[![javadoc](https://javadoc.io/badge2/se.alipsa/journo-runtime/javadoc.svg)](https://javadoc.io/doc/se.alipsa/journo-runtime)\n\nJourno is a tool to generate PDF from Freemarker templates i.e. it\ncreates PDF documents from Freemarker markup.\n\nUsage of this could be as a reporting engine in an application server (Spring Boot, Play, Quarkus etc.) or a\njava gui (Swing, JavaFx or SWT).\n\nThis library uses [OpenHTMLtoPDF](https://github.com/openhtmltopdf/openhtmltopdf) to generate the PDF so the html produced by the Freemarker\ntemplate needs to take into account the xhtml requirements posed.\n[See the disclaimer section of OpenHTMLtoPDF](https://github.com/openhtmltopdf/openhtmltopdf?tab=readme-ov-file#disclaimer) for details.\n\nJourno runtime requires JDK 17 or later.\n\nBelow is a short introduction, for more comprehensive documentation, see [the wiki](https://github.com/Alipsa/journo/wiki/Journo-Wiki-Home)\n\nExample usage:\n\n```groovy\nimport se.alipsa.journo.JournoEngine;\n\nJournoEngine engine = new JournoEngine(this, \"/templates\");\n\nMap\u003cString, Object\u003e data = new HashMap\u003c\u003e();\ndata.put(\"user\", \"Per\");\n\n// Render the html using the template and the data\nString html = engine.renderHtml(\"test.ftlh\", data);\n\n// Create a pdf file from the html\nPath path = Paths.get(\"test.pdf\");\nengine.renderPdf(html, path);\n```\n\nTo use it, add the following dependency to your maven pom.xml (or equivalent for your build system)\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ese.alipsa\u003c/groupId\u003e\n    \u003cartifactId\u003ejourno-runtime\u003c/artifactId\u003e\n    \u003cversion\u003e0.7.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Handling images\n\n### Regular images\nRegular images should be converted to base64 data url's that are passed in as data.\n\nAssuming you have an image like this in your Freemarker template saved as a file called svgImage.ftlh:\n```xhtml\n\u003cimg src=\"${alice2}\" width=\"200px\" height=\"300px\"/\u003e\n```\nYou can then convert the image to a data url using the Image util:\n\n```groovy\nimport se.alipsa.journo.JournoEngine;\nimport se.alipsa.journo.ImageUtil;\nimport java.util.HashMap;\nimport java.util.Map;\n\nJournoEngine engine = new JournoEngine(this, \"/templates\");\nMap\u003cString, Object\u003e data = new HashMap\u003c\u003e();\n\n// fetch the image from the classloader, in this case its in src/main/resources/alice2.png\n// which is copied to the classes dir and to the root in the jar file\ndata.put(\"alice2\", ImageUtil.asDataUrl(\"/alice2.png\"));\n// Render the html using the template and the data\nString html = engine.renderHtml(\"svgImage.ftlh\", data);\n```\n\n### SVG images\nSvg images are handled automatically using Batik, so you can just insert your\nsvg image into the Freemarker template and use it. However, you must associate the svg image with a block \nor inline block.\n\nIf you are dynamically inserting your svg image, you need to \n[disable autoescaping](https://freemarker.apache.org/docs/dgui_misc_autoescaping.html)\n\nAssuming your Freemarker markup saved as a file called svgImage.ftlh with the following content:\n\n```xhtml\n\u003chtml xmlns=\"http://www.w3.org/1999/xhtml\"\u003e\n\u003chead\u003e\n    \u003ctitle\u003eSVG image example\u003c/title\u003e\n    \u003cstyle\u003e\n        svg {display: block;width:400px;height:400px}\n    \u003c/style\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003ch1\u003eA big SVG circle\u003c/h1\u003e\n\u003cdiv\u003e\n    \u003c!-- inserting a svg image directly --\u003e\n    \u003csvg xmlns=\"http://www.w3.org/2000/svg\"\u003e\n        \u003ccircle cx=\"150\" cy=\"65\" r=\"60\" stroke=\"black\" stroke-width=\"3\"\n                fill=\"red\" /\u003e\n    \u003c/svg\u003e\n    \u003c!-- inserting a svg image from the data, must disable auto escaping --\u003e\n    ${svgImage?no_esc}\n\u003c/div\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nYou can then do:\n\n```groovy\nimport se.alipsa.journo.JournoEngine;\nimport java.util.HashMap;\nimport java.util.Map;\n\nJournoEngine engine = new JournoEngine(this, \"/templates\");\nMap\u003cString, Object\u003e data = new HashMap\u003c\u003e();\ndata.put(\"svgImage\", \"\"\"\n        \u003ch2\u003eA big blue circle\u003c/h2\u003e\n        \u003csvg xmlns=\"http://www.w3.org/2000/svg\"\u003e\n            \u003ccircle cx=\"150\" cy=\"90\" r=\"80\" stroke=\"black\" stroke-width=\"3\"\n                    fill=\"blue\" /\u003e\n        \u003c/svg\u003e\n    \"\"\");\n\n// Create a pdf file:\nPath path = Paths.get(\"svgImage.pdf\");\nengine.renderPdf(\"svgImage.ftlh\", data, path);\n```\n\n## Page structure\n\nA good way to structure your document is to define 3 sections in your page style i.e. for header, footer and content, e.g:\n\n```xhtml\n\u003cstyle\u003e\n    div.header {\n        display: block;\n        position: running(header);\n    }\n\n    div.footer {\n        display: block;\n        position: running(footer);\n    }\n\n    div.content {page-break-after: always;}\n    div.lastpage {page-break-after: avoid;}\n\n    @page {\n        @top-center { content: element(header) }\n    }\n    @page {\n        @bottom-right-corner { content: element(footer) }\n    }\n\n    #pagenumber:before {\n        content: counter(page);\n    }\n\n    #pagecount:before {\n        content: counter(pages);\n    }\n\n\u003c/style\u003e\n```\n\nThen, in the body you put div sections for each e.g:\n```xhtml\n\u003cbody\u003e\n    \u003cdiv class=\"header\"\u003eHere goes the header text\u003c/div\u003e\n    \u003cdiv class=\"footer\" style=\"\"\u003e  Page \u003cspan id=\"pagenumber\"/\u003e of \u003cspan id=\"pagecount\"/\u003e \u003c/div\u003e\n    \u003cdiv class=\"content\" id=\"page1\"\u003e\n        \u003ch1\u003eCHAPTER I\u003c/h1\u003e\n        \u003cp\u003e\n         Some text and images for the first page\n        \u003c/p\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"content\" id=\"page2\"\u003e\n      \u003ch1\u003eCHAPTER 2\u003c/h1\u003e\n      \u003cp\u003e\n        Some text and images for the second page\n      \u003c/p\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"lastpage\" id=\"page3\"\u003e\n      \u003cp\u003e\n        some text and images for the last page\n      \u003c/p\u003e\n    \u003c/div\u003e\n\u003c/body\u003e\n```\n\n## External Resources\nExternal resources, such as an external css must be treated with some care.\nIf you run Journo in a servlet environment and need to reference an external css\nthat is not publicly available, you should parameterize the location using \n`getServletContext().getRealPath()`; if you are in Spring Boot you can do\n`getClass().getResource(\"/path/to/resource.css\").toExternalForm()`.\n\nFor example, in your Freemarker template:\n```xhtml\n\u003clink rel=\"stylesheet\" href=\"${externalCssPath}\" type=\"text/css\" media=\"all\" /\u003e\n```\n\n... you then find the css and set the url parameter:\n```groovy\nString externalCssPath = this.getClass().getResource(\"/templates/mystyle.css\").toExternalForm();\ndata.put(\"externalCssPath\", externalCssPath);\n```\n\nOf course if you either make your css available from some url or put your style inline in the\nxhtml document you don't need to do any of this.\n\n## Fonts\nJourno detects and adds declared fonts if you specify it. I.e. if you do:\n```html\n\u003cstyle\u003e\n\n        /* declared fonts are automatically added to the Journo Engine */\n        @font-face {\n            font-family: \"Jersey 25\";\n            src: url(${jerseyUrl});\n        }\n\u003c/style\u003e\n```\nAnd the Jersey font is in src/main/resources/fonts you can insert the location\n```groovy\nimport se.alipsa.journo.JournoEngine;\nimport java.net.URL;\nimport java.util.HashMap;\nimport java.util.Map;\n\nJournoEngine engine = new JournoEngine(this, \"/templates\");\nURL urlJersey = getClass().getResource(\"/fonts/Jersey25-Regular.ttf\");\nMap\u003cString, Object\u003e data = new HashMap\u003c\u003e();\ndata.put(\"jerseyUrl\", urlJersey);\nbyte[] pdf = engine.renderPdf(\"someReport.ftl\", data);\n```\n\n### Google fonts\nThe woff2 format, which many of the Google fonts default to is not supported in OpenHTMLtoPDF. \nTtf fonts works just fine though, so what you can do after finding a nice font you want to use \nis to look up the ttf location of that font e.g. \n[here](https://gist.githubusercontent.com/karimnaaji/b6c9c9e819204113e9cabf290d580551/raw/ed71595a691320ba63e48335c7c77818336cb1c2/GoogleFonts.txt)\nand search for the font family. E.g: if google fonts advices you to \n```html\n\u003clink href=\"https://fonts.googleapis.com/css2?family=Sofia\u0026display=swap\" rel=\"stylesheet\"\u003e\n```\nYou can navigate to the css `https://fonts.googleapis.com/css2?family=Sofia` and you will see that this is a woff2 font\n`src: url(https://fonts.gstatic.com/s/sofia/v14/8QIHdirahM3j_su5uI0Orbjl.woff2) format('woff2');`. When looking it up in \nthe list of [google ttf fonts](https://gist.githubusercontent.com/karimnaaji/b6c9c9e819204113e9cabf290d580551/raw/ed71595a691320ba63e48335c7c77818336cb1c2/GoogleFonts.txt)\nyou will find that there is a ttf version here: http://fonts.gstatic.com/s/sofia/v5/Imnvx0Ag9r6iDBFUY5_RaQ.ttf. Armed with that you can declare the font as follows:\n```css\n        @font-face {\n          font-family: \"Sofia\";\n          src: url(http://fonts.gstatic.com/s/sofia/v5/Imnvx0Ag9r6iDBFUY5_RaQ.ttf);\n          font-weight: normal;\n          font-style: normal;\n        }\n```\n\n## Javascript\nif you need to use Javascript to manipulate the DOM you must run the html code in a browser (e.g. Javafx WebView)\nbefore rendering the pdf (see [the gmd documentation](https://github.com/Alipsa/gmd/blob/main/README.md) for\nan example of using a WebView to do just this). \n\n## Journo viewer\nThe [Journo Viewer](viewer/readme.md) is a simple but powerful gui tool to create reports. It can significantly shorten the report creation lifecycle.\n\n## Documentation etc.\nFor more information please see [the wiki](https://github.com/Alipsa/journo/wiki/Journo-Wiki-Home)\n\n## License\nThe journo code is licensed under the MIT license.\nNote that it heavily depends on Freemarker and OpenHTMLtoPDF which are\nlicenced under the Apache License (Freemarker) and\nLGPL (OpenHTMLtoPDF) respectively.\n\n## 3:rd party libraries used\n\n### Freemarker (https://freemarker.apache.org/)\n- Used to create the (x)html\n- Apache License Version 2.0\n\n### OpenHTMLtoPDF (https://github.com/openhtmltopdf/openhtmltopdf)\n- Used to create PDFs\n- GNU Lesser General Public License, version 2.1 or later\n\n### Jsoup (https://jsoup.org/)\n- Used to convert html to xhtml\n- MIT license\n\n### Batik (https://xmlgraphics.apache.org/batik/)\n- Used to convert SVG to bitmaps\n- Apache License, Version 2.0\n\n### SLF4J (https://www.slf4j.org/)\n- Used for logging\n- MIT license\n\n## Test dependencies\n\n### Junit Jupiter (https://junit.org/junit5/)\n- Used for test assertions\n- Eclipse Public License 1.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falipsa%2Fjourno","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falipsa%2Fjourno","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falipsa%2Fjourno/lists"}