Skip to main content
April 28, 2010
Question

Why does AddWatermark make file so big?

  • April 28, 2010
  • 1 reply
  • 4209 views

I have created a 600 x 253 72 dpi gif file.  It is only 36kb in size.  When I take a 7 page 220kb PDF file and do a cfpdf action="addwatermark" to the file, it grows from 220kb to a whopping 1.3 MB!

Strangely enough, if I open the same file in Adobe Acrobat Professional and manually add the exact same gif file as a watermark to the exact same PDF file, the result file actually got SMALLER!?!?!

You don't believe me?  Try it yourself.

Image file: https://www.calcerts.com/images/logo_main_watermark_color.gif

Original PDF: https://www.calcerts.com/BB4031.pdf

PDF File after doing a simple addwatermark: https://www.calcerts.com/BB4031_WTF.pdf

PDF File if I add the image as a watermark in Adobe Acrobat Professional 8: https://www.calcerts.com/BB4031_AdobeWatermarked.pdf

The code I used was this:

<cfpdf action="addwatermark"
  source="d:\BB4031.pdf"
  destination="d:\BB4031_WTF.pdf"
  image="D:\images\logo_main_watermark_color.gif"
  opacity = 2
  foreground = "yes"
  rotation = 0
  showonprint = "yes"
  overwrite="yes"
  position = "0,250"
  >

This topic has been closed for replies.

1 reply

Inspiring
April 29, 2010

My guess would be it is how the watermark image is added internally. From the size increase, it seems like the image bytes are added to the pdf multiple times. ie Once per page. As opposed to adding them once, and then reusing some sort of reference.  But that is just a guess. You might also submit a bug report on this behavior.

If you have createObject("java") access, you could always use iText to add the watermark. It is not as simple as cfpdf. But done correctly, it does not increase the file size so drastically.  If you are looking for an iText example, see the entry below. I wrote it for another problem. But you could easily adapt it.

http://cfsearching.blogspot.com/2009/06/cfpdf-issues-when-using-transparent.html

Message was edited by: -==cfSearching==-

April 29, 2010

Awesome.  It does not answer the why problem, but it did offer an alternative thing for me to do.  The iText worked great.  I think I am going to be doing some iText learning, because the file is significantly smaller.

As you said, it's not as easy, but it works nicely.

Also, FYI - you need to fix your sample code. On line 30, it says:

ii = i + 1;

I think you need only one i.  The while loop goes to infinity. 

Inspiring
April 29, 2010

Awesome.  It does not answer the why problem, but it did

offer an alternative thing for me to do. 

Yes, I do not know the technical implementation. But it is a pretty good guess the image bytes are being added multiple times. Do not forget to submit a bug on it.

Also, FYI - you need to fix your sample code. On line 30,

it says:

 

ii = i + 1;

 

I think you need only one i.  The while loop goes to

infinity. 

Thanks. I will check into that. Most likely blogger is messing up the code examples. It does something funky to the formatted code whenever certain elements are present like BR's. (Thank you very much blogger ...;)