benjohnde/play-pdf

image source not displayed in prod mode

ASchmidt84 opened this issue · 11 comments

Hi,

i have inserted an tag. In develop mode their is no problem. the images is shown all the time.
But in production mode, the images is not shown. And it dows not have effect to use an hosted image on another server. Same with @routes.Assets("images/....jpg")

Don´t know where the problem is.

I am using IntelliJ and sbt to create a dist.

It is because you compile it to a .jar-file, the current version of this library does not support that. Same issue arises for including custom fonts.

Hi Wolfert,
thanks for your reply.

Okay. That makes sense. The issue with the font I corrected. I make the dir, when I start my application in prod mode. So the folder is created and I can copy the fonts in it. Is terrible, but a solution for this moment.

But I dont have any idea about the issue with the images. Do you think it download the image file anywhere? Maybe we can make a solution like the above?

Thanks a lot.

I think I actually solved this issue with commit 4fbdfd9

Use the documentBaseUrl, this url is the base from which 'images/yourimage' will be loaded. The call becomes: PDFExtern.toBytes(views.html.pdf.pdf(),"http://youwebsiteurl")

I see.
Is it neccessary to create the folder "images/...." manual?
Oh I see their is no new version ready for download over sbt/maven.
I think I should use your code.

The folder that worked in develop mode will work in prod mode when you use documentBaseURL.

My commit is merged in the last version, version 0.5 I believe. But if you want a 'better' solution for your fonts issue, use my fork: https://github.com/Wolfert/play20-pdf - fonts are handled differently there.

Okay I tried it with the base url. First http://www.domain.tld second with /var/www/......
I added the place for the folder and created it. But both dont has any effect.

Did I a mistake?

Suppose the image is located at http://domain.tld/assets/images/image.jpg, and the pdf is rendered at http://domain.tld.

You have to pass http://domain.tld as the documentBaseURL, and then in your view call to the asset as you would normally using @routes.Assets("images/image.jpg").

Ok that will help for local images. Thanks I will try it.

But sometimes I have images located on a other webserver. For example http://t2.ftcdn.net/jpg/00/54/75/31/400_F_54753118_IAo94t0LKjkXg6nhjUgNBLnkX1WSoScx.jpg

This images wont be placed

You can place those directly in the img href="url", should work for external images.

I did! But no effect. No image. That is the problem :(

Found the error with the http://. It was a misconfiguration.
Your updates solve all other problems. 👍
Thanks