I did some experiments this morning. My test image was 800x600 with a file size of 100.69K when saved as a PNG. I pasted this into a PDF (using iTextSharp and the regular GetInstance () method), and the file size increased from 301.71K to 402.63K. Then I re-saved the test image as a raw bitmap with a file size of 1,440,054. I pasted this into a PDF and the file size went down to 389.81K. Interesting!
I did some research on the Internet for a possible explanation, and based on what I found, it seems that iTextSharp is not compressing images, but rather compressing everything with some general compression. In other words, BMP is not actually converted to another type of file, it is simply compressed in the same way as in a ZIP archive. No matter what they do, this should be good, as it is compressed better than an image with PNG compression. I assume that iTextSharp woudld will try to compress PNG, but will compress by 0% since it is already compressed. (This is incompatible with the original comments of the author, although ... Paddy said that his size in PDF format is much larger than the size of PNG ... I'm not sure what to do with it. I can only continue my own experiments).
Conclusions:
1) I do not need to add any fancy library to my project in order to convert my (possible dynamically created) image to PNG; in fact, it's best to leave it completely uncompressed and let iTextSharp do all the compression work.
2) I also read material on the Internet about saving iTextSharp images in a specific DPI. I did NOT see this problem ... I used the ScalePercent () method to scale the bitmap to 1% and the file size was the same and there were no βlossesβ in the bitmap pixels ... this confirms that iTextSharp does simple, pleasant, general lossless compression.
source share