senny / sablon

Ruby Document Template Processor based on docx templates and Mail Merge fields.
MIT License
443 stars 126 forks source link

Rendering an image where filename contains special characters (ä, ö, ü, ß) fails #136

Open ChrisKaun opened 5 years ago

ChrisKaun commented 5 years ago

Hey,

I'm rendering an image to sablon content via uri and filename Sablon.content(:image, uri, filename: name).
If the name variable contains any special characters like ä, ü, ö, ß this will fail and sablon will display a blackish image replacement instead.

stadelmanma commented 5 years ago

I suspect this is a limitation in MS Word since that "name" parameter is used as the filename inside the DOCX zip file structure. Word gets around this by renaming everything image1, image2, etc. My advice would be to just strip out the special characters entirely.

ChrisKaun commented 5 years ago

As you already mentioned a valid work around in my case is to strip the special characters from the file name.
What happens when a file is directly loaded from a path, without specifying a filename parameter?
Sablon.content(:image, 'fixtures/images/c3pö.jpg') Would this still fail?

Don't think that the special characters should be stripped inside the sablon-code, but a note should be added to the docs that some characters might not be supported.