0

I've read through and tried multiple posts on similar topics and none satisfied my purpose.

I have multiple pdfs which are project reports for each week of a 16-week project and are titled Week1.pdf, Week2.pdf, ..., Week16.pdf. I'd like to combine them into a single large pdf with a single page between each new report. The single-page between each report must have a title like "Week 2" between the pdfs of Week1 and Week2 reports, "Week3" between the reports of Week2 and Week3, and so on.

I understand that the ImageMagick command convert can be used to create single pdf pages for the page breaks and ps2pdf package can later be used to combine all of them together. Is there a simpler or easier solution where I create such pdfs and combine them in a single shot?

Any suggestions/workarounds are very much appreciated!

1 Answer 1

0

Do you have any experience with python? This tutorial here explains how to do what you want at the "merge pdf" section.

# pdf_merging.py

from PyPDF2 import PdfFileReader, PdfFileWriter

def merge_pdfs(paths, output):
    pdf_writer = PdfFileWriter()

    for path in paths:
        pdf_reader = PdfFileReader(path)
        for page in range(pdf_reader.getNumPages()):
            # Add each page to the writer object
            pdf_writer.addPage(pdf_reader.getPage(page))

    # Write out the merged PDF
    with open(output, 'wb') as out:
        pdf_writer.write(out)

if __name__ == '__main__':
    paths = ['document1.pdf', 'document2.pdf']
    merge_pdfs(paths, output='merged.pdf')

You then just need to create a pdf page with what you want in between, and stitch them together with the above script.

There are plenty of methods to create a pdf page with your text, the easiest one is LaTex generation, but also any Word/OpenOffice let's you export your document as a PDF.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.