pdfcoldfusioncoldfusion-9acrobatcfpdf

CFPDF add watermark any level of transparency is coming out opaque


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?


Solution

  • 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">