如何在Perl上使用Ghostscript将PDF转换为JPG,就像我在c#上做的那样



我需要一种在Perl脚本上执行gswin32.exe (Ghostscript)的方法,因为我很容易在c#中执行,以便将PDF文件转换为JPG文件并将其发送到某个地方。我已经搜索了足够多,我找到了一些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 Filesgsgs9.01bingswin32.exe";
string inputFileName = @"C:test.pdf";
string outputFileName = @"E:Newtest";
PdfToJpg(ghostScriptPath, inputFileName, outputFileName);
}

好吧,现在,有人可以为我写一个Perl的例子,或者至少,把我带到正确的方向?请,谢谢!

#!/usr/bin/perl
use strict;
use warnings;
my $ghostScriptPath = 'D:Program Filesgsgs9.01bingswin32.exe';
my $inputFileName = 'C:test.pdf';
my $outputFileName = 'E:Newtest';
my $ars = "-dNOPAUSE -sDEVICE=jpeg -r300 -o$outputFileName-%d.jpg $inputFileName";
system( $ghostScriptPath, $ars );

最新更新