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

Webアプリケーション(.net 2.0)でサムネイルを生成するためにGhostscriptWrapperを使用しています。このクラスは、上記でインポートされたメソッドを使用します。

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

Visual Studio 2008でキー「F5」を押してWebアプリケーションをデバッグすると、正常に機能します(Webサーバーの新しいインスタンスが生成されます)。WindowsFormアプリケーションを作成すると、それも機能します。サムネイルが生成されます。

Webブラウザ(http:// localhoast / mywebappliation / ..)を使用してアプリケーションに直接アクセスすると、機能しません。サムネイルは生成されません。ただし、例外はスローされません。

gsdll32.dllをWindowsXPのsystem32フォルダーに配置しました。Ghostscriptランタイムもインストールされています。IIS-Webproject(.Net 2.0)でフルアクセスを許可しました。

Webアプリケーションから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

Web サイトを実行している ID に、c:\ に対する書き込み権限がない可能性があります。

于 2010-03-30T14:32:46.293 に答える