我使用的是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在.net应用程序(.net 2.0)中生成缩略图。这个类使用上面导入的方法。
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文件是否存在任何安全问题?
问候克劳斯
发布于 2010-03-30 22:24:49
我现在有了一个变通方法。我没有使用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>"));
}发布于 2011-06-21 08:27:34
尝试更改当前目录
string workingDirectory = @"C:\tmp";
Directory.SetCurrentDirectory(workingDirectory);
GhostscriptWrapper.GeneratePageThumb("c:\\sample.pdf", "c:\\sample.jpg", 1, 100, 100);发布于 2010-03-30 22:32:46
您运行网站的身份可能没有c:\的写入权限
https://stackoverflow.com/questions/2506623
复制相似问题