carrizal
carrizal

Reputation: 724

Why the unknown error?

This is my error message:

ColdFusion could not delete the file C:\path\guid.png for an unknown reason.

I've already checked to make sure my coldFusion user has permission to do so, as suggested here. That is not the problem, the user has all the permissions. Unfortunately, the code is breaking on production servers, and not my own local server (could be relevant). Production is on CF11 but I am on CF9.

Here is the code:

<cffunction name="svgToPDF" access="public" output="false" returntype="string">
    <cfargument name="svg" required="true" type="string" />

    <cfset var local = {} />
    <cfset local.guid = CreateUUID() />
    <cfset local.outPDF = ExpandPath(local.guid & '.pdf') />

    <cfset local.svg = DeserializeJSON(exportToImage(svg=arguments.svg)) />

    <cfif local.svg.error>
        <!-- Conversion error -->
        <cfset FileDelete(#local.svg.file#) />
        <cfreturn '' />
    </cfif>

    <!--- rotate the png --->
    <cfimage
        action="read"
        source="#local.svg.file#"
        name="local.objImage" />

    <cfimage
        action="rotate"
        source="#local.objImage#"
        angle="90"
        name="local.objImage" />

    <cfimage
        action="write"
        source="#local.objImage#"
        destination="#local.svg.file#"
        overwrite="yes" />

    <!--- Add the png to the pdf, write the pdf file, and delete the png --->
    <cfscript>
        img = CreateObject("java", "com.lowagie.text.Image");
        png = img.getInstance(local.svg.file);

        document = CreateObject("java", "com.lowagie.text.Document");
        document.init(png);
        fileIO = CreateObject("java", "java.io.FileOutputStream");
        fileIO.init(local.outPDF);
        writer = CreateObject("java", "com.lowagie.text.pdf.PdfWriter");
        writer.getInstance(document, fileIO);
        document.setMargins(0, 0, 0, 0);
        document.open();
        document.add(png);
        document.close();

        FileDelete(#local.svg.file#); <!--- This is the line where it breaks--->
    </cfscript>

    <cfreturn local.outPDF />

</cffunction>

How can I fix this function? Thanks

Upvotes: 1

Views: 214

Answers (1)

haxtbh
haxtbh

Reputation: 3534

If you production server is CF11 then this is a bug that has been mentioned here, in Bug# 4031026 - http://bugbase.adobe.com/index.cfm?event=bug&id=4031026

The bug has been verified by Adobe and fix will be due, most probably in their next hotfix.

JPEG seems to be the only format that works at the moment without locking issues.

Upvotes: 2

Related Questions