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

时间:2015-12-07 06:14:06

标签: c# asp.net-mvc ghostscript

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

2 个答案:

答案 0 :(得分:1)

试试这个:

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

答案 1 :(得分:1)

我知道这是一篇过时的文章,但想分享一下我最终要花的时间,因为花了一些时间才弄清楚,由于这是我开始着手解决问题的贴子,我想我会提供详细信息,以便像我一样遇到此帖子的其他人将有一个很好的起点。就是说,这就是我要工作的:

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”。