Skip to content

Instantly share code, notes, and snippets.

@yuwash
Created February 1, 2018 18:40
Show Gist options
  • Select an option

  • Save yuwash/51d602805b37d3f15f87d30f2ca2e0e6 to your computer and use it in GitHub Desktop.

Select an option

Save yuwash/51d602805b37d3f15f87d30f2ca2e0e6 to your computer and use it in GitHub Desktop.
Combine top halves of two PDF into one page, rotating the second upside-down
#! /usr/bin/env bash
[[ "$#" == 2 ]] || {
echo Please specify the two input PDF files.
exit 1
}
PDF1="$1"
PDF2="$2"
PDFALL="all-$(date -I).pdf"
OUTPUTPDF="topcombine-${PDF1%.pdf}-$PDF2"
pdftk A="$PDF1" B="$PDF2" cat A B output "$PDFALL" \
&& pdftops "$PDFALL" \
&& rm "$PDFALL" \
&& pstops "2:0(0,-.5h)+1U(1w,1.5h)" "${PDFALL%.pdf}.ps" "${OUTPDF%.pdf}.ps" \
&& rm "${PDFALL%.pdf}.ps" \
&& ps2pdf "${OUTPDF%.pdf}.ps" \
&& rm "${OUTPUTPDF%.pdf}.ps"
@yuwash

yuwash commented Jan 5, 2020

Copy link
Copy Markdown
Author

When pdftk isn’t available in more recent ubuntu repositories, you can convert both to ps first and then use psmerge.

Update: Or better (actually simpler than pdftk for this use case), use pdfunite like

pdfunite "$PDF1" "$PDF2" "$PDFALL"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment