johndoe31415 / pdfminify

PDF minifier that allows removing duplicate data, re-compresses images, creation of PDF/A-1b and digital PDF signing
GNU General Public License v3.0
55 stars 11 forks source link

Getting ValueError: 255 is not a valid PNGPredictor #10

Closed mat100payette closed 3 years ago

mat100payette commented 3 years ago

Running the thing with no optional parameters, I get ValueError: 255 is not a valid PNGPredictor.

Here's the stacktrace:

Traceback (most recent call last):
  File "c:\users\matpa\anaconda3\envs\wastack-test-2\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\matpa\anaconda3\envs\wastack-test-2\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\matpa\Anaconda3\envs\wastack-test-2\Scripts\pdfminify.exe\__main__.py", line 4, in <module>
  File "c:\users\matpa\anaconda3\envs\wastack-test-2\lib\site-packages\pdfminify\__main__.py", line 148, in <module>
    pdf_filter.run()
  File "c:\users\matpa\anaconda3\envs\wastack-test-2\lib\site-packages\llpdf\filters\DownscaleImageOptimization.py", line 94, in run
    resampled_image = self._rescale_image(image, scale_factor)
  File "c:\users\matpa\anaconda3\envs\wastack-test-2\lib\site-packages\llpdf\filters\DownscaleImageOptimization.py", line 55, in _rescale_image
    resampled_image = reformatter.reformat(image)
  File "c:\users\matpa\anaconda3\envs\wastack-test-2\lib\site-packages\llpdf\img\ImageReformatter.py", line 112, in reformat
    reformatted_image = self._reformat_channel(image, lossless)
  File "c:\users\matpa\anaconda3\envs\wastack-test-2\lib\site-packages\llpdf\img\ImageReformatter.py", line 79, in _reformat_channel
    image.writefile(src_img_file.name)
  File "c:\users\matpa\anaconda3\envs\wastack-test-2\lib\site-packages\llpdf\img\PDFImage.py", line 189, in writefile
    pnm_image = self.get_pnm()
  File "c:\users\matpa\anaconda3\envs\wastack-test-2\lib\site-packages\llpdf\img\PDFImage.py", line 159, in get_pnm
    pixeldata = self.get_pixeldata()
  File "c:\users\matpa\anaconda3\envs\wastack-test-2\lib\site-packages\llpdf\img\PDFImage.py", line 153, in get_pixeldata
    return self._imgdata.decode()
  File "c:\users\matpa\anaconda3\envs\wastack-test-2\lib\site-packages\llpdf\EncodeDecode.py", line 208, in decode
    return self._depredict(self._decompress())
  File "c:\users\matpa\anaconda3\envs\wastack-test-2\lib\site-packages\llpdf\EncodeDecode.py", line 172, in _depredict
    png_filter = PNGPredictor(deencoded_data[i])
  File "c:\users\matpa\anaconda3\envs\wastack-test-2\lib\enum.py", line 309, in __call__
    return cls.__new__(cls, value)
  File "c:\users\matpa\anaconda3\envs\wastack-test-2\lib\enum.py", line 600, in __new__
    raise exc
  File "c:\users\matpa\anaconda3\envs\wastack-test-2\lib\enum.py", line 584, in __new__
    result = cls._missing_(value)
  File "c:\users\matpa\anaconda3\envs\wastack-test-2\lib\enum.py", line 613, in _missing_
    raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 255 is not a valid PNGPredictor

Any idea what's up with that ?

johndoe31415 commented 3 years ago

Hey there. Thanks for trying out pdfminify.

I believe pdfminify is right here. It refers to the PNG Predictor byte which indicates how a PNG row relates to the previous row. It's defined in the PNG standard RFC2083, https://datatracker.ietf.org/doc/html/rfc2083 -- Sect. 6.1 shows which types of predictors there are. There are five in total (values 0 to 4), but the PNG you seem to have embedded in your PDF has 255 there.

Either this is a malformed PNG inside your PDF or that is some PNG extension that is newer than the standard which I am unaware of. In either case it is not easy for me to tell what is supposed to happen without having seen the PDF file. If you could send it over, I can try to see what is going ion.

johndoe31415 commented 3 years ago

Closing this for inactivity. Please feel free to reopen.