如何使用ghostPCL和c#将pcl文件转换为pdf

本文关键字:文件 转换 pdf pcl 何使用 ghostPCL | 更新日期: 2023-09-27 18:25:59

我必须在mvc4项目中将pcl文件转换为pdf。我找到了ghostPCL.exe,它做这项工作。但我找不到任何关于如何在我的mvc项目中使用它的参考资料。请帮我处理这件事。

如何使用ghostPCL和c#将pcl文件转换为pdf

试试这个:

public void Convert(String pclFile, String pdfFile)
{
    var command = String.Format(
        "{0} -q -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile={1} -f{2}",
        GhostscriptPath, pdfFile, pclFile);
    var process = System.Diagnostics.Process.Start(command);
}

其中GhostscriptPath是PC上Ghostscript的路径。

我知道这是一篇旧帖子,但我想分享我最终做了什么,因为我花了一段时间才弄清楚,因为这是我开始弄清楚事情的帖子,我想我会在这里提供详细信息,这样其他像我一样看到这篇帖子的人就会有一个很好的起点。也就是说,以下是我要做的工作:

public static void Convert(string GhostscriptPath, String pclFile, String pdfFile)

var args = $"-dNOPAUSE -sOutputFile='"{pdfFile}'" -sDEVICE=pdfwrite '"{pclFile}'"";

System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = GhostscriptPath;
process.StartInfo.Arguments = args;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
process.Start();
process.WaitForExit();

}

GhostscriptPath字符串值是GhostPCL的完整路径,可以从https://www.ghostscript.com/download/gpcldnld.html.由于我将9.50 win32版本的GhostPCL下载到了我的C驱动器中,我作为GhostscriptPath传入的路径是"C:''GhostPCL-9.50-win32''GhostPCL-9.50-win32/gpcl6win32.exe"。