Results 1 to 13 of 13

Thread: NEED HELP! Merge many pdf files into single pdf file using Visual Basic

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2021
    Posts
    12

    Post NEED HELP! Merge many pdf files into single pdf file using Visual Basic

    Hi, I hope someone will help me, I am developing PDF BINDER APPS and everything went well until the last phase where I need to merge many pdf file. Will somebody teach me on how to merge many pdf files into single PDF file using VISUAL BASIC 6.0. I really don't know how to do it. What I need to do is to merge all the pdf files that the Datagrid show in filtering.

    Please see attached image for reference

    Thank you!
    Attached Images Attached Images  

  2. #2
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    471

    Re: NEED HELP! Merge many pdf files into single pdf file using Visual Basic

    Check my signature pour PDFAssist

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2021
    Posts
    12

    Re: NEED HELP! Merge many pdf files into single pdf file using Visual Basic

    I dont know how to use that. Can you teach me?

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,297

    Re: NEED HELP! Merge many pdf files into single pdf file using Visual Basic

    Quote Originally Posted by KipoyRavena View Post
    Please see attached image for reference
    The UI of your form is irrelevant because your main problem is merging just *two* PDF files.

    This is almost impossible to do in native VB6 without some 3-rd party component -- be it an ActiveX component or an external executable.

    So your quest must continue research components (DLL/OCX) or applications (EXE) which can merge two PDF files.

    Here is one project written in golang: https://github.com/pdfcpu/pdfcpu

    In releases tab there is a pdfcpu_0.3.12_Windows_i386.zip archive for Windows with a single 32-bit executable file (no extra dependencies like python implementations for instance).

    cheers,
    </wqw>

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2021
    Posts
    12

    Re: NEED HELP! Merge many pdf files into single pdf file using Visual Basic

    I need to merge not only 2 pdf files but more than 2 files. Sometimes I need to merge 3 pdf files , then sometimes 4 pdf files and so on. It depends how many pdf files that the datagrid will show when the user filter specific data.. I really have a big problem with this.

  6. #6
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,297

    Re: NEED HELP! Merge many pdf files into single pdf file using Visual Basic

    I just merged serveral PDFs with pdfcpu.exe utility above

    D:\TEMP>pdfcpu.exe merge result.pdf aaa.pdf bbb.pdf ccc.pdf
    aaa.pdf
    bbb.pdf
    ccc.pdf
    writing result.pdf...
    Didn't even have to read any documentation as the parameters on the command-line are obvious.

    cheers,
    </wqw>

  7. #7
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    471

    Re: NEED HELP! Merge many pdf files into single pdf file using Visual Basic

    I'll investigate pdfcpu.

    I need to add a image to some specific location in a PDF (a stamp).
    And it seems it coule be possible with pdfcpu
    I'll investigate

    NB : My PDFAssist is using Poppler

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2021
    Posts
    12

    Re: NEED HELP! Merge many pdf files into single pdf file using Visual Basic

    Thank you so much. I will try it. I wish this is the answer to my problem.

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2021
    Posts
    12

    Re: NEED HELP! Merge many pdf files into single pdf file using Visual Basic

    Quote Originally Posted by wqweto View Post
    The UI of your form is irrelevant because your main problem is merging just *two* PDF files.

    This is almost impossible to do in native VB6 without some 3-rd party component -- be it an ActiveX component or an external executable.

    So your quest must continue research components (DLL/OCX) or applications (EXE) which can merge two PDF files.

    Here is one project written in golang: https://github.com/pdfcpu/pdfcpu

    In releases tab there is a pdfcpu_0.3.12_Windows_i386.zip archive for Windows with a single 32-bit executable file (no extra dependencies like python implementations for instance).

    cheers,
    </wqw>
    But how can I use it on my visual basic program? Sorry for too many question.

  10. #10
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,297

    Re: NEED HELP! Merge many pdf files into single pdf file using Visual Basic

    Quote Originally Posted by KipoyRavena View Post
    But how can I use it on my visual basic program?
    Read this thread for some ideas how to do it.

    There are even easier ways using ShellExecute API like this

    Code:
    Option Explicit
    
    Private Declare Function ShellExecuteEx Lib "shell32" Alias "ShellExecuteExA" (lpExecInfo As SHELLEXECUTEINFO) As Long
    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    
    Private Type SHELLEXECUTEINFO
        cbSize              As Long
        fMask               As Long
        hWnd                As Long
        lpVerb              As String
        lpFile              As String
        lpParameters        As String
        lpDirectory         As Long
        nShow               As Long
        hInstApp            As Long
        '  optional fields
        lpIDList            As Long
        lpClass             As Long
        hkeyClass           As Long
        dwHotKey            As Long
        hIcon               As Long
        hProcess            As Long
    End Type
    
    Public Function ShellWait( _
                sFile As String, _
                sParameters As String, _
                Optional ByVal StartHidden As Boolean, _
                Optional Verb As String, _
                Optional ExitCode As Long) As Boolean
        Const SW_HIDE                       As Long = 0
        Const SW_SHOWDEFAULT                As Long = 10
        Const SEE_MASK_NOCLOSEPROCESS       As Long = &H40
        Const SEE_MASK_NOASYNC              As Long = &H100
        Const SEE_MASK_FLAG_NO_UI           As Long = &H400
        Const INFINITE                      As Long = -1
        Dim uShell          As SHELLEXECUTEINFO
        
        With uShell
            .cbSize = Len(uShell)
            .fMask = SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_NOASYNC Or SEE_MASK_FLAG_NO_UI
            .lpVerb = Verb
            .lpFile = sFile
            .lpParameters = sParameters
            .nShow = IIf(StartHidden, SW_HIDE, SW_SHOWDEFAULT)
        End With
        If ShellExecuteEx(uShell) <> 0 Then
            Call WaitForSingleObject(uShell.hProcess, INFINITE)
            Call GetExitCodeProcess(uShell.hProcess, ExitCode)
            Call CloseHandle(uShell.hProcess)
            '--- success
            ShellWait = True
        Else
            ExitCode = Err.LastDllError
        End If
    End Function
    cheers,
    </wqw>

  11. #11

    Thread Starter
    New Member
    Join Date
    Jul 2021
    Posts
    12

    Re: NEED HELP! Merge many pdf files into single pdf file using Visual Basic

    Thank you so much!

  12. #12

    Thread Starter
    New Member
    Join Date
    Jul 2021
    Posts
    12

    Re: NEED HELP! Merge many pdf files into single pdf file using Visual Basic

    Quote Originally Posted by wqweto View Post
    Read this thread for some ideas how to do it.

    There are even easier ways using ShellExecute API like this

    Code:
    Option Explicit
    
    Private Declare Function ShellExecuteEx Lib "shell32" Alias "ShellExecuteExA" (lpExecInfo As SHELLEXECUTEINFO) As Long
    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    
    Private Type SHELLEXECUTEINFO
        cbSize              As Long
        fMask               As Long
        hWnd                As Long
        lpVerb              As String
        lpFile              As String
        lpParameters        As String
        lpDirectory         As Long
        nShow               As Long
        hInstApp            As Long
        '  optional fields
        lpIDList            As Long
        lpClass             As Long
        hkeyClass           As Long
        dwHotKey            As Long
        hIcon               As Long
        hProcess            As Long
    End Type
    
    Public Function ShellWait( _
                sFile As String, _
                sParameters As String, _
                Optional ByVal StartHidden As Boolean, _
                Optional Verb As String, _
                Optional ExitCode As Long) As Boolean
        Const SW_HIDE                       As Long = 0
        Const SW_SHOWDEFAULT                As Long = 10
        Const SEE_MASK_NOCLOSEPROCESS       As Long = &H40
        Const SEE_MASK_NOASYNC              As Long = &H100
        Const SEE_MASK_FLAG_NO_UI           As Long = &H400
        Const INFINITE                      As Long = -1
        Dim uShell          As SHELLEXECUTEINFO
        
        With uShell
            .cbSize = Len(uShell)
            .fMask = SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_NOASYNC Or SEE_MASK_FLAG_NO_UI
            .lpVerb = Verb
            .lpFile = sFile
            .lpParameters = sParameters
            .nShow = IIf(StartHidden, SW_HIDE, SW_SHOWDEFAULT)
        End With
        If ShellExecuteEx(uShell) <> 0 Then
            Call WaitForSingleObject(uShell.hProcess, INFINITE)
            Call GetExitCodeProcess(uShell.hProcess, ExitCode)
            Call CloseHandle(uShell.hProcess)
            '--- success
            ShellWait = True
        Else
            ExitCode = Err.LastDllError
        End If
    End Function
    cheers,
    </wqw>


    Hi, how to run your application? I downloaded the files you provided, but when I am trying to open the application nothing happens.

  13. #13
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,297

    Re: NEED HELP! Merge many pdf files into single pdf file using Visual Basic

    Quote Originally Posted by KipoyRavena View Post
    Hi, how to run your application? I downloaded the files you provided, but when I am trying to open the application nothing happens.
    You run it in a console like cmd.exe. Press Win+R and type cmd.exe to start the so called "Windows Command Processor".

    In the command prompt navigate to the folder with your pdf files (cd c:\path\to\your\pdf\files) and type something like pdfcpu.exe merge output.pdf file1.pdf file2.pdf file3.pdf to merge file1.pdf, file2.pdf and file3.pdf into output.pdf

    cheers,
    </wqw>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width