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

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ก.ย. 2024

ความคิดเห็น • 54

  • @donghwikwak
    @donghwikwak 3 ปีที่แล้ว

    Thanks for teaching pythons

    • @CodingIsFun
      @CodingIsFun  3 ปีที่แล้ว

      Most welcome 😊 Thanks for watching the video 👍

  • @miguelorta3652
    @miguelorta3652 3 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      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!

  • @abhisheksrivastava8479
    @abhisheksrivastava8479 3 ปีที่แล้ว

    Great Tutorial

  • @KhalilYasser
    @KhalilYasser 3 ปีที่แล้ว

    Awesome. Thanks a lot.

    • @CodingIsFun
      @CodingIsFun  3 ปีที่แล้ว

      *A pleasure, thanks for watching!*

  • @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.

  • @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.

  • @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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      @@CodingIsFun thank you very much Sven! Really appreciate it!

    • @CodingIsFun
      @CodingIsFun  3 ปีที่แล้ว

      @@alecouto I'm happy to help.

  • @krishnajagadeesh6307
    @krishnajagadeesh6307 2 ปีที่แล้ว

    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  2 ปีที่แล้ว +1

      Spot on! This solution uses Python. For doing something similar in VBA, check out the following video:
      th-cam.com/video/2GjPjc-Jtvs/w-d-xo.html
      Happy Coding!

  • @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

  • @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 ปีที่แล้ว +1

      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:
      th-cam.com/video/2GjPjc-Jtvs/w-d-xo.html

  • @myfav7570
    @myfav7570 ปีที่แล้ว

    Sir whenever I click merge button first cmd screen pops up : how to resolve this issue

    • @CodingIsFun
      @CodingIsFun  ปีที่แล้ว +1

      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

  • @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  ปีที่แล้ว +1

      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  ปีที่แล้ว +1

      @@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

  • @abdullahrehman7321
    @abdullahrehman7321 ปีที่แล้ว

    Can you teach how to convert excel Report to pdf?

    • @CodingIsFun
      @CodingIsFun  ปีที่แล้ว

      Thanks for watching. Here is an example: stackoverflow.com/a/71978652

  • @ahmedelhaddad6817
    @ahmedelhaddad6817 2 ปีที่แล้ว

    great work thx
    and pls how to do the opposite

    • @CodingIsFun
      @CodingIsFun  2 ปีที่แล้ว +1

      Thanks for watching. Have a look here: stackoverflow.com/a/490203
      Happy Coding!

    • @ahmedelhaddad6817
      @ahmedelhaddad6817 2 ปีที่แล้ว

      @@CodingIsFun Thank u so much 🙏

  • @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  ปีที่แล้ว +1

      @@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!

  • @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 ปีที่แล้ว +1

      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:
      th-cam.com/video/iIATJtruZBE/w-d-xo.html
      In the video, I am covering different scenarios on how to combine Excel with Python.
      I hope this helps! Happy Coding! :)

  • @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 ปีที่แล้ว +1

      Have you installed the required dependency PyPDF as shown in the video? Thanks!