Results 1 to 17 of 17

Thread: Convert all jpg and pdf files from folder into 1 single pdf with same width

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #14
    try this on a sample folder.
    Public Sub subTestMagick()
        Dim inPath As String
        Dim outPath As String
        Dim Path As String
        Dim dictFiles As Object, i As Integer
        Set dictFiles = CreateObject("scripting.dictionary")
        Path = "C:\MIHAI\DOC\ASIG\DOSARE\"
        inPath = Path & "*.*"
        outPath = Path & "Output.pdf"
        'save all the filename first so we can delete later
        Dim sFile As String
        sFile = Dir$(inPath)
        Do Until Len(sFile) = 0
             dictFiles(Path & sFile) = 1
             sFile = Dir$
        Loop
        'remove Output.pdf
        Select Case dictFiles.Count
            Case Is > 1
                If dictFiles.Exists(outPath) Then
                     'delete only if there are other files
                    dictFiles.Remove outPath
                    Kill outPath
                End If
           Case Is = 1
               If dictFiles.Exists(outPath) Then
                   Exit Sub
               End If
           Case Is = 0
               Exit Sub
        End Select
        'convert to pdf
        Call ConvertJpgToPdfUsingMagick(inPath, outPath)
        'delete the initial files
        For i = 0 To dicFiles.Count - 1
             Kill dictFiles.Keys()(i)
        Next
    End Sub
    
    
    Sub ConvertJpgToPdfUsingMagick(ByVal inputImagePath As String, ByVal outputPdfPath As String)
        Dim command As String
        command = "C:\Program Files\ImageMagick-7.1.1-Q16-HDRI\magick.exe convert -resize 1240x1753 -extent 1240x1753 -gravity center -units _
        PixelsPerInch -density 150x150 """ & inputImagePath & """ """ & outputPdfPath & """"
        Shell command, vbHide
    End Sub
    Last edited by Aussiebear; 12-24-2024 at 05:51 PM.

Posting Permissions

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