VBA PDF Automation - Split pdf pages based upon text search (Part-1)

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ส.ค. 2024
  • This tutorial will demonstrate on how to get the target Pdf page out from entire document based on text search. This is "Single" string search based automation. However, practicalIT is open to make changes as and when required.
    #practicalIt #vbapdfautomation #pdftextsearch #searchtextinpdfpage #findtextinpdfpage

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

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

    Thank you very much for this tutorial. It has been very useful for me.

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

    It's very useful 😇😊
    Please upload part-2

  • @AyushGupta-no1yn
    @AyushGupta-no1yn ปีที่แล้ว

    This is a wonderful tutorial, and I appreciate you sharing it with us. It would be helpful if you could tell me more about VBA Developer skills. VBA is a huge language, so one must possess the skills of a VBA developer.

  • @lucasdab6688
    @lucasdab6688 4 หลายเดือนก่อน

    Epic. You are master! I've a question about what should be modified to search for text such as 125/6. I turned off checking whether the value being searched for is a number in the code, but it finds 125 without /6. Same thing with the time 19:55 - it finds 19 or 55 separately. It doesn't see 19:55. What should be modified to find data of the 125/6 type?

    • @practicalit91
      @practicalit91  4 หลายเดือนก่อน

      Currently this macro is designed to search for string text to give accurate results. Searching numbers may give undesired output.

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

    Option Explicit
    'Part 1
    Sub Search_text_and_splitPages()
    Dim Acro_App As Acrobat.AcroApp
    Dim Acro_AVDoc As Acrobat.AcroAVDoc
    Dim Acro_PDDoc As Acrobat.AcroPDDoc
    Dim Acro_JSO As Object
    Dim F_path As String
    Dim Search_Word As String
    Dim Pg_Cntr As Long
    Dim Wrd_cntr As Long
    Dim word As String
    Dim result As Long
    Dim trick As Boolean
    'Turn off screen updating
    Application.ScreenUpdating = False
    'Initialize variables
    Set Acro_App = New Acrobat.AcroApp
    Set Acro_AVDoc = New Acrobat.AcroAVDoc
    'F_path = "C:\Users\Sunil Kumar\OneDrive\Desktop\To be Uploaded\Page to PDF\Page.pdf"
    F_path = "C:\Users\Sunil Kumar\OneDrive\Desktop\To be Uploaded\Page to PDF\Vendor List_210415_Published-Final.pdf"
    Search_Word = Sheet1.Range("A1").Value
    'Validate if range A1 is appearing a number
    If VBA.IsNumeric(Search_Word) Then GoTo ExitMacro
    'open PDF File
    Acro_AVDoc.Open F_path, ""
    Set Acro_PDDoc = Acro_AVDoc.GetPDDoc
    'Initialize JSO object
    Set Acro_JSO = Acro_PDDoc.GetJSObject
    For Pg_Cntr = 0 To Acro_JSO.numpages - 1
    'Debug.Print Acro_JSO.getpagenumwords(Pg_Cntr) - 1
    For Wrd_cntr = 0 To Acro_JSO.getpagenumwords(Pg_Cntr) - 1

    'check if the word is string
    word = Acro_JSO.getpagenthword(Pg_Cntr, Wrd_cntr)

    If VBA.VarType(word) = vbString Then
    'lets compare the word
    result = VBA.StrComp(word, Search_Word, vbTextCompare)

    'check if the match is found
    If result = 0 Then
    'select the word by calling JS object
    Call Acro_JSO.getpagenthword(Pg_Cntr, Wrd_cntr)

    'Print the page number where word is selected
    Debug.Print Acro_JSO.getpagelabel(Pg_Cntr) - 1

    'Extract PDF Page
    Acro_JSO.extractpages Pg_Cntr, Pg_Cntr, "C:\Users\Sunil Kumar\OneDrive\Desktop\ext" & Pg_Cntr & ".pdf"
    trick = True
    If Pg_Cntr = Acro_JSO.numpages - 1 Then GoTo exit_programme
    GoTo nxtpage
    End If

    End If

    Next Wrd_cntr
    nxtpage:
    Next Pg_Cntr
    If Pg_Cntr = Acro_JSO.numpages And trick = False Then GoTo ExitMacro Else GoTo exit_programme
    ExitMacro:
    MsgBox "Sorry!! NO matches found, Please re-check the word you are looking for. " & vbCrLf & _
    "It should be single word only"
    GoTo Out
    exit_programme:
    MsgBox "Page(s) Extracted"
    Out:
    Acro_AVDoc.Close False
    Acro_App.Exit
    Set Acro_JSO = Nothing
    Set Acro_PDDoc = Nothing
    Set Acro_AVDoc = Nothing
    Set Acro_App = Nothing
    End Sub

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

    Great job 👍 👌 , Sir, can you explain How to rename PDF files using on content (Invoice Number ect...)

  • @KuldeepSingh-nq1vi
    @KuldeepSingh-nq1vi ปีที่แล้ว

    Hi Sir, Please make a Complete Video on Class Module in VBA in details...

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

    Thank you This was really helpful....I am stuck on the line code where pdf is been extracted to new pdf doc it is throwing error like The file is read only or this may have opened at other user.please save document with different file name or folder...I tried some Google solution but it didn't work...can you please help me with this?

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

    Sir how to automate strike out captcha using selenium Pls post video sir

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

      It depends on nature of captcha. I tried to create trained model of captcha available on web page. It works only for 20-30% for distorted fonts & strike out captcha ,sometimes it doesn't not. This is for your information. Also there is no sufficient trained font model library on github. Still waiting for some major updates from github.

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

    Acrobat is mandatory????

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

    can you give the no. please