[PYTHON] Batch convert image files uploaded to MS Forms / Google Forms to PDF

Batch convert image files submitted to MS Forms / Google Forms to PDF

Image file format uploaded to MS Forms

--The files uploaded through MS Forms are as follows. --File name_Student's first and last name. Extension. It is in the format of. Please note that some people have surnames. --0FBABF78-CCCB-4958-A17B-61BC43EF27D3_ Tech Taro.jpeg --0FBABF78-CCCB-4958-A17B-61BC43EF27D3_ Tech Taro 1.jpeg --If an image is specified as the format to be submitted in the form, jpg, png, pdf, etc. exist. The file name part depends on the student, so if a file with the same name is submitted, it seems that a serial number will be added like name 1.jpeg. --test_ Tech Hanako.png --I want to convert this to a file with student number_serial number.pdf as shown below.

Format of image files uploaded to Google Forms

--The files uploaded through Google Forms are as follows. --File name --Student's first and last name. Extension. It is in the format of. Please note that some students may have surnames. --0FBABF78-CCCB-4958-A17B-61BC43EF27D3 --Technical University Taro.jpeg --0FBABF78-CCCB-4958-A17B-61BC43EF27D3 --Taro Institute of Technology (1) .jpeg --When the same student uploads a file with the same name, (1) etc. will be added after the second one. --test_ Tech Hanako.png --I want to convert this to a file with student number_serial number.pdf as shown below.

What you can and cannot do

--Image files submitted using the file upload function of MS Forms or Google Forms can be individually converted to PDF such as student number_serial number.pdf based on the list information. --PDF conversion other than image files is not possible --Only jpg and png are supported by image files. Not compatible with other formats such as heic --For docx, pptx, html, etc., assume batch conversion with Acrobat after converting the file name with ren_ * file2sid.py --Start Acrobat-> File-> Create-> Create multiple PDF files

I couldn't do it, but now I can

--The first and last name was flipped in the original file --Fixed to search by both surname and surname patterns --In some cases, the same student uploaded a file with the same name at the same time. --Since it seems that serial numbers are added to the end of the file name, such as "1.jpg " and "(1) .jpg ", the numbers were deleted using regular expressions when extracting the first and last name from the file name. --Conversion may fail due to Value error, etc.-> Conversion succeeds when the program is re-executed (so far, almost 100% re-execution is successful. The cause is unknown). --If the file name contains machine-dependent characters such as 4 in ○, it will fail if it is cp932 when outputting csv. --Changed the character code for output to utf8

Preparation

--Create a csv file in the following format --There must be a space between the first and last name --The file must be the character code of cp932 output from Excel as csv. --This program outputs csv for managing the converted file name, but it is output with utf8 (because machine-dependent characters may be used in the file name).

sid name
B88000 Institute of Technology Taro
B87999 Hanako, Institute of Technology

--Collect the uploaded image files in a specific folder

PDF conversion of image files submitted to MS Forms

Rename file (ren_msfile2sid.py)

Change to PDF file (con_sid2pdf.py)

PDF conversion of image files submitted to Google Forms

Rename file (ren_gfile2sid.py)

Change to PDF file (con_sid2pdf.py)

--Same as the one used on the MS Forms side

Recommended Posts

Batch convert image files uploaded to MS Forms / Google Forms to PDF
Batch convert PSD files in directory to PDF
Convert PDF to image with ImageMagick
Convert PDF files to PNG files with GIMP
Convert PDF to image (JPEG / PNG) with Python
Convert multiple jpg files to one PDF file
Convert the image in .zip to PDF with Python
Batch convert all xlsx files in the folder to CSV files
Convert a large number of PDF files to text files using pdfminer
Convert PDF to Documents by OCR
Convert markdown to PDF in Python
Convert A4 PDF to A3 every 2 pages
Workflow to convert formula (image) to python
Convert from pdf to txt 2 [pyocr]
Convert a string to an image
Convert from PDF to CSV with pdfplumber
Convert PDF attached to email to text format
Convert HEIC files to PNG files with Python
Sample to convert image to Wavelet with Python
Create an API to convert PDF files to TIF images with FastAPI and Docker