none
Need help in consolidating and print setting of all PDF saved in a particular drive . RRS feed

  • Question

  • Hi All,

    Many Thanks in advance for looking this thread/problems.

    I need to consolidate all the PDF's saved in any drive also need to change the print or display setting:

    1. I need the page setting be like:

    Center Footer Text <<Page 1 of n>>  
    Margins 0.5 0.22
      0.2 0.2
    Size 5  
    Maginification  100%  

    2. By Googling I am in position to consolidate all PDF's by putting the below code in VBA code window:

    Sub PDFs_Combine_LateBound()
    Dim PdfDst As Object, PdfSrc As Object
    Dim sPdfComb As String, sPdf As String
    Dim b As Byte

    Mainz.Activate
    Dim ipath As Variant
    ipath = Range("E5").Value




        Rem Set Combined Pdf filename - save the combined pdf in a new file in order to preserve original pdfs
        sPdfComb = ipath & "\" & "Pdf Combined" & Format(Now, " mmdd_hhmm ") & ".pdf"   'change as required

        Rem Open Destination Pdf
        b = 1
        sPdf = ipath & "\" & "Lon_Packpdf" & b & ".pdf"
        Set PdfDst = CreateObject("AcroExch.PDDoc")
        If Not (PdfDst.Open(sPdf)) Then
            MsgBox "Error opening destination pdf:" & vbCrLf _
                & vbCrLf & "[" & sPdf & "]" & vbCrLf _
                & vbCrLf & vbTab & "Procees will be cancelled!", vbCritical
            Exit Sub
        End If

        Do

            Rem Set & Validate Source filename
            b = b + 1
            sPdf = ipath & "\" & "Lon_Packpdf" & b & ".pdf"
            If Dir(sPdf, vbArchive) = vbNullString Then Exit Do

            Rem Open Source filename
            Set PdfSrc = CreateObject("AcroExch.PDDoc")
            If Not (PdfSrc.Open(sPdf)) Then
                MsgBox "Error opening source pdf:" & vbCrLf _
                    & vbCrLf & "[" & sPdf & "]" & vbCrLf _
                    & vbCrLf & vbTab & "Procees will be cancelled!", vbCritical
                GoTo Exit_Sub
            End If

            With PdfDst

                Rem Insert Source filename pages
                If Not (.InsertPages(-1 + .GetNumPages, PdfSrc, 0, PdfSrc.GetNumPages, 0)) Then
                    MsgBox "Error inserting source pdf:" & vbCrLf _
                        & vbCrLf & "[" & sPdf & "]" & vbCrLf _
                        & vbCrLf & vbTab & "Procees will be cancelled!", vbCritical
                    GoTo Exit_Sub
                End If

                Rem Save Combined Pdf
                If Not (.Save(1, sPdfComb)) Then
                    MsgBox "Error saving combined pdf:" & vbCrLf _
                        & vbCrLf & "[" & sPdfComb & "]" & vbCrLf _
                        & vbCrLf & vbTab & "Procees will be cancelled!", vbCritical
                    GoTo Exit_Sub
                End If

                PdfSrc.Close
                Set PdfSrc = Nothing

            End With

    '        sPdf = Dir(sPdf, vbArchive)
    '    Loop While sPdf <> vbNullString
        Loop

        MsgBox "Combined successfully!", vbExclamation

    Exit_Sub:
        PdfDst.Close

       End Sub

    Please help.

    Regards,

    Mohammad Irshad Alam

    Sunday, October 20, 2019 2:47 PM