首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在PDF应用程序中使用Ghostscript (PDF缩略图)

在PDF应用程序中使用Ghostscript (PDF缩略图)
EN

Stack Overflow用户
提问于 2010-03-24 17:50:01
回答 3查看 6.2K关注 0票数 3

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

从ghostscript-c-dll "gsdll32.dll“导入了不同的方法。

代码语言:javascript
复制
 [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在.net应用程序(.net 2.0)中生成缩略图。这个类使用上面导入的方法。

代码语言:javascript
复制
 protected void Page_Load(object sender, EventArgs e){
      GhostscriptWrapper.GeneratePageThumb("c:\\sample.pdf", "c:\\sample.jpg", 1, 100, 100);
 }

当我在Visual Studio2008中敲击"F5“键来调试Web应用程序时,它工作得很好(生成了一个新的webserver实例)。当我创建一个WindowsForm应用程序时,它也可以工作。生成缩略图。

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

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

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

问候克劳斯

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-03-30 22:24:49

我现在有了一个变通方法。我没有使用GhostscriptWrapper-Class访问Ghostscript。相反,我直接访问服务器上的cmd.exe。下面的方法接受一个命令(ghostscript语法)并在cmd.exe中运行它。为此,我使用了以下方法:

代码语言:javascript
复制
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>"));
    }
票数 1
EN

Stack Overflow用户

发布于 2011-06-21 08:27:34

尝试更改当前目录

代码语言:javascript
复制
string workingDirectory = @"C:\tmp";
Directory.SetCurrentDirectory(workingDirectory);
GhostscriptWrapper.GeneratePageThumb("c:\\sample.pdf", "c:\\sample.jpg", 1, 100, 100);
票数 2
EN

Stack Overflow用户

发布于 2010-03-30 22:32:46

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2506623

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档