mozilla / pdf.js

PDF Reader in JavaScript
https://mozilla.github.io/pdf.js/
Apache License 2.0
47.09k stars 9.81k forks source link

Handle transparent images in the createImage method of the StampAnnotation class #18299

Closed pirogom closed 1 week ago

pirogom commented 1 week ago

Modify the createImage method of the StampAnnotation class in src/core/annotation.js

The existing createImage method always fills the background with white before saving the image data as JPEG, even if the image data includes an alpha channel. This results in all image data, including those with alpha channels, being forcibly converted to JPEG.

The PDF format manages a separate mask stream for the alpha channel. Therefore, image data that includes an alpha channel has been modified to include DecodeParms and use the FlateDecode filter instead of DCTDecode

Snuffleupagus commented 1 week ago

Please remember that the commit message should have the same title as the pull request, and then contain all same context as you included in https://github.com/mozilla/pdf.js/pull/18299#issue-2363641412.