jung-kurt / gofpdf

A PDF document generator with high level support for text, drawing and images
http://godoc.org/github.com/jung-kurt/gofpdf
MIT License
4.33k stars 782 forks source link

Prevent image duplication #296

Closed joewestcott closed 5 years ago

joewestcott commented 5 years ago

Currently, it's possible to end up with the same image inserted into the final PDF multiple times.

This is possible if you register the same image under two different keys (unlikely), but it's also possible when trying to use the same image in multiple templates. The CreateTemplate example actually attempts this and the image is written into the PDF twice. After this
change the filesize is reduced by about 20%.

It accomplishes this by storing the SHA-1 hash of each inserted image, and re-uses the objects ID if it's found. I've also committed my comments in a bunch of places from trying to understand the codebase.

joewestcott commented 5 years ago

On second inspection, I think I've found a better way to do this. Please hold off on merging for now...!

jung-kurt commented 5 years ago

@joewestcott -- will do, thanks for the tip-off.

joewestcott commented 5 years ago

I've placed my proposed breaking changes in another PR. This one should be fine!