views:

462

answers:

2

Hello,

i am using the ghostscriptsharp wrapper for c# and ghostscript. I want to generate thumbnails out of pdf-files. Further Information on the sample-code are given here.

There are different Methods imported form the ghostscript-c-dll "gsdll32.dll".

 [DllImport("gsdll32.dll", EntryPoint = "gsapi_new_instance")]
 private static extern int CreateAPIInstance(out IntPtr pinstance, 
                                        IntPtr caller_handle);

 [DllImport("gsdll32.dll", EntryPoint = "gsapi_init_with_args")]
 private static extern int InitAPI(IntPtr instance, int argc, IntPtr argv);

 //...and so on

I am using the GhostscriptWrapper for generating the thumbnails in a webapplication (.net 2.0). This class uses the methods imported above.

 protected void Page_Load(object sender, EventArgs e){
      GhostscriptWrapper.GeneratePageThumb("c:\\sample.pdf", "c:\\sample.jpg", 1, 100, 100);
 }

When i debug the Web-Application in Visual Studio 2008 by hitting key "F5" it works fine (a new instance of webserver is generated). When i create a WindowsForm Application it works too. The thumbnails get generated.

When i access the application with the webbrowser directly (http://localhoast/mywebappliation/..) it doesn't work. No thumbnails are generated. But there is also no exception thrown.

I placed the gsdll32.dll in the system32-folder of windows xp. The Ghostscript Runtime is installed too. I have given full access in the IIS-Webproject (.Net 2.0).

Does anybody know why i can't access Ghostscript from my webapplication? Are there any security-issues for accessing dll-files on the IIS-Server?

Greetings Klaus

A: 

I now have a workaround. I am not accessing Ghostscript with the GhostscriptWrapper-Class. Instead i access the cmd.exe on the server directly. The following method takes a command (ghostscript syntax) and runs it in cmd.exe. I used the following method for doing this:

public static string runCommand(string workingDirectory, string command)
    { 
        // Create the ProcessInfo object
        System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");
        psi.UseShellExecute = false;
        psi.RedirectStandardOutput = true;
        psi.RedirectStandardInput = true;
        psi.RedirectStandardError = true;
        psi.WorkingDirectory = workingDirectory;

        // Start the process
        System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);

        // Attach the output for reading
        System.IO.StreamReader sOut = proc.StandardOutput;

        // Attach the in for writing
        System.IO.StreamWriter sIn = proc.StandardInput;

        sIn.WriteLine(command);

        // strm.Close();

        // Exit CMD.EXE
        string stEchoFmt = "# {0} run successfully. Exiting";

       // sIn.WriteLine(String.Format(stEchoFmt, targetBat));
        sIn.WriteLine("EXIT");

        // Close the process
        proc.Close();

        // Read the sOut to a string.
        string results = sOut.ReadToEnd().Trim();

        // Close the io Streams;
        sIn.Close();
        sOut.Close();

        // Write out the results.
        string fmtStdOut = "<font face=courier size=0>{0}</font>";
        return String.Format(fmtStdOut, results.Replace(System.Environment.NewLine, "<br>"));
    }
cpt.oneeye
A: 

Its possible that the identity you are running the web site under does not have write permissions for c:\

Adrian
i have given all possible users (iis user, aspnetuser, etc..) write permissions for c:\, gsdll32.dll, gs.exe,... but it didn't work.
cpt.oneeye
You'll need to put the gsdll32.dll into the webs bin folder.
Adrian