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

how to use ghostPCL with c# to convert pcl files to pdf

我必须在我的 mvc4 项目中将 pcl 文件转换为 pdf。我找到了可以完成这项工作的 ghostPCL exe。但我找不到任何参考如何在我的 mvc 项目中使用它。请帮我解决这个问题。

试试这个:

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 的路径。

我知道这是一个旧的 post 但我想分享我终于开始工作的东西,因为我花了一段时间才弄明白,因为这是 posting 让我开始了解决问题的道路,我想我会在这里提供详细信息,以便像我一样遇到此 posting 的其他人会有一个很好的起点。也就是说,这就是我要做的工作:

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