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

Gerben Wierda gerben.wierda at rna.nl
Sun Jan 15 17:58:09 CET 2012


On 15 Jan 2012, at 10:56, Victor Ivrii wrote:

> On Sat, Jan 14, 2012 at 6:53 PM, Gerben Wierda <gerben.wierda at rna.nl> wrote:
>> pdfpages won't do the trick. The reason is that the resulting pages in my
>> document should not have a paper size equivalent to the included PDFs (which
>> have any random size, e.g. may be 2 by 4 inch), but it should be possible to
>> set each page to some sensible size (restricted to A4 portrait and A3
>> landscape in my situation)
> 
> Then majority of advices you got would not work but this was not
> mentioned in the original post.

A guess I was not clear enough in my original post. I did write that the pages should be different size and orientation (and gave A4 and A3 examples) and I wrote the PDF's had a random size, but I never was clear enough that the page sizes in the final result was restricted to sizes which differ from the completely random PDF sizes.

> However the script below means that one should manually select
> pagesize for each included document which may require too much work if
> there are plenty of documents to include.

Yes, but that can only be prevented if I have an algorithm that for each random PDF size decides how to get it on portrait A4 or landscape A3. Now, I decide manually. Doable for the 30 PDFs or so I have to combine and creating an algorithm will be much work.

pdfjam looks like a nice and smart hack, btw.

G

> 
>> 
>> I ended up using ConTeXt:
>> 
>> \setuppapersize[A4,portrait][A4,portrait]
>> \starttext
>> 
>> \page\setuppapersize[A4,portrait][A4,portrait]
>> \setuplayout[backspace=10mm,topspace=10mm,width=277mm,height=190mm,header=5mm,footer=1mm]
>> \rotate[rotation=90]{\externalfigure[foo.pdf][width=\hsize]}
>> 
>> \page\setuppapersize[A3,landscape][A3,landscape]
>> \setuplayout[backspace=10mm,topspace=10mm,width=400mm,height=277mm,header=5mm,footer=1mm]
>> \rotate[rotation=90]{\externalfigure[bar.pdf][width=\vsize]}
>> 
>> \page\setuppapersize[A3,landscape][A3,landscape]
>> \setuplayout[backspace=10mm,topspace=10mm,width=400mm,height=277mm,header=5mm,footer=1mm]
>> \externalfigure[foobar.pdf][height=\vsize]
>> 
>> etc.
>> 
>> \stoptext
>> 
>> On 14 Jan 2012, at 20:43, Jens Nöckel wrote:
>> 
>> 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
>> 
>> 
>> 
>> 
>> ----------- Please Consult the Following Before Posting -----------
>> TeX FAQ: http://www.tex.ac.uk/faq
>> List Reminders and Etiquette: http://email.esm.psu.edu/mac-tex/
>> List Archive: http://tug.org/pipermail/macostex-archives/
>> TeX on Mac OS X Website: http://mactex-wiki.tug.org/
>> List Info: http://email.esm.psu.edu/mailman/listinfo/macosx-tex
>> 
>> 
>> 
>> ----------- Please Consult the Following Before Posting -----------
>> TeX FAQ: http://www.tex.ac.uk/faq
>> List Reminders and Etiquette: http://email.esm.psu.edu/mac-tex/
>> List Archive: http://tug.org/pipermail/macostex-archives/
>> TeX on Mac OS X Website: http://mactex-wiki.tug.org/
>> List Info: http://email.esm.psu.edu/mailman/listinfo/macosx-tex
>> 
>> 
> 
> 
> 
> -- 
> ========================
> Victor Ivrii, Professor, Department of Mathematics, University of Toronto
> http://www.math.toronto.edu/ivrii
> ----------- Please Consult the Following Before Posting -----------
> TeX FAQ: http://www.tex.ac.uk/faq
> List Reminders and Etiquette: http://email.esm.psu.edu/mac-tex/
> List Archive: http://tug.org/pipermail/macostex-archives/
> TeX on Mac OS X Website: http://mactex-wiki.tug.org/
> List Info: http://email.esm.psu.edu/mailman/listinfo/macosx-tex
> 




More information about the macostex-archives mailing list