You are not logged in.
Pages: 1
Topic closed
Does anybody know of a way (preferably command line) to stitch two pdfs side by side?
The closest I can get is
pdftk in1.pdf multibackground in2.pdf output out.pdfbut that puts them on top of each other. That could work if I could insert room for them by having white space on opposite side of each pdf, and then merge them.
Last edited by penguin (2014-12-04 12:53:23)
Offline
Do you want them stretch (compressed) to fit the same size in the end, or do you want the page width to double?
edit: I don't actually know any tool to do this off the top of my head, but clarifying the above might help pinpoint exactly what is needed.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
So this is impossible to seach the Internet for, since either you find the "usual" way people want to merge files, or you find people wanting to add stamps or signatures or "do not distribute" text on top of a pdf.
However, I think I have found the building blocks I need. With the command in my first post, and
convert -extent <wd> x <ht> option of imagemagick, I think I can get there.
I'll post again my complete solution, since this needs to be put in text.
http://www.imagemagick.org/script/comma … php#extent
Offline
So I think I solved it fairly OK. I post the script to do it here, although it might need some tweaking since it assumes the following:
1. there are two files, both eps that should be stitched.
2. file1 should be to the left of file2
3. file1 has the width of both (original)file1+file2. (In gnuplot I doubled the width of file1 manually, and made it a multiplot with 2 columns, the second column being empty, where I will place file2)
The script works for me, but I'm going to do some more non-general stuff to it, so I post it here while it still might be of use to others.
#!/bin/bash
FILE1_PATH[0]="fig_file1.eps"
FILE2_PATH[0]="fig_file2.eps"
for i in `seq 0 1`;
do
INPUT_FILE1=${FILE1_PATH[$i]}
INPUT_FILE2=${FILE2_PATH[$i]}
# Read in dimensions (bounding box) of fig1
WIDTH1=$(awk '$1 ~ /%BoundingBox:/{print $4-$2}' $INPUT_FILE1)
HEIGHT1=$(awk '$1 ~ /%BoundingBox:/{print $5-$3}' $INPUT_FILE1)
# Read in dimensions of (bounding box) fig2
WIDTH2=$(awk '$1 ~ /%BoundingBox:/{print $4-$2}' $INPUT_FILE2)
HEIGHT2=$(awk '$1 ~ /%BoundingBox:/{print $5-$3}' $INPUT_FILE2)
BOUNDINGBOX_CMD=$(awk '$1 ~ /%BoundingBox:/{print $1}' $INPUT_FILE2)
# Set bounding box of fig2 to same as fig1, making fig2 twice as wide (with white "canvas")
sed -i 's/.*%BoundingBox:.*/'"$BOUNDINGBOX_CMD 0 0 $WIDTH1 $HEIGHT1"'/g' $INPUT_FILE2
# Scale fig2 accordingly, to make the height of fig2 same as fig1
# (thus when stitching them side by side, they have the same height)
SCALE=$(echo "scale=20; $HEIGHT1/$HEIGHT2" | bc)
sed -i '/%%EndComments/a '"$SCALE $SCALE scale"'' $INPUT_FILE2
# Translate fig2 to right place on new big canvas
TRANSLATE_X=$(echo "scale=20; $WIDTH1/2.0" | bc)
sed -i '/%%EndComments/a '"$TRANSLATE_X 0 translate"'' $INPUT_FILE2
# convert eps to pdf, since that is what pdftk likes
epstopdf $INPUT_FILE1
epstopdf $INPUT_FILE2
# MERGE that sucker!
pdftk ${INPUT_FILE1%.*}".pdf" background ${INPUT_FILE2%.*}".pdf" output out"$i".pdf
doneLast edited by penguin (2014-12-04 12:52:57)
Offline
(( an old post, but ranked highly in search for "arch pdf combine side-by-side" ))
Contemporary solution using cpdf (AUR)::
> cpdf -merge -collate A.pdf B.pdf AND -impose-xy "2 1" -o out.pdfMerges two documents together, such that each page from A.pdf is placed side-by-side with each page from B.pdf; the output document has the same page-count as the original pdfs.
Offline
Mod note:
Please refrain from necro-bumping: https://wiki.archlinux.org/title/Genera … bumping%22
Closing this old thread.
Inofficial first vice president of the Rust Evangelism Strike Force
Offline
Pages: 1
Topic closed