Commit 023c6c78 authored by Adrià Labay's avatar Adrià Labay
Browse files

fallback to wand if pike pdf fails to decode img with ByteAlign true

parent 68af6d43
......@@ -8,6 +8,7 @@ import re
from flask import current_app
from PIL import Image
from pikepdf import Pdf, PdfImage, PdfError
from pikepdf.models.image import UnsupportedImageTypeError
from tempfile import SpooledTemporaryFile
from wand.image import Color, Image as WandImage
from reportlab.lib.units import inch
......@@ -217,8 +218,9 @@ def extract_images_from_pdf(file_path_or_buffer, file_info=None, dpi=300, only_i
# Try to use PikePDF, but catch any error it raises
img = extract_image_pikepdf(page)
except (ValueError, AttributeError, NotImplementedError, PdfError):
except (ValueError, AttributeError, NotImplementedError, UnsupportedImageTypeError, PdfError):
# Fallback to Wand if extracting with PikePDF failed
# UnsupportedImageTypeError is raised when /CCITTFaxDecode with /EncodedByteAlign true (535)
use_wand = True
if use_wand:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment