Python Forum
Most optimized way to merge figures from multiple PDFs into one PDF page?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Most optimized way to merge figures from multiple PDFs into one PDF page?
#1
Hi everyone!

The thread can be found from here:
https://stackoverflow.com/questions/5623...4kTgjHXW5c

Br,
Tuukka
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Comparing PDFs CaseCRS 5 1,203 Apr-01-2023, 05:46 AM
Last Post: DPaul
  OCR-Python from Multi TIFF to HOCR getting only Data from 1st Page of multiple TIFF JOE 0 2,161 Feb-18-2022, 03:18 PM
Last Post: JOE
  download pubmed PDFs using pubmed2pdf in python Wooki 8 5,482 Oct-19-2020, 03:06 PM
Last Post: jefsummers
  How to compare two PDFs for differences Normanie 2 2,405 Jul-30-2020, 07:31 AM
Last Post: millpond
  Concatenate multiple PDFs using python gmehta1996 0 2,116 Mar-29-2020, 09:48 PM
Last Post: gmehta1996
  How to read multiple csv files and merge data rajeshE 0 1,954 Mar-28-2020, 04:01 PM
Last Post: rajeshE
  Merging pdfs with PyPDF2 Pedroski55 0 3,288 Mar-07-2019, 11:58 PM
Last Post: Pedroski55
Photo How to Extract Specific Words from PDFs with Python danvsv 1 4,521 Jan-17-2019, 11:07 AM
Last Post: Larz60+
  reading pdfs in windows10 - Python 3.6 cobra 1 5,329 May-10-2018, 09:40 PM
Last Post: nilamo
  Round a number up to certain significant figures brocq_18 4 7,219 Apr-06-2017, 06:49 PM
Last Post: alicarlos13

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020