#!/bin/bash # Usage: 1colpdf *.pdf, where the pdf files are proceeding files in 2 columns # Creates 1col-*.pdf file, 1-column files for ebook readers # Needs: pdflatex pdftotext pdfcrop for SOURCE in $@ do # This parts outputs 2n pages, one per left col, one per right col pdflatex -interaction batchmode -jobname="tmp1" \ "\documentclass[twoside]{article}" \ "\usepackage{pdfpages}" \ "\begin{document}" \ "\includepdf[pages=-,doublepages,offset={4.25in 0in}]{$SOURCE}" \ "\end{document}" # This parts outputs the text in the PDF file up to the word Abstract # It also bolds the first line it reads, hoping it is the title of the paper pdftotext -eol unix -l 1 -layout $SOURCE - | { read x echo "{\\bf $x}\\\\[\\medskip]" while read x do if [[ "foo$x" == foo*Abstract* ]] then break fi echo "$x\\\\" done } > tmp2 # This parts merges the 2n pages + 1 page for title and author pdflatex -interaction batchmode -jobname="tmp3" \ "\documentclass{article}" \ "\setlength{\textwidth}{3.5truein}" \ "\pdfpagewidth=3.5truein" \ "\usepackage{pdfpages}" \ "\pagestyle{empty}" \ "\begin{document}" \ "\begin{flushleft}\large" \ `cat tmp2` \ "\end{flushleft}" \ "\newpage" \ "\includepdf[pages=-,noautoscale]{tmp1}" \ "\end{document}" # This part shrinks the margins to fit the reduced file # It's very slow! pdfcrop --margins '10 10 10 10' tmp3.pdf 1col-$SOURCE # cleanup rm tmp1.* tmp2 tmp3.* done