Skip to main content
Participant
January 6, 2011
Answered

CFPDF GetInfo "Invalid date format"

  • January 6, 2011
  • 1 reply
  • 1438 views

We receive PDF documents via a upload function we incorporated and once the file is saved to our server we perform     the following action

<cfpdf action="getinfo"       name="pdfInfoStc"       source="#uploadResult.serverDirectory#/#uploadResult.serverFile#">    

this works great if the PDF was made from a genuine source but a lot     of times we're receiving files from low end scanners or banks that aren't     saving a created date so the getinfo action fails with     the message "Invalid date format" which makes sense as the date     doesn't obviously exist, however it's not really acceptable that the     getinfo process couldn't just return back a null value or blank     string rather then throw  a massive coldfusion error?

Currently running Coldfusion Enterprise version is 8,0,1,195765


Has anyone else ever ran into this bug / problem before and found a     solution?

    This topic has been closed for replies.
    Correct answer meensi

    Hi,

    I have not used this tag, by surfing I got this.

    Created

    D:20061121155226-05'00'

    System-generated creation date of the PDF document. You can specify a text string with the setInfo action.

    We can set the created using this setInfo.

    Which ever PDF is throwing an error, you could possibly catch the exception and using this setInfo, you could set created date.

    <cfset PDFinfo=StructNew()> 
    <cfset PDFinfo.Title="Make Way for Ducklings">
    <cfset PDFinfo.Author="Donald Duck">
    <cfset PDFinfo.Keywords="Huey,Dewy,Louie">
    <cfset PDFinfo.Subject="Ducks">

    <cfpdf action="setInfo" source="chap1.pdf" info="#PDFinfo#" destination="meta1.pdf" overwrite="yes">

    1 reply

    meensiCorrect answer
    Inspiring
    January 7, 2011

    Hi,

    I have not used this tag, by surfing I got this.

    Created

    D:20061121155226-05'00'

    System-generated creation date of the PDF document. You can specify a text string with the setInfo action.

    We can set the created using this setInfo.

    Which ever PDF is throwing an error, you could possibly catch the exception and using this setInfo, you could set created date.

    <cfset PDFinfo=StructNew()> 
    <cfset PDFinfo.Title="Make Way for Ducklings">
    <cfset PDFinfo.Author="Donald Duck">
    <cfset PDFinfo.Keywords="Huey,Dewy,Louie">
    <cfset PDFinfo.Subject="Ducks">

    <cfpdf action="setInfo" source="chap1.pdf" info="#PDFinfo#" destination="meta1.pdf" overwrite="yes">

    Kaotic101Author
    Participant
    January 7, 2011

    This does seem to fix the issue for the getInfo action if you set the Created property on the struct.

    <cfset pdfInfoStc = StructNew()>
    <cfset pdfInfoStc.Created = "D:" & DateFormat(now(), "YYYYMMDD") & TimeFormat(now(), "HHmmss") & "-00'00'">

    <cfpdf action="setinfo" overwrite="yes" info="#pdfInfoStc#"
                source="#uploadResult.serverDirectory#/#uploadResult.serverFile#"
                destination="#uploadResult.serverDirectory#/#newFileName#">

    However it does bring me back to my original problem of why I needed to run a getInfo action to begin with, we need to check if the PDF has any type of security on it and if it does return a message back to the user saying we're unable to work with the PDF. Running a setinfo action on a secured PDF also throws a massive error as it's unable to modify the PDF... It would be really convenient if Coldfusion could just return a getinfo regardless of which fields are filled in or not.

    Kaotic101Author
    Participant
    January 7, 2011

    I figured out a workaround for the issue using a series of if / try / catch statements for anyone else who ever runs into this issue...

    <!--- Scrub filename for dirty characters --->
    <cfset newFileName = "fixed.pdf">

    <cfset pdfInfoStc = StructNew()>
    <cfset pdfInfoStc.Encryption = "No Security">
    <cfset pdfInfoStc.Created = "D:" & DateFormat(now(), "YYYYMMDD") & TimeFormat(now(), "HHmmss") & "-00'00'">
    <cftry>
        <!--- Try and set new information for PDF --->
        <cfpdf action="setinfo" overwrite="yes" info="#pdfInfoStc#"
            source="#uploadResult.serverDirectory#/#uploadResult.serverFile#"
            destination="#uploadResult.serverDirectory#/#newFileName#">
           
        <cfcatch type="any">
            <!--- Check to see if setinfo failed because of secured document --->
            <cfif Find("password", cfcatch.Detail, 1) gt 0>
                <cfset pdfInfoStc.Encryption = "Password Security">
                <cffile action="move" mode="777"
                    source="#uploadResult.serverDirectory#/#uploadResult.serverFile#"
                    destination="#uploadResult.serverDirectory#/#newFileName#">
            </cfif>
        </cfcatch>
    </cftry>

    <!--- Check to make sure PDF is not secured --->
    <cfif pdfInfoStc.Encryption eq "No Security">
        <!--- Grab PDF Information --->
        <cfpdf action="getinfo" name="pdfInfoStc" source="#uploadResult.serverDirectory#/#newFileName#">
    </cfif>

    <!--- Check to make sure PDF is not secured --->
    <cfif pdfInfoStc.Encryption neq "No Security">
        <!--- NOTIFY USER DOCUMENT IS SECURED --->
    </cfif>