Linux上的GhostScript附带一个名为psmerge
的shell脚本(安装在/usr/bin
目录中)。经过一些简单的尝试,似乎这个程序考虑了资源定义。它确实依赖于您的PostScript程序严格遵守Adobe DSC的事实。此处再次重申合法许可下的合并脚本内容:
© Angus J. C. Duggan 1991–1995
eval 'exec perl -S $0 "$@"'
if $running_under_some_shell;
use strict;
$^W = 1;
my $prog = ($0 =~ m,([^/\\]*)$,) ? $1 : $0;
my $outfile = undef;
usage() unless @ARGV;
while ($ARGV[0] =~ /^-/) {
$_ = shift;
if (/^-o(.+)/) {
$outfile = $1;
} elsif (/^-t(horough)?$/) {
} else {
usage();
}
}
my $gs = find_gs();
if (defined $gs)
{
$outfile = '/dev/stdout' unless defined $outfile;
exec +(qw(gs -q -dNOPAUSE -dBATCH -sDEVICE=pswrite),
"-sOutputFile=$outfile", '-f', @ARGV);
die "$prog: exec /usr/bin/gs failed\n";
}
else
{
warn +("$prog: /usr/bin/gs not found; falling back to old," .
" less functional behavior\n");
}
if (defined $outfile)
{
if (!close(STDOUT) || !open(STDOUT, ">$outfile")) {
print STDERR "$prog: can't open $1 for output\n";
exit 1;
}
}
my $page = 0;
my $first = 1;
my $nesting = 0;
my @header = ();
my $header = 1;
my @trailer = ();
my $trailer = 0;
my @pages = ();
my @body = ();
my @resources = ();
my $inresource = 0;
while (<>) {
if (/^%%BeginFont:/ || /^%%BeginResource:/ || /^%%BeginProcSet:/) {
$inresource = 1;
push(@resources, $_);
} elsif ($inresource) {
push(@resources, $_);
$inresource = 0 if /^%%EndFont/ || /^%%EndResource/ || /^%%EndProcSet/;
} elsif (/^%%Page:/ && $nesting == 0) {
$header = $trailer = 0;
push(@pages, join("", @body)) if @body;
$page++;
@body = ("%%Page: ($page) $page\n");
} elsif (/^%%Trailer/ && $nesting == 0) {
push(@trailer, $_);
push(@pages, join("", @body)) if @body;
@body = ();
$trailer = 1;
$header = 0;
} elsif ($header) {
push(@trailer, $_);
push(@pages, join("", @body)) if @body;
@body = ();
$trailer = 1;
$header = 0;
} elsif ($trailer) {
if (/^%!/ || /%%EOF/) {
$trailer = $first = 0;
} elsif ($first) {
push(@trailer, $_);
}
} elsif (/^%%BeginDocument/ || /^%%BeginBinary/ || /^%%BeginFile/) {
push(@body, $_);
$nesting++;
} elsif (/^%%EndDocument/ || /^%%EndBinary/ || /^%%EndFile/) {
push(@body, $_);
$nesting--;
}
}
print @trailer;
sub find_gs
{
my $path = $ENV{'PATH'} || "";
my @path = split(':', $path);
foreach my $dir (@path)
{
return "$dir/gs" if -x "$dir/gs";
}
undef;
}
sub usage
{
print STDERR "Usage: $prog [-oout] file...\n";
exit 1;
}
pswrite
是默认情况下可以写出PostScript Level 1数据的PostScript设备。而PS L1不知道Adobe后来添加到语言中的一些高级操作符,这些操作符在PS L2和PS L3中。因此会产生更大的输出大小(例如通过像素化某些字体类型)。您可以尝试在命令中添加-dLanguageLevel=3
。(但是,目前Ghostscript的level 3生成与其level 2相同的输出...) - Kurt Pfeifleps2write
输出设备在字体不可用的情况下也会将字体转换为位图字体(例如,如果嵌入由其许可证禁止)。我现在没有太多时间,但今晚稍后我可能可以设计出完整的命令行,并提供有用的所有选项,以尽量减小 PS 输出文件大小而不影响打印质量。 - Kurt Pfeifle