import PyPDF2 import os import sys # Recupera a string passada como argumento string_argument = sys.argv[1] input_folder_path = string_argument def convert_pdf_to_v1_4(input_path, output_path): # Open the input PDF file with open(input_path, 'rb') as input_file: # Create a PDF reader object reader = PyPDF2.PdfReader(input_file) # Create a PDF writer object writer = PyPDF2.PdfWriter() # Iterate over each page in the input PDF for page_num in range(len(reader.pages)): # Get the page at the specified index page = reader.pages[page_num] # Add the page to the writer object writer.add_page(page) # Open the output PDF file with open(output_path, 'wb') as output_file: # Set the PDF version in the output file's trailer writer._root_object.update({ PyPDF2.generic.NameObject('/Version'): PyPDF2.generic.create_string_object('(1.4)') }) # Write the modified PDF to the output file writer.write(output_file) # # Specify the input and output file paths # input_file_path = '10257396551/0cdc03272c0f1cfecb5462da9b4d65ae29ee196a.pdf' # output_file_path = '10257396551/0cdc03272c0f1cfecb5462da9b4d65ae29ee196a.pdf' # # Convert the PDF to version 1.4 # convert_pdf_to_v1_4(input_file_path, output_file_path) for filename in os.listdir(input_folder_path): if filename.lower().endswith('.pdf'): input_file_path = os.path.join(input_folder_path, filename) output_file_path = os.path.join(input_folder_path, filename) print(input_file_path) convert_pdf_to_v1_4(input_file_path, output_file_path)