Python Forum
Most optimized way to merge figures from multiple PDFs into one PDF page? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Most optimized way to merge figures from multiple PDFs into one PDF page? (/thread-18554.html)



Most optimized way to merge figures from multiple PDFs into one PDF page? - dmm809 - May-22-2019

Hi everyone!

The thread can be found from here:
https://stackoverflow.com/questions/56239621/most-optimized-way-to-merge-figures-from-multiple-pdfs-into-one-pdf-page?fbclid=IwAR0IwToEzhvOPp1TL9A_h9bVNoFcVA5-Xe_o1V9ECIac8rShF4kTgjHXW5c

Br,
Tuukka


RE: Most optimized way to merge figures from multiple PDFs into one PDF page? - micseydel - May-22-2019

For others:
Quote:I'm the developer of NLS GNSS SOFAMESA (https://github.com/nlsfi/nls-gnss-sofamesa) and releasing a new version of it this week. There are many updates coming. However, I haven't figured out, what is the most optimized way to merge figures from multiple pdfs into one pdf page. I have utilized reportlab and pypdf2 libraries to produce the pdfs.

First pdf file: 18 figures on separate pages. Total 18 pages.

Second pdf file: 18 figures on separate pages. Total 18 pages.

Combined pdf file: 36 figures so that the first figure from the first pdf file matches with the first figure from the second pdf file. Thus, two figures per page. Total 18 pages.

Later on there should be maximum 5 figures per page from five different pdfs. ^ the two pdf file example is just an example.

Option 1: If the "Combined pdf file" can be produced by the help of merging the existing first and second pdf files, this would be the fastest way.

Option 2: The figures are saved to a specific folder location, so I could just make a new pdf from the figure locations. Not the fastest way.

Example, in merger1 "...Combined_Measurement_Report_plain.pdf" is uncorrectly created containing the figures:

def merger1(output_path, input_paths):
    pdf_merger = PdfFileMerger()

    for path in input_paths:
        pdf_merger.merge(position = 1, fileobj = path, pages = (5, 22))

    with open(output_path, 'wb') as fileobj:
        pdf_merger.write(fileobj)

    output_path = [output_path]
    return output_path
output_filepaths = merger1('{0}{3}{1}_{2}_Combined_Measurement_Report_plain.pdf'.format(number_of_visit_at_the_reference_point_folder_path, name_of_the_reference_point_folder, number_of_visit_at_the_reference_point, os.sep), filepaths)
As previously described, I expect:

Combined pdf file: 36 figures so that the first figure from the first pdf file matches with the first figure from the second pdf file. Thus, two figures per page. Total 18 pages.

Later on there should be maximum 5 figures per page from five different pdfs. ^ the two pdf file example is just an example.