Skip navigation
Currently Being Moderated

cfpdf watermark issue

Oct 20, 2011 8:21 AM

Tags: #pdf #coldfusion #cfpdf

All,

 

I'm having a problem when adding a watermark to a pdf document.  Here is the sample code below:

 

<!--- Merge 2 documents together --->

<cfpdf

  action="merge"

  source="test.pdf, test2.pdf"

  destination="merged.pdf"

  overwrite="yes">

 

<!--- Add text watermark to the newly merged pdf --->

<cfpdf

  action="addwatermark"

  text="Hello"

  source="merged.pdf"

  overwrite="yes"

  foreground="yes"

  destination="watermark.pdf">

 

<!--- Output file to user and then delete --->

<cfcontent

  file="http://WEB-ADDRESS/watermark.pdf"

  type="application/pdf"

  deletefile="yes">

 

The files merge together properly and the text watermark is added successfully.  However, when I change the watermark to something like, "Hello1", save, then hit the back button in the browser and try to merge again, it still shows, "Hello", and not "Hello1".  If I close the browser down, and reopen, then "Hello1" properly shows. 

 

Seems like it's storing this in cache somehow.  As shown in the code above, I tried adding the 'deletefile="yes"' to the <cfcontent> tag, but it is not deleting the file after displaying to the user (I checked the folder location).  Also, I've tried adding, "<cfcache action="flush">" to the top of my page, but no success either. 

 

Can you guys think of any other way to delete this file, or some other solution?

 

Thanks for the help.

 
Replies
  • Currently Being Moderated
    Oct 20, 2011 8:26 AM   in reply to jfvaught

    Sounds like it's just your browser caching the PDF as the URL hasn't changed so it thinks it's the same document and tries to be clever. I'm not sure if there's any kind of meta tag you can pass in an octet stream, is creating a dynamic PDF name on the fly an option, or does it have to have the name it has? That's the easiest sure-fire way of getting a fresh download each time.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 20, 2011 8:38 AM   in reply to jfvaught

    Yup, you'd need to have some way of monitoring or deleting old files, unless the onRequestEnd method is usable here.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 22, 2011 9:33 AM   in reply to jfvaught

    If you go with the dynamic naming scheme, you could use the code below as a scheduled task to simply delete all the files on a given interval, like daily, weekly, monthly, etc.

     

    <cfdirectory directory="path/to/folder/containing/files/to/be/deleted/" action="list" name="docList">

    <cfif #docList.recordcount# gt 0>

        <cfloop query="docList">

            <cffile action="delete" file="path/to/folder/containing/files/to/be/deleted/#name#">

        </cfloop>

     

    <cfmail>- - - optional - - -</cfmail>

     

    </cfif>

     

    I use this for a client that desires to retain pdf copies of submissions for a 30 day period. Once the scheduled task is set, it triggers on the set interval and if there are files to be deleted does so and sends me an email letting me know it was done. If there are no files, nothing happens.

     

    Just another thought to consider.

     

    Leonard B

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points