【发布时间】:2014-10-09 23:22:06
【问题描述】:
GhostScript v9.10 64位版
我想获取 jpg 的列表并将它们转换为单个 pdf 文件,其中每个图像都有自己的页面。
我尝试按照这里使用的方法: Using Ghostscript to convert JPEG to PDF 但我遇到了错误。
这是我的命令:
C:\Temp>gswin64c -sDEVICE=pdfwrite -o cafb0173-f4be-47a8-a39e-f479ca0a4d09.pdf viewjpeg.ps -c 5c520934-461a-44f3-9f00-9fdc9fe666c1.jpg
这是我得到的:
GPL Ghostscript 9.10 (2013-08-30)
Copyright (C) 2013 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Error: /undefined in 5c520934-461a-44f3-9f00-9fdc9fe666c1.jpg
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_pus
h --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push .runexec2 --
nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval--
Dictionary stack:
--dict:1179/1684(ro)(G)-- --dict:0/20(G)-- --dict:80/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 9.10: Unrecoverable error, exit code 1
我尝试使用 viewjpeg.ps 的完整路径,并尝试将 viewJPEG showpage 放在末尾,但也没有用。
但是,当我运行这段 c# 代码时:
try
{
var guid = System.Guid.NewGuid().ToString();
Process p = new Process();
p.StartInfo.WorkingDirectory = @"C:\Temp";
p.StartInfo.FileName = Program.ghostScriptLocation;
p.StartInfo.Arguments = " -sDEVICE=pdfwrite -o " + guid + ".pdf " + "\""+Program.viewJPEGLoc+"\"" +" -c " + String.Join(" ", pictures.ToArray());
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string outp = p.StandardOutput.ReadToEnd();
p.WaitForExit();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
我收到一个空白的 pdf 文件以及一个错误提示“不可恢复的错误,退出代码 1”
【问题讨论】:
标签: c# pdf cmd ghostscript