[Ra...] Posted March 19, 2025 Share Posted March 19, 2025 Hi, I need help installing a Python library "pypdf" to combine pdf from different reports. Ultimately I want to make a script that combines pdf files from several reports into one file and save it under a different name, Each pdf file or page is always to be added to the end of the file ready to be save as. I work on GOM Scanbox 6, Atos 2020 nad 20222. Sample script in attachment - pdf.txt pdf.txt Link to comment Share on other sites More sharing options...
[Ma...] Posted March 31, 2025 Share Posted March 31, 2025 (edited) Hi Please sign in to view this username. , You already provided a mostly working solution. In ZEISS INSPECT 2025, you install Python packages with the App Editor as follows: ZEISS INSPECT 2025 provides the `choose_file()` command (see Selecting a file or folder), which can be configured interactively to request an existing folder, an existing file or a new file as in the following script: import gom import os from PyPDF2 import PdfMerger def merge_pdfs_with_last_file(input_folder, last_file, output_file): # Creating a PdfMerger object merger = PdfMerger() # Retrieving all PDF files in the folder pdf_files = [file for file in os.listdir(input_folder) if file.endswith('.pdf')] # Sorting files alphabetically (optional) pdf_files.sort() # Adding PDF files to the PdfMerger object for pdf in pdf_files: pdf_path = os.path.join(input_folder, pdf) if os.path.abspath(pdf_path) != os.path.abspath(last_file): # Skipping the file specified to be at the end merger.append(pdf_path) # Adding the file that should be at the end merger.append(last_file) # Saving the merged PDF file merger.write(output_file) merger.close() print(f"Merged PDF files and saved as '{output_file}'") if __name__ == "__main__": # Location of the folder with PDF files input_folder=gom.script.sys.choose_file (selection_type='select directory') # Path to the file that should be added at the end last_file=gom.script.sys.choose_file ( file_types=[['*.pdf', 'PDF files'], ['*.*', 'All files']], file_types_default='*.pdf', folder='', file='', selection_type='load file') # Location of the output file output_file=gom.script.sys.choose_file ( file_types=[], file_types_default='', folder='', file='', selection_type='new file') merge_pdfs_with_last_file(input_folder, last_file, output_file) As an alternative, you create a user-defined dialog with File Widgets, which also works in older versions of ZEISS INSPECT. Best regards, Matthias Edited March 31, 2025 1 Link to comment Share on other sites More sharing options...
[Ma...] Posted March 31, 2025 Share Posted March 31, 2025 BTW: You can also use pypdf (which is newer than PyPDF2) with minimal modifications: [...] from pypdf import PdfWriter def merge_pdfs_with_last_file(input_folder, last_file, output_file): # Creating a PdfWriter (formerly PdfMerger) object merger = PdfWriter() [...] 1 Link to comment Share on other sites More sharing options...
[Ra...] Posted April 1, 2025 Author Share Posted April 1, 2025 (edited) Hi Please sign in to view this username. Thanks for your help and information. I downloaded the pypdf package, during installation I don't want to overwite data the current py files, because the installed ones are used in other processes. I would like to be sure that my pypdf package will not affect the work of Atos and the scanning robot, so the installation must be on the user folder - "test pypdf". This is the first time I install the py package on Atos Scanbox. Edited April 1, 2025 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in