5
votes

I am trying to convert pdf first page to image using Ghostscript.NET it works fine on local IIS but fails on the Azure web app with the following error:

[GhostscriptException: Delegate of an exported function couldn't be created for symbol 'gsapi_revision']
Ghostscript.NET.GhostscriptLibrary.Initialize() +865
Ghostscript.NET.GhostscriptLibrary..ctor(GhostscriptVersionInfo version, Boolean fromMemory) +178
Ghostscript.NET.Interpreter.GhostscriptInterpreter..ctor(GhostscriptVersionInfo version, Boolean fromMemory) +48
Ghostscript.NET.Viewer.GhostscriptViewer.Open(String path, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory) +75
Ghostscript.NET.Viewer.GhostscriptViewer.Open(Stream stream, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory) +59
Ghostscript.NET.Rasterizer.GhostscriptRasterizer.Open(Stream stream, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory) +40
VirtualWindow.Dropzone.Pages.Home.btnUpload_Click(Object sender, EventArgs e) +270
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +116
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +31 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3582

My code is below

protected void btnUpload_Click(object sender, EventArgs e)
{
    if (fileUpload.HasFile)
    {
        string ghostDllPath = HttpContext.Current.Server.MapPath("~/bin/External");
        GhostscriptRasterizer rasterizer = null;
        GhostscriptVersionInfo vesion = null;
        if (Environment.Is64BitProcess)
            vesion = new Ghostscript.NET.GhostscriptVersionInfo(new Version(0, 0, 0), ghostDllPath + @"\gsdll64.dll", string.Empty, Ghostscript.NET.GhostscriptLicense.GPL);
        else
            vesion = new Ghostscript.NET.GhostscriptVersionInfo(new Version(0, 0, 0), ghostDllPath + @"\gsdll32.dll", string.Empty, Ghostscript.NET.GhostscriptLicense.GPL);
        using (rasterizer = new Ghostscript.NET.Rasterizer.GhostscriptRasterizer())
        {
            rasterizer.Open(fileUpload.PostedFile.InputStream, vesion, false);
            if (rasterizer.PageCount > 0)
            {
                  int dpi = 90;
                  System.Drawing.Image img = rasterizer.GetPage(dpi, dpi, 1);
                  using (MemoryStream ms = new MemoryStream())
                  {
                       string file = Guid.NewGuid().ToString() + ".png";
                       img.Save(ms, ImageFormat.Png);
                       Response.ContentType = "image/png";
                       byte[] data = ms.ToArray();
                       Response.OutputStream.Write(data, 0, data.Length);
                       Response.AddHeader("Content-Disposition", "attachment;filename=" + file);
                       Response.Flush();
                   }
            }
            rasterizer.Close();
        }   
    }
}

What I am doing wrong?

1
Is your gsdll64.dll being included in the package? Right click-> properties on the dll, should be BuildAction = None, Copy to output directory = Copy Always.Alex S
Yes it is. Infact my local environment is also 64bit. But both 32bit and 64bit versions are present.adil
And the path as well: If you are publishing from within Visual Studio, check the build output after publish. Search the build output for gsdll64.dll, there will be a section on the files copied and should show ...PackageTmp\bin\External\gsdll64.dllAlex S

1 Answers

3
votes

Ok found the issue. Everything including the paths were correctly setup. My site was hosted on free plan and hence it was configured to be on 32-bit environment. My local environment was 64 bit which was working. So I redownloaded the gsdll32.dll. Updated azure and it started working on azure too.

Problem was with wrong gsdll32.dll.