2

我如何运行以下命令以使用 ghost 脚本在 Web 应用程序中将 pdf 转换为 jpeg。

我正在使用以下代码:

 protected void Page_Load(object sender, EventArgs e)
    {
        string file = @"C:\pdf\p_o6GEE+.pdf";
        string image = @"C:\image";

        try
        {
            PdfToJpg(file, image);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    private void PdfToJpg(string inputPDFFile, string outputImagesPath)
    {
        string ghostScriptPath = @"C:\Program Files\gs\gs9.09\bin\gswin32.exe";
        String ars = "-dNOPAUSE -sDEVICE=jpeg -r300 -o" + outputImagesPath + "%d.jpg -sPAPERSIZE=a4 " + inputPDFFile;
        Process proc = new Process();
        proc.StartInfo.FileName = ghostScriptPath;
        proc.StartInfo.Arguments = ars;
        proc.StartInfo.CreateNoWindow = true;
        proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        proc.Start();
        proc.WaitForExit();

    }

当我尝试运行此代码时,我的应用程序进入等待状态并且图像文件夹仍然为空。

4

2 回答 2

3

我建议您使用Ghostscript.NET(Ghostscript 库的包装器)而不是直接调用 .exe。

在那里你可以找到GhostscriptJpegDevice类,它将完全满足你的需要。看看GhostscriptDevice 使用示例

您还可以查看GhostscriptProcessor 示例,它也可以满足您的需要。

于 2013-10-15T08:53:02.323 回答
0

你必须使用:-sDEVICE=tiffg4 -dBATCH -dNOPAUSE -r600x600 -dNOSAFER -q -sOutputFile=

事实上 -dBATCH -dNOPAUSE ,会做你所期望的工作,享受它。

于 2014-04-01T07:47:32.067 回答