我需要一种在Perl脚本上执行gswin32.exe(Ghostscript)的方法,就像在C#中轻松执行一样,以便将PDF文件转换为JPG文件并将其发送到某处。我已经使用Google搜索了足够的东西,我发现了一些Perl示例,但是使用ImageMagick。因为我不是决定使用哪种技术的人,在工作中,在这台服务器上,我需要使用GhostScript和句点。
以下是我在C#上的表现:
public static void PdfToJpg(string ghostScriptPath,string input, string output)
{
String ars = "-dNOPAUSE -sDEVICE=jpeg -r300 -o" + output + "-%d.jpg " + input;
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();
}
static void Main(string[] args)
{
string ghostScriptPath = @"D:\Program Files\gs\gs9.01\bin\gswin32.exe";
string inputFileName = @"C:\test.pdf";
string outputFileName = @"E:\New\test";
PdfToJpg(ghostScriptPath, inputFileName, outputFileName);
}
很好,现在,有人可以为我写一个Perl示例,或者至少可以让我走向正确的方向吗?拜托,谢谢!
答案 0 :(得分:0)
#!/usr/bin/perl
use strict;
use warnings;
my $ghostScriptPath = 'D:\Program Files\gs\gs9.01\bin\gswin32.exe';
my $inputFileName = 'C:\test.pdf';
my $outputFileName = 'E:\New\test';
my $ars = "-dNOPAUSE -sDEVICE=jpeg -r300 -o$outputFileName-%d.jpg $inputFileName";
system( $ghostScriptPath, $ars );