How to Merge Multiple PDF Files in Excel Using Python (fast & easy)

  Рет қаралды 9,367

Coding Is Fun

Coding Is Fun

Күн бұрын

Пікірлер: 54
@miguelorta3652
@miguelorta3652 3 жыл бұрын
Congratulations, excellent application! Is it possible to join PDF sheets in a specific order? I used your application but when I joined the PDF sheets the one I wanted to be sheet number 2 was number 17.
@CodingIsFun
@CodingIsFun 3 жыл бұрын
Thank you very much for watching the video. I am glad you like the solution. The 'append' method will just append the pdf to the end. Meaning, the order is then defined by the order you will get back from the 'pdf_files' list: pdf_files = list(Path(source_dir).glob("*.pdf")) One option could be to reorder the list before using it in the for-loop. Example: pdf_files = list(Path(source_dir).glob("*.pdf")) # Let's assume you have 5 pdf files in the folder myorder = [3, 2, 0, 1, 4] pdf_files= [pdf_files[i] for i in myorder] Alternatively, you can also use the 'merge' method, which merges the pages from the given file into the output file at the specified page number. Here is the documentation: pythonhosted.org/PyPDF2/PdfFileMerger.html#PyPDF2.PdfFileMerger.merge Hope this helps!
@fahuil146
@fahuil146 3 жыл бұрын
Thanks for the tutorial! What modifications need to be done to module/vba in mac system?
@CodingIsFun
@CodingIsFun 3 жыл бұрын
Thank you for watching the video. I do not have a mac available to test the code. Yet, xlwings and the containing VBA code should be also working on mac os.
@donghwikwak
@donghwikwak 3 жыл бұрын
Thanks for teaching pythons
@CodingIsFun
@CodingIsFun 3 жыл бұрын
Most welcome 😊 Thanks for watching the video 👍
@abhisheksrivastava8479
@abhisheksrivastava8479 3 жыл бұрын
Great Tutorial
@CodingIsFun
@CodingIsFun 3 жыл бұрын
Glad you like it!
@mattpensa9850
@mattpensa9850 2 жыл бұрын
Hey, great video. Can you post all of the code for the Sub SampleCall()? It's cut off in the view and I'm having some issues with the code in that sub.
@CodingIsFun
@CodingIsFun 2 жыл бұрын
Thanks for watching. I have uploaded the files incl. the workbook (with the VBA code) to GitHub. Please find it here: github.com/Sven-Bo/merge-pdf-files-in-excel
@seevlog4317
@seevlog4317 Жыл бұрын
File error file new
@alecouto
@alecouto 3 жыл бұрын
Great video. It makes me wonder if It's possible to detect and extract fields in a standardized pdf file and add it to a database?
@CodingIsFun
@CodingIsFun 3 жыл бұрын
Thank you! Yes, it should be possible. I got some inspiration from the following StackOverflow post: stackoverflow.com/questions/3984003/how-to-extract-pdf-fields-from-a-filled-out-form-in-python ... and created the following example for you: 👉 drive.google.com/file/d/1jjprU34kPWhJ-BJL3-wmvRPSiqtErS4r/view?usp=sharing The script will get the values from the PDF Form. You can then add those values to your preferred database. Hope it helps 🙏 Cheers, Sven ✌
@CodingIsFun
@CodingIsFun 3 жыл бұрын
Hi Alexandre, In my lunch break, I shortly extended my previous example. The script will now loop over any given folder, get only pdf files, get the values from the fields and export the result to Excel. You can find the updated example here: drive.google.com/file/d/16b_gx4iU3AOIekwYEG_6OaIu4Yao6M0F/view?usp=sharing Hope it gives you a good starting point for your individual project. If you need any support, please let me know. Thank you.
@alecouto
@alecouto 3 жыл бұрын
@@CodingIsFun thank you very much Sven! Really appreciate it!
@CodingIsFun
@CodingIsFun 3 жыл бұрын
@@alecouto I'm happy to help.
@KhalilYasser
@KhalilYasser 3 жыл бұрын
Awesome. Thanks a lot.
@CodingIsFun
@CodingIsFun 3 жыл бұрын
*A pleasure, thanks for watching!*
@ahmedelhaddad6817
@ahmedelhaddad6817 2 жыл бұрын
great work thx and pls how to do the opposite
@CodingIsFun
@CodingIsFun 2 жыл бұрын
Thanks for watching. Have a look here: stackoverflow.com/a/490203 Happy Coding!
@ahmedelhaddad6817
@ahmedelhaddad6817 2 жыл бұрын
@@CodingIsFun Thank u so much 🙏
@abdullahrehman7321
@abdullahrehman7321 2 жыл бұрын
Can you teach how to convert excel Report to pdf?
@CodingIsFun
@CodingIsFun 2 жыл бұрын
Thanks for watching. Here is an example: stackoverflow.com/a/71978652
@DuyPham-px4yj
@DuyPham-px4yj 3 жыл бұрын
Hi Can I ask if this application can be run on a computer that does not have python installed? Thank you so much.
@CodingIsFun
@CodingIsFun 3 жыл бұрын
Thank you for watching the video. No, that is not possible. You could, however, convert the .py file to a standalone executable file (.exe) using 'pyinstaller'. Once converted, you can execute the .exe file from VBA. Hope this helps! :)
@DuyPham-px4yj
@DuyPham-px4yj 3 жыл бұрын
@@CodingIsFun Great! Thanks for help me ^.^
@nullhas
@nullhas 3 жыл бұрын
Hi, Can we do this using only VBA? Without using python?
@CodingIsFun
@CodingIsFun 3 жыл бұрын
Thanks for watching the video. No, you could also use VBA for this. 'VBAA2Z' has a great video on how to merge pdf files using VBA: kzbin.info/www/bejne/aHjNgZ2ZYq-nrNU
@myfav7570
@myfav7570 Жыл бұрын
Sir, I made executable file. Then the foll code is to be placed in module1 Sub MySample() RunFrozenPython "F:\Currentwork\PDFmerge\pdfmerger.exe", "arg1 arg2" End Sub Here my both files excel and pdfmerger.exe is in F drive in above said path. What is arg1 and arg2 I dont know? I am not getting my combined file
@CodingIsFun
@CodingIsFun Жыл бұрын
Thanks for watching and for your question. Hard to tell from a distance why you are facing an error. Sorry that I cannot help.
@krishnajagadeesh6307
@krishnajagadeesh6307 3 жыл бұрын
Dear Sir without installing python we can't use We need to only excel vba using to compile all pdf in single file it is possible sir Kindly your advise
@CodingIsFun
@CodingIsFun 3 жыл бұрын
Spot on! This solution uses Python. For doing something similar in VBA, check out the following video: kzbin.info/www/bejne/aHjNgZ2ZYq-nrNU Happy Coding!
@myfav7570
@myfav7570 Жыл бұрын
Sir , in my excel the code stops at RunPython , i did everything as per video. Do i have to install xlwings addin
@CodingIsFun
@CodingIsFun Жыл бұрын
Thanks for watching and for your question. Hard to tell from a distance why you are facing an error. Sorry that I cannot help.
@myfav7570
@myfav7570 Жыл бұрын
You reply to every one questions, that’s so great sir. Really appreciate you. Sir I got where my mistake is. I have one more question if I want to share this excel file to pc where no python is installed,then by .python executable file I have to share, but along with it does this excel file also has to be shared.?
@CodingIsFun
@CodingIsFun Жыл бұрын
@@myfav7570 How did you manage to resolve your issue? Sharing your solution here could be really helpful for others who might face the same problem. Regarding your question, if the other device doesn't have Python installed, you'll need to convert your Python script into a standalone executable file. After that, you can run the file using the xlwings VBA module. For more details, check out this link: docs.xlwings.org/en/0.30.2/deployment.html
@myfav7570
@myfav7570 Жыл бұрын
@@CodingIsFun Sir Thank you for your reply. First of all my issue got resolved because i did not followed properly the first step of quickstart----- so My code did not ran properly. Next sir now my code is running properly, but in start i am getting cmd screen -- how to avoid this. Secondly , I am not getting output name as I am specifying in excel sheet & the file is genered in name "output_name" and also not getting ".pdf" extension to it. so i have to right click and select open with acrobat reader... Hope I am able to convey my problem.
@myfav7570
@myfav7570 Жыл бұрын
SIr I have to change my code little bit because it gave me error. I am writing my code here.from PyPDF2 import PdfMerger, PdfReader , It gave me error if I wrote" PdfFileMerger", "PdfFIleReader". Also at this line of code [output_name=sheet.range('output_name').value+'.pdf'] the output_name is greyed out and while hovering over it says "output_name" is not accessed by Pylance. Please guide me. Thank you
@analyticsadda6080
@analyticsadda6080 Жыл бұрын
I love this but I want to do this with VBA not using python.
@CodingIsFun
@CodingIsFun Жыл бұрын
Thank you for watching the video & your suggestion.
@analyticsadda6080
@analyticsadda6080 Жыл бұрын
@@CodingIsFun How can I do this with VBA.
@CodingIsFun
@CodingIsFun Жыл бұрын
@@analyticsadda6080 I receive many requests for creating individual solutions. As much as I want to help, I simply do not find the time in my daily schedule to develop & test all the different requests. I hope you can understand. Thank you!
@myfav7570
@myfav7570 Жыл бұрын
Sir whenever I click merge button first cmd screen pops up : how to resolve this issue
@CodingIsFun
@CodingIsFun Жыл бұрын
Unhide the hidden worksheet, remove the leading underscore _ from the sheet name and set showConsole to False: docs.xlwings.org/en/latest/addin.html#workbook-config-xlwings-conf-sheet
@myfav7570
@myfav7570 Жыл бұрын
@@CodingIsFun sir it worked, only I have to remove underscore. Because it was originally set to false only. Thank you sir
@sathikraja5865
@sathikraja5865 2 жыл бұрын
I am get below mentioned Error: --------------------------- Error --------------------------- Traceback (most recent call last): File "", line 1, in File "c:\users\sathikraja.segu\pdfmerger\pdfmerger.py", line 3, in from PyPDF2 import PdfFileMerger, PdfFileReader ModuleNotFoundError: No module named 'PyPDF2' Press Ctrl+C to copy this message to the clipboard. --------------------------- OK --------------------------- Kindly help me
@CodingIsFun
@CodingIsFun 2 жыл бұрын
Have you installed the required dependency PyPDF as shown in the video? Thanks!
@madhurimotamarri2910
@madhurimotamarri2910 2 жыл бұрын
Im getting an error at the very beginning: --------------------------- Error --------------------------- Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases. Press Ctrl+C to copy this message to the clipboard. --------------------------- OK ---------------------------
@CodingIsFun
@CodingIsFun 2 жыл бұрын
Have you already installed Python?
@vishnupeteti8408
@vishnupeteti8408 2 жыл бұрын
@@CodingIsFun yeah already installed main anaconda not miniconda-- installed miniconda again and it worked! Just wondering if you know how to get python in an existing pdf file ?
@CodingIsFun
@CodingIsFun 2 жыл бұрын
@@vishnupeteti8408 Can you perhaps elaborate on what it is you're actually trying to achieve? Please provide some additional info. Thanks!
@vishnupeteti8408
@vishnupeteti8408 2 жыл бұрын
@@CodingIsFun I'm sorry -- so basically I have a user form doing many different things and I want it to combine pdfs as an extra feature. I just wanted to know how to allow python to work with an existing excel file in order to build this in
@CodingIsFun
@CodingIsFun 2 жыл бұрын
@@vishnupeteti8408 Alright, you might want to check out the following video: kzbin.info/www/bejne/n3qkhX2qp9qNeKc In the video, I am covering different scenarios on how to combine Excel with Python. I hope this helps! Happy Coding! :)
Will A Basketball Boat Hold My Weight?
00:30
MrBeast
Рет қаралды 152 МЛН
Disrespect or Respect 💔❤️
00:27
Thiago Productions
Рет қаралды 34 МЛН
Car Bubble vs Lamborghini
00:33
Stokes Twins
Рет қаралды 37 МЛН
How To Read PDF Files in Python using PyPDF2
11:32
Mukesh otwani
Рет қаралды 77 М.
How to Create PDF Files with Python [New Method 2024]
22:27
The PyCoach
Рет қаралды 55 М.
Merge PDF Files in Python
6:30
NeuralNine
Рет қаралды 15 М.