Skip to content

saveAs file exists exception #2

@danderson421

Description

@danderson421

I can't seem to find a way to overwrite an existing pdf file. the saveAs function will not overwrite an existing file. ColdFusion keep the file open and a simple cffile delete & rename cannot be done.

Error says file is open by Coldfusion.

I'm simply trying to replace the input file after the operation is complete.

<cfset variables.source = createObject('java','com.adobe.pdfservices.operation.io.FileRef').createFromLocalFile(variables.docPath)> <cfset variables.destination = variables.docDir & "\COM." & variables.docFile> <cfset pdfOp = createObject('java', 'com.adobe.pdfservices.operation.pdfops.CompressPDFOperation').createNew()> <cfset pdfOp.setInput(source)> <cfset ev = auth()> <cfset result = pdfOp.execute(ex)> <cfif IsObject(result)> <cfset result.saveAs(variables.destination)> <cfif FileExists(variables.destination)> <cffile action="delete" file="#variables.docPath#"> <cffile action="rename" source="#variables.destination#" destination="#variables.docPath#"> </cfif> </cfif>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions