Am looking for a way to join separate PDF files I exported from QGIS layout, with specific naming format will include decimal number at beginning. 1- 8.5_Point_5555 2- 01.50_Point_5557 3- 12.0_line_5554 4- 00.5_polygon_3554 The issue that when joining, Python will use the ASCii order so 12.0 will be before 8.5 because 1 is before 8, I tried to trick it by adding zeros on left side but same issue again, I saw Natsorting library but still can't work. Any Suggestion? This the code am using
from PyPDF2 import PdfFileMerger
import os
from natsort import natsorted, ns
from natsort import os_sorted
#List name
#Create and instance of PdfFileMerger() class
merger = PdfFileMerger()
#Create a list with PDF file names
path_to_files = r'C:/Users/Ahmed.Ismail/Documents/IMAGES/delete/example/New folder/'
#Get the file names in the directory
for root, dirs, file_names in os.walk(path_to_files):
#Iterate over the list of file names
#natsorted(file_names)
#natsorted(file_names, key=lambda x: x.replace('apple', ''), alg=ns.REAL)
os_sorted(file_names)
for file_name in file_names:
#Append PDF files
merger.append(path_to_files + file_name)
#Write out the merged PDF
merger.write("merged_all_pages.pdf")
merger.close()