Você está procurando a montagem do ImageMagick? ImageMagick pode trabalhar em pdf.
Se você quiser algo mais flexível do que a montagem do ImageMagick, você também pode escrever um script simples na linguagem Python com pyPdf biblioteca. pyPdf pode mesclar páginas PDF e aplicar transformações básicas (por exemplo, conversão, rotação, dimensionamento). Exemplo de script:
import pyPdf
def merge_horizontal(out_filename, left_filename, right_filename):
""" Merge the first page of two PDFs side-to-side """
# open the PDF files to be merged
with open(left_filename) as left_file, open(right_filename) as right_file, open(out_filename, 'w') as output_file:
left_pdf = pyPdf.PdfFileReader(left_file)
right_pdf = pyPdf.PdfFileReader(right_file)
output = pyPdf.PdfFileWriter()
# get the first page from each pdf
left_page = left_pdf.pages[0]
right_page = right_pdf.pages[0]
# start a new blank page with a size that can fit the merged pages side by side
page = output.addBlankPage(
width=left_page.mediaBox.getWidth() + right_page.mediaBox.getWidth(),
height=max(left_page.mediaBox.getHeight(), right_page.mediaBox.getHeight()),
)
# draw the pages on that new page
page.mergeTranslatedPage(left_page, 0, 0)
page.mergeTranslatedPage(right_page, left_page.mediaBox.getWidth(), 0)
# write to file
output.write(output_file)
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc:
if not (exc.errno == errno.EEXIST and os.path.isdir(path)):
raise
if __name__ == '__main__':
import sys, os, errno
output_folder_name = sys.argv[1]
left_folder_name = sys.argv[2]
right_folder_name = sys.argv[3]
left_files = set(os.listdir(left_folder_name))
right_files = set(os.listdir(right_folder_name))
mkdir_p(output_folder_name)
# for every files that are in both left_files and right_files
for f in left_files.intersection(right_files):
output_file_name = os.path.join(output_folder_name, f)
left_file_name = os.path.join(left_folder_name, f)
right_file_name = os.path.join(right_folder_name, f)
print 'merging %s and %s into %s' % (left_file_name, right_file_name, output_file_name)
merge_horizontal(output_file_name, left_file_name, right_file_name)
# pair is missing, not merging
print 'Only in left folder: ', left_files - right_files
print 'Only in right folder: ', right_files - left_files
E chame o script da seguinte forma:
python merge.py output_folder left_folder right_folder
Exemplo de saída:
merging folderA/two.pdf and folderB/two.pdf into output/dacd/adca/two.pdf
merging folderA/one.pdf and folderB/one.pdf into output/dacd/adca/one.pdf
merging folderA/three.pdf and folderB/three.pdf into output/dacd/adca/three.pdf
Only in left folder: set(['four.pdf'])
Only in right folder: set(['five.pdf'])