在web应用使用的Ghostscript(PDF缩略图) [英] Using Ghostscript in a Webapplication (PDF Thumbnails)

查看:440
本文介绍了在web应用使用的Ghostscript(PDF缩略图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#和Ghostscript的ghostscriptsharp包装。我想生成缩略图出来的PDF文件。在样品 - code更多信息给出的这里

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.

有进口的形式不同方法的ghostscript-C-DLLgsdll32.dll。

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

我现在用的GhostscriptWrapper在web应用(.NET 2.0)生成缩略图。这个类使用上面导入的方法。

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);
 }

当我通过敲击键F5调试网络应用程序在Visual Studio 2008中,它工作正常(网络服务器的新实例生成)。当我创建一个应用程序WindowsForm它工作了。缩略图获取生成。

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.

当我直接在WebBrowser访问应用程序(HTTP:// localhoast / mywebappliation / ..)这是行不通的。没有缩略图生成。但也有没有的异常。

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.

我把gsdll32.dll在Windows XP中的SYSTEM32文件夹。 Ghostscript的运行时间也被安装。我已在IIS-Webproject(.NET 2.0)完全访问权限。

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).

是否有人知道为什么我无法从我的web应用访问的Ghostscript?是否有任何安全问题,用于访问IIS的服务器?

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?

问候
克劳斯

推荐答案

我现在有一个解决方法。我不与GhostscriptWrapper级访问Ghostscript的。相反,我直接访问服务器上的CMD.EXE。下面的方法需要一个命令(ghostscript的语法)并运行它在CMD.EXE。我用下面的方法这样做的:

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>"));
    }

这篇关于在web应用使用的Ghostscript(PDF缩略图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆