0

I have a thymeleaf html template with custom css styling and a 'flying saucer' to produce the pdf and download from the GET REST endpoint.

Here is the project folder structure of the project with template: enter image description here

When I run the Application class and use the endpoint, the pdf downloaded has the css styling applied as expected. However, when it is packaged in a jar and run, pdf downloaded does not have the styling applied.

This is how it looks in jar: enter image description here

And here is how html template looks for styling.css

<head>
<meta charset="UTF-8"/>
<link th:href="@{src/main/resources/templates/styling.css}" rel="stylesheet" type="text/css"/>

Can anybody please tell me what's wrong when applicaion is packged in jar?

tyro
  • 577
  • 8
  • 17

1 Answers1

0

In the thymeleaf template, I had an absolute path for external css as mentioned in

<link th:href="@{src/main/resources/templates/styling.css}" rel="stylesheet" type="text/css"/>

And when application as jar, the path to css is not the same hence it's not resolved.

I tried with relative path like

<link th:href="@{/templates/styling.css}" 

but this does not work with thymeleaf's Context class, it only works with IWebContext class.

So as a solution, I had to add inliner styles to the template to make it work with styled pdf generation.

tyro
  • 577
  • 8
  • 17