0

I am currently creating pdfs with images using pdfbox in a vaadin application. I am wondering how I could use the same images path in pdfbox that is used by the vaadin theme.
Right now I'm still using a .properties file to point to an images-folder, but I'd prefer if I could just put the images in the theme folder. That way I could easily add images to the folder and have them in git. This automation would save me trouble of making sure the .properties file and images are working on different machines.

The best solution I found so far is using Application.class.getResource("/images").toString(); What I dont like about that is that it returns it in the format of "file:". I could just remove the "file:"-part, but I was wondering if theres a better solution for this?

Tigerware
  • 3,196
  • 2
  • 23
  • 39
  • Do you mean you create pdfs during the runtime? And you want them to be accessible by the users of the vaadin aplication? – kukis May 24 '16 at 09:18
  • So, you want to determine where the image under VAADIN/themes/yourtheme/imagxyz.img is located on your local file system? – Steffen Harbich May 24 '16 at 09:32
  • @SteffenHarbich Yes thats what im looking for. – Tigerware May 24 '16 at 20:38
  • @kukis Yes I am creating the pdfs during runtime (when the user clicks a button). That part works so far. The local folder that is used by the vaadin theme I want to use to locate a picture and place that in the pdf. The only paths I found were refering to the online URL of the application. – Tigerware May 24 '16 at 20:42

1 Answers1

0

First get the servlet context via VaadinServlet (see also this answer).

ServletContext servletContext = VaadinServlet.getCurrent().getServletContext();

Then call

String path = getServletContext().getRealPath("/VAADIN/themes/...");

According to the docs it might be not possible if you have a web app that is not unpacked from WAR file.

Community
  • 1
  • 1
Steffen Harbich
  • 2,639
  • 2
  • 37
  • 71