1

When I watermark a pdf onto another pdf any semi-transparency in the watermark PDF is made completely opaque. Is there anything I can do about this or is this a limitation of CFPDF?

Server is CF9 with latest hotfixes.

Fun bit, when chrome renders the final product the transparency is preserved, but when Acrobat Pro renders it it's opaque. I can print the final product to AdobePDF and it's accurately transparent, but I don't get a consistent page size to send through our print shop which is a showstopper issue.

Code added per request:

<cfpdf  action="addwatermark" 
    source="#BackgroundPDF#" 
    copyfrom="#ForegroundPDF#" 
    destination="#DestinationPDF#" 
    foreground="yes" 
    opacity="10" 
    overwrite="yes" 
    position="#XYPositioning#" 
    rotation="#RotationIfRequired#" 
    showonprint="yes"
  >

Additional detail I've discovered as I go along: if I get on Acrobat pro, I can go to print production, and output preview and change the "show" option to "Not DeviceCMYK" and I get my transparency back, but this is just some kind of preview, how do I actually remove that colorspace from the PDF?

invertedSpear
  • 10,864
  • 5
  • 39
  • 77

1 Answers1

2

Thanks to the help provided by @mkl Here we were able to figure out how to monkey patch the pdf binary. So then I just need to be able to do so in CF. Since reading the file in as a text file causes problems due to character encoding I was able to do this.

  1. Identify the text to change in the binary. This is what @mkl helped my with. The problem text is "/K true" which is telling the PDF to use knockout groups which I'm sure makes sense to PDF experts but is total Greek to me.

  2. Read the pdf into coldfusion as a binary <cffile action="readbinary" file="#inputPath#" variable="input">

  3. Encode the binary bytearray to Hex <cfset temp=BinaryEncode(input,"Hex")>

  4. Remove the, now hex, string I want removed <cfset temp2 = ReplaceNoCase(temp,"2F4B2074727565","","All")><!--- 2F4B2074727565 is HEX for /K true --->

  5. Decode the Hex back into a bytearray <cfset output = BinaryDecode(temp2,"Hex")>

  6. Write the output file to the file system <cffile action="write" file="#outputPath#" output="#output#" nameconflict="overwrite">

Now you have a PDF that looks like expected. The problem is that there is something wrong with it. If I open it, do nothing, and close it I'm prompted to save. If I save it, I no longer have an issue. I figured that a CFPDF merge operation would do basically this without requiring a user to do something so I added this final step.

  1. Resave the pdf with the merge command <cfpdf action="merge" source="#outputPath#" destination="outputPath2" pages="1" overwrite="yes">
Community
  • 1
  • 1
invertedSpear
  • 10,864
  • 5
  • 39
  • 77
  • *Remove the, now hex, string I want removed* - do not remove, instead replace with spaces, i.e. "20202020202020". Then you don't need to fix cross reference entries in the end. – mkl May 08 '14 at 04:10
  • @mkl - Can you explain further what you mean? I'd follow you're instructions blindly here, but I like to understand why I'm doing things. – invertedSpear May 12 '14 at 16:56
  • You do `ReplaceNoCase(temp,"2F4B2074727565","","All")` but I'd advice you to do `ReplaceNoCase(temp,"2F4B2074727565","20202020202020","All")`. This way all offsets remain correct. – mkl May 12 '14 at 20:27
  • @mkl - I understand what to do, but what do you mean by "all offsets remain correct." What problems might occur if they do not? – invertedSpear May 15 '14 at 19:09
  • *What problems might occur if they do not?* - The problem you have witnessed, the problem that forces you to *Resave the pdf with the merge command*. A PDF file contains a cross reference structure indicating at which byte offset in the file to find certain information. If you remove bytes, those cross references are incorrect. If you replace data with the same amount of spaces, those cross references remain correct. – mkl May 16 '14 at 13:42