pdfmerge

[email protected] (Mårten Svantesson)
Newsgroups gmane.comp.printing.ghostscript.patches
Message-ID <[email protected]>
Hi!

I don't know if this is the right place to contribute scripts that
would be suitable to distribute with ghostscript, but here goes
anyway:

Pdfmerge is a script modeled to be a (kind of, superior) replacement
to psmerge (from the psutils-package). Because of the nature of
ghostscript it can of course do PS to PDF conversion as well. As an
afterthought I also added psselect style page selection (making the
name of the script even more inaccurate). Currently page selection
only works for PDF, but since ghostcript might support it for PS
documents in the future I don't test for that. (Should I?)

The options to ghostscript were mostly taken from ps2pdfwr; I don't
understand them all, but since ps2pdfwr tend to work I let them be.

The license statement is taken from fixmswrd.pl, so it should be fine.

-- 
                - Mårten
 
mail: [email protected] *** ICQ: 4356928 *** mobile: +46 (0)707390385

_______________________________________________
gs-code-review mailing list
[email protected]
http://www.ghostscript.com/mailman/listinfo/gs-code-review
(unnamed) (text/plain, 2.9 KB)
#!/usr/local/bin/perl

# pdfmerge: Merge PDF files, convert PostScript to PDF and selecting pages from
# PDF files without specifying CompatibilityLevel.
#
# (C) 2003 Mårten Svantesson <[email protected]>
#
#   This software is provided 'as-is', without any express or implied
#   warranty.  In no event will the authors be held liable for any damages
#   arising from the use of this software.
#
#   Permission is granted to anyone to use this software for any purpose,
#   including commercial applications, and to alter it and redistribute it
#   freely, subject to the following restrictions:
#
#   1. The origin of this software must not be misrepresented; you must not
#      claim that you wrote the original software. If you use this software
#      in a product, an acknowledgment in the product documentation would be
#      appreciated but is not required.
#   2. Altered source versions must be plainly marked as such, and must not be
#      misrepresented as being the original software.
#   3. This notice may not be removed or altered from any source distribution.
#


$gs='gs';

@OPTIONS="-dSAFER";

$outfile='/dev/stdout';
$0 =~ m=.*/(.*)=;
$prog = $1;

while ($ARGV[0]) {
   $_ = shift;
   if (/^-o(.*)/) {
     if ($1) {
       $outfile=$1;
     } else {
       $outfile=shift;
       if (! $outfile) {
	 $outfile="output.pdf";
	 print(STDERR "No output file specified; writing to output.pdf.\n");
       }
     }
   } elsif (/^-/) {
     push(@OPTIONS,$_);
   } else {
     if ((! -f) && /(.*):([0-9,-]+)$/) {
       $infile=$1;
       $ranges=$2;
       @ranges=split /,/, $ranges;
       foreach (@ranges) {
	 @pages=split /-/;
	 if (/^-/) {
	   push(@infiles,'-uFirstPage');
	 } else {
	   push(@infiles,"-dFirstPage=$pages[0]");
	 }
	 if (/-$/) {
	   push(@infiles,'-uLastPage');
	 } else {
	   push(@infiles,"-dLastPage=$pages[-1]");
	 }
	 push(@infiles,$infile);
       }
       push(@infiles,'-uFirstPage');
       push(@infiles,'-uLastPage');
     } else {
       push(@infiles,$_);
     }
   }
}

if (@infiles==0) {
  print STDERR "Usage: $prog [gs options] [-o outfile.pdf] file.[e]ps | file.pdf[:pages] ...

     Pages is a comma separated list of page ranges, each of which may
     be a page number, or a page range of the form first-last. If
     first is omitted, the first page is assumed, and if last is
     omitted, the last page is assumed. Note that you only can specify
     pages for PDF files.

     Gs options are sent along to ghostscript. Options affecting the
     PDF file can be found on

        http://www.ghostscript.com/doc/AFPL/8.00/Ps2pdf.htm

     The PDF is by default optimized for the screen.

     Example:

        $prog -o out.pdf afile.pdf:-2 another.pdf:4-6,9 afile.pdf
";
  exit 1;
}

# We have to include the options twice because -I only takes effect if it
# appears before other options.
exec $gs, @OPTIONS, '-q', '-dPDFSETTINGS=/screen', '-dNOPAUSE', '-dBATCH', '-sDEVICE=pdfwrite', "-sOutputFile=$outfile", @OPTIONS, '-c', '.setpdfwrite', '-f', @infiles;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.