[OS X TeX] Can TeX help out here? Merging PDF with various page sizes and keeping it vector.

Jens Nöckel noeckel at uoregon.edu
Sat Jan 14 20:43:26 CET 2012


On Jan 14, 2012, at 7:30 AM, Juan Luis Varona wrote:

> Try the package pdfpages to joint pdf file (with pdflatex):
> 
> \documentclass[11pt]{article}
> 
> \usepackage{pdfpages}
> 
> \title{Brief Article}
> \author{The Author}
> 
> \begin{document}
> 
> \maketitle
> 
> Hello
> 
> %\newpage
> 
> \includepdf[fitpaper=true]{a-pdf-with-different-size.pdf}
> 
> %\newpage
> 
> Hello
> 
> \end{document}  
> 
> ---
> 
> Yours,
> 
> Juan Luis
> 

Hi,
as an extension of this, the script below should do the trick. If there are problems with line breaks in the pasted code, you may want to copy it from my web page instead:
http://pages.uoregon.edu/noeckel/computernotes/latex/n-up.html
After saving this in a file, e.g., "~/bin/pdfnup2" and making it executable by typing "chmod 700 ~/bin/pdfnup2" you can get the concatenation of files with their dimensions intact by typing "~/bin/pdfnup -o outputfile.pdf file1.pdf file2.pdf" 
where outputfile.pdf is the desired output name, and file1 etc are an arbitrary number of input files with arbitrary dimensions. 

Hope this helps,
Jens



#!/bin/tcsh
#
#   Save this file under any name (e.g., pdfnup2) and make it executable in your PATH.
#   Usage instructions are displayed when invoking the command without arguments.
#
#   Created Oct 11, 2007 by J.U.Noeckel (originally called pdfbgcolor, only used to change background color)
#   Modified March 30, 2009 by J.U.Noeckel (added n-up functionality because no such tool seemed to exist for Leopard)

alias printHelp 'printf "Usage: "`basename $0`" [-o outputfile] [-c HTML-color] [-n ROWSxCOLUMNS] [-d DELTA_XxDELTA_Y] filename(s)\n\n";\\
    printf  "outputfile:\n"; \\
    printf  "name of the output PDF file (default: converted.pdf)\n"; \\
    printf  "HTML-color:\n"; \\
    printf  "hexadecimal RGB number in capitals, RRGGBB\n"; \\
    printf  "The background of the file filename is changed to color HTML-color\n"; \\
    printf  "Default color: white\n\n";\\
    printf  "ROWSxCOLUMNS:\n"; \\
    printf  "two integers separated by x specifying the number of rows and columns to\nprint per physical page (e.g., 2x2)\n\n"; \\
    printf  "DELTA_XxDELTA_Y:\n"; \\
    printf  "two floats separated by x sepcifying the offset in points between rows and\ncolumns (may be negative)\n\n"; \\
    printf  "Output PDF is written to filename-converted.pdf\n"'

alias cleanup 'rm -Rf $TMPNAME*'

if ("$#" == 0) then
   echo "**** Input file name required"
   printHelp
   exit 1
endif

set TMPNAME = `mktemp -dt pdfnup`
echo $TMPNAME
# Default background color is white:
set COLOR = "FFFFFF"
set NUP = ","
set DELTA = ""
set OUTFILE = ~/Desktop/converted.pdf 

# Define the permissible command-line options:
set ARGS = `getopt hd:n:c:o: $*`
# Arguments preceding the special "--" are command-line options:
while ("$ARGS[1]" != "--") 

  switch ("$ARGS[1]")
#    Check if a color option is given:
     case "-c": 
             set COLOR = $ARGS[2]
             shift ARGS
             breaksw
#    Output file name:
     case "-o": 
             set OUTFILE = "$ARGS[2]"
             shift ARGS
             breaksw
#    Check if an n-up option is given:
     case "-n": 
             set NUP = ",nup="$ARGS[2]
             shift ARGS
             breaksw
#    Check if an offset option is given:
     case "-d": 
             set DELTA = ",delta="$ARGS[2]:s/x/ /
             shift ARGS
             breaksw
     default:
             printHelp
             exit 0
             breaksw
  endsw
  shift ARGS
end
if (-f $OUTFILE) then
    echo -n "Output file "$OUTFILE" exists. Overwrite ? [yes/no]"
    set overwrite = "$<"
    if ( $overwrite != "yes" ) then
        echo "NOT OVERWRITING"
        cleanup
        exit 1
    endif
endif
echo '\documentclass{minimal}\usepackage{xcolor}\pagecolor[HTML]{'$COLOR'}\usepackage{pdfpages}\begin{document}' > $TMPNAME/converted.tex
shift ARGS
set FILECOUNTER = 0
foreach i (`echo "$ARGS"`)
    if (-f $i) then
        @ FILECOUNTER++
        cp "$i" "$TMPNAME"/$FILECOUNTER.pdf
    else
        echo  "**** Invalid filename ""$i"
        printHelp
        cleanup
        exit 1
    endif
    echo '\includepdf[fitpaper,pages=-'$NUP$DELTA',frame=false]{'$FILECOUNTER.pdf'}' >> $TMPNAME/converted.tex
end
echo '\end{document}' >> $TMPNAME/converted.tex
pushd $TMPNAME
pdflatex -interaction nonstopmode converted.tex
# Return to original working directory:
popd
if ( -f $TMPNAME/converted.pdf) then
    mv $TMPNAME/converted.pdf $OUTFILE 
    echo "Output written to "$OUTFILE
else
    echo "**** Couldn't convert"
endif
cleanup



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/macostex-archives/attachments/20120114/4dacd336/attachment.html>


More information about the macostex-archives mailing list