vizicsaba89 / pdf-signer

sign pdf documents
MIT License
38 stars 33 forks source link

When I change the image to transparent png, the background color of the image will become black after signing #3

Closed ccmBlockChain closed 3 years ago

ccmBlockChain commented 4 years ago

When I change the image to transparent png, the background color of the image will become black after signing

imagePath: './assets/icon_next@3x.png'

The results are as follows: image

pankucsi commented 4 years ago

Thank you for opening this issue, we will look after and try to fix these issue as soon as we can.

HanderUp commented 3 years ago

@pankucsi @vizicsaba89 Hello, I also encountered this problem. After trying, I did this. I don’t know if it’s correct. I hope you can point it out, thanks!

png-appender.ts : 50

pngBaseData['SMask'] = [val, val]

png-appender.ts : 58

pngBaseData['SMask'] = mask

png-appender.ts : 67

pngBaseData['SMask'] = sMask
pngBaseData['Length'] = imgData.length

png-appender.ts : 128


const getSmask = (pdf: PdfCreator, image: any, alphaChannel: Buffer) => {
let sMask
if (image.hasAlphaChannel) {
const sMaskData: PNGBaseData = {
Type: 'XObject',
Subtype: 'Image',
BitsPerComponent: 8,
Width: image.width,
Height: image.height,
Length: alphaChannel.length,
Filter: 'FlateDecode',
ColorSpace: 'DeviceGray',
}
sMask = pdf.appendStream(sMaskData, alphaChannel)

}

return sMask }



The results are as follows:
Before:
![image](https://user-images.githubusercontent.com/22523322/103746462-1bd2ed00-503c-11eb-991b-be3c25d4b3cc.png)

After:
![image](https://user-images.githubusercontent.com/22523322/103746573-42912380-503c-11eb-80a9-2bf92ff6074f.png)
pankucsi commented 3 years ago

@HanderUp

Nice one ! I will publish this fix in the next version.