Linux上的GhostScript附帶一個名爲psmerge
(安裝在/usr/bin
目錄中)的shell腳本。經過一些簡單的試驗後,看起來這個程序考慮了資源定義。它確實依賴於您的PostScript程序嚴格符合Adobe DSC的事實。合併腳本的內容轉載此處考慮許可證:
©Angus J.C。杜根1991 – 1995年
#!/usr/bin/perl
eval 'exec perl -S $0 "[email protected]"'
if $running_under_some_shell;
# psmerge: merge PostScript files produced by same application and setup
# usage: psmerge [-oout.ps] file1.ps file2.ps ...
#
# Copyright (C) Angus J. C. Duggan 1991-1995
# See file LICENSE for details.
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)?$/) {
# This doesn't do anything, but we leave it for backward compatibility.
} else {
usage();
}
}
my $gs = find_gs();
if (defined $gs)
{
# Just invoke 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;
}
嗨皮皮塔斯。感謝提示(我給你1分),但是我不能使用pdf方法,因爲它需要我將postscript轉換爲pdf,然後在將合併的pdf轉換爲postscript之前將pdf合併回postscript。我以前走過這條路,速度非常慢(過程沒有完成,6小時後我停下了)。注意:我有很大的postscript文件。你知道純後記appraoch? – Syd 2010-08-10 00:35:09
這裏有很多「轉換」:*需要我將postscript轉換爲pdf,然後再將pdf合併到postscript,然後再將合併的pdf轉換爲postscript *? - 這也取決於您的打印服務提供商。有時候,這些傢伙** DO **更喜歡PDF(因爲它被壓縮,所以PDF更小),有時他們甚至有打印機使用PDF(不是PostScript)。 - 如果你的程序沒有完成,你不知道開關調整Ghostscript的性能和更高的RAM容差? – 2010-08-10 00:50:39
@papitas ..我以前的評論錯別字。 pdf的方法是 1)將每個後記轉換爲pdf 2)將pdf合併成一個pdf 3)將合併的pdf轉換爲postscript。 – Syd 2010-08-10 00:58:19