Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVGs not supported by PDF library #1108

Closed
Tracked by #1533
timobrembeck opened this issue Jan 18, 2022 · 5 comments · Fixed by #1291
Closed
Tracked by #1533

SVGs not supported by PDF library #1108

timobrembeck opened this issue Jan 18, 2022 · 5 comments · Fixed by #1291
Labels
🐛 bug Something isn't working ❗ prio: medium Should be scheduled in the forseeable future.
Milestone

Comments

@timobrembeck
Copy link
Member

Describe the Bug

At the moment, we use svg images as icons and the media export from wordpress also might contain svg images.
These images are not included in PDFs which are generated with xhtml2pdf.
The corresponding issue is: xhtml2pdf/xhtml2pdf#73
Apparently, there is an open PR for it (xhtml2pdf/xhtml2pdf#561), but it shows no recent activity.

As solution, I see 3 options:

  1. Change our icons to png and convert all svgs to pngs during the media export
  2. See what's holding up the upstream process and try support the library maintainers
  3. Switch to another PDF library

Steps to Reproduce

  1. Insert SVG into page
  2. Convert this page to PDF
  3. The image is missing in the PDF

Expected Behavior

The image should be included in the PDF

Actual Behavior

The image is missing and the error PIL.UnidentifiedImageError: cannot identify image file appears in the console

Traceback
Jan 18 16:23:49 WARNING integreat_cms.cms.utils.pdf_utils - The file 'http://localhost:8000/static/svg/pin.svg' is not inside the static directories '/static/' and '/media/'.
Jan 18 16:23:49 INFO django.server - "GET /static/svg/pin.svg HTTP/1.1" 200 781
Jan 18 16:23:49 WARNING xhtml2pdf - Error in handling image
'<img style="width: 15px; height: 15px;" src="http://localhost:8000/static/svg/pin.svg"/>'
Traceback (most recent call last):
  File "/integreat/integreat-cms/.venv/lib/python3.9/site-packages/xhtml2pdf/xhtml2pdf_reportlab.py", line 350, in __init__
    self._image = self._read_image(self.fp)
  File "/integreat/integreat-cms/.venv/lib/python3.9/site-packages/xhtml2pdf/xhtml2pdf_reportlab.py", line 380, in _read_image
    return PILImage.open(fp)
  File "/integreat/integreat-cms/.venv/lib/python3.9/site-packages/PIL/Image.py", line 3008, in open
    raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f04716d3d10> fileName=<_io.BytesIO object at 0x7f04716d3d10>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/integreat/integreat-cms/.venv/lib/python3.9/site-packages/xhtml2pdf/tags.py", line 344, in start
    img = PmlImage(
  File "/integreat/integreat-cms/.venv/lib/python3.9/site-packages/xhtml2pdf/xhtml2pdf_reportlab.py", line 487, in __init__
    img = self.getImage()
  File "/integreat/integreat-cms/.venv/lib/python3.9/site-packages/xhtml2pdf/xhtml2pdf_reportlab.py", line 508, in getImage
    img = PmlImageReader(six.BytesIO(self._imgdata))
  File "/integreat/integreat-cms/.venv/lib/python3.9/site-packages/xhtml2pdf/xhtml2pdf_reportlab.py", line 369, in __init__
    raise RuntimeError("{0} {1} {2}".format(et, ev, tb))
RuntimeError: <class 'PIL.UnidentifiedImageError'> cannot identify image file <_io.BytesIO object at 0x7f04716d3d10> fileName=<_io.BytesIO object at 0x7f04716d3d10> <traceback object at 0x7f0469e96340>

Additional Information

@timobrembeck timobrembeck added 🐛 bug Something isn't working ❗ prio: medium Should be scheduled in the forseeable future. labels Jan 18, 2022
@timobrembeck timobrembeck added this to the Version 1.1 milestone Jan 18, 2022
@luisza
Copy link

luisza commented Jan 28, 2022

Hi, sorry the delay, PR in xhtml2pdf was merge today, and I how in few days I will launch a new release.

@timobrembeck
Copy link
Member Author

@luisza Awesome, thank you so much for fixing the problem and letting us know about it!

@svenseeberg svenseeberg added the ⛔ blocked Blocked by external dependency label Feb 19, 2022
@ulliholtgrave
Copy link
Member

ulliholtgrave commented Mar 2, 2022

@luisza Hey,
Our project is really interested in this feature and we wanted to ask if we can help with anything to speed up the process? If developer hours are needed, feel free to contact us. We would also be willing to put an issue bounty on the feature if your project supports something like that :)
And thanks for your great work. xhtml2pdf has been proven to be super helpful! 👍

@luisza
Copy link

luisza commented Mar 2, 2022

Hi,
Thanks for your offer, right now I need people testing master branch, checking that everything works as expected. If you can confirm that master branch works well, I can make the release faster.
This new release drop python2 support, change some parts of the base code, and update libraries, our automated test are working, but are insufficient, there is many situations that don't are tested so I have to make manual test also.
I think I am closest to have a release.

@svenseeberg svenseeberg removed the ⛔ blocked Blocked by external dependency label Mar 5, 2022
@ulliholtgrave
Copy link
Member

@luisza Hey Luisza,
Thanks for the reply. We'll try to help with the testing of the master branch :) Is there some place where we can document the tested functions/features? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working ❗ prio: medium Should be scheduled in the forseeable future.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants