3

我正在为 c# 和 ghostscript 使用 ghostscriptsharp 包装器。我想从 pdf 文件中生成缩略图。

从 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

我正在使用 GhostscriptWrapper 在 web 应用程序 (.net 2.0) 中生成缩略图。此类使用上面导入的方法。

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

当我通过按“F5”键在 Visual Studio 2008 中调试 Web 应用程序时,它工作正常(生成了一个新的网络服务器实例)。当我创建一个 WindowsForm 应用程序时,它也可以工作。生成缩略图。

当我直接使用网络浏览器访问应用程序时(http://localhoast/mywebappliation/..)它不起作用。不生成缩略图。但是也没有抛出异常。

我将 gsdll32.dll 放在 windows xp 的 system32 文件夹中。Ghostscript 运行时也已安装。我已授予 IIS-Webproject (.Net 2.0) 的完全访问权限。

有人知道为什么我不能从我的网络应用程序访问 Ghostscript 吗?访问 IIS 服务器上的 dll 文件是否存在任何安全问题?

问候克劳斯

4

3 回答 3

2

尝试更改当前目录

string workingDirectory = @"C:\tmp";
Directory.SetCurrentDirectory(workingDirectory);
GhostscriptWrapper.GeneratePageThumb("c:\\sample.pdf", "c:\\sample.jpg", 1, 100, 100);
于 2011-06-21T00:27:33.767 回答
1

我现在有一个解决方法。我没有使用 GhostscriptWrapper-Class 访问 Ghostscript。相反,我直接访问服务器上的 cmd.exe。以下方法采用命令(ghostscript 语法)并在 cmd.exe 中运行它。我使用以下方法来执行此操作:

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>"));
    }
于 2010-03-30T14:24:49.340 回答
0

您运行网站的身份可能没有 c:\ 的写入权限

于 2010-03-30T14:32:46.293 回答