PDF In-Depth

IAC - How to merge every PDF in a given folder into one

May 22, 1998

Advertisement
Advertisement
 

This method takes all of the PDFs in the folder c:\acrobatdocstomerge and merges them together to form a file called complete.pdf.

This code sample is posted here for the general benefit of the PDF development community. Attribution and usage guidelines are as noted in the code source; please respect the wishes of the author when using this code.


Option Explicit ' Force variable declaration
' Author : Planet PDF
' E-Mail: info@debenu.com
' Date : 08 March 1998
' Description: JoinAllAcrobatDocsInDir
' This vb method uses IAC to join all PDF documents in a folder 
' to a predetermined filename
' This method / function should be extended to suit the requirements
' of an organisation
Public Const PDF_WILDCARD = "*.pdf"
Public Const PDF_DIRECTORY = "c:\acrobatdocstomerge\"
Public Const JOIN_FILENAME = "complete.pdf"
Sub JoinAllAcrobatDocsInDir()


    Dim AcroExchApp As Object, AcroExchPDDoc As Object, _
        AcroExchInsertPDDoc As Object
    Dim strFileName As String, strPath As String
    Dim iNumberOfPagesToInsert As Integer, _
        iLastPage As Integer
    Set AcroExchApp = CreateObject("AcroExch.App")
    Set AcroExchPDDoc = CreateObject("AcroExch.PDDoc")

' Show the Acrobat Exchange window
    AcroExchApp.Show

' Set the directory / folder to use
    strPath = PDF_DIRECTORY

' Get the first pdf file in the directory
    strFileName = Dir(strPath + PDF_WILDCARD, vbNormal)

' Open the first file in the directory
    AcroExchPDDoc.Open strPath + strFileName
    
' Get the name of the next file in the directory [if any]
    If strFileName <> "" Then
        strFileName = Dir
   
    ' Start the loop.
        Do While strFileName <> ""
    
    ' Get the total pages less one for the last page num [zero 
based]
            iLastPage = AcroExchPDDoc.GetNumPages - 1
            Set AcroExchInsertPDDoc = CreateObject("AcroExch.PDDoc")
        
        ' Open the file to insert
            AcroExchInsertPDDoc.Open strPath + strFileName

        ' Get the number of pages to insert
            iNumberOfPagesToInsert = AcroExchInsertPDDoc.GetNumPages

        ' Insert the pages
        AcroExchPDDoc.InsertPages iLastPage, AcroExchInsertPDDoc, 0, 
iNumberOfPagesToInsert, True
    
        ' Close the document
            AcroExchInsertPDDoc.Close
    
       ' Get the name of the next file in the directory
            strFileName = Dir
             Loop
        
    ' Save the entire document as the JOIN_FILENAME using SaveFull 
[0x0001 = &H1]
        AcroExchPDDoc.Save &H1, strPath + JOIN_FILENAME

End If

' Close the PDDoc
    AcroExchPDDoc.Close
        
' Close Acrobat Exchange
    AcroExchApp.Exit
End Sub

(ARTS PDF and Planet PDF have been since acquired by Debenu)

PDF In-Depth Free Product Trials Ubiquitous PDF

Ubiquitous PDF: DIY PDF magazines, courtesy of CNET and Magazinify

Thanks to Magazinify.com, it's possible to have web articles delivered right to your inbox in PDF form. If that weren't enough, the nice folks at CNET have been nice enough to publish a step-by-step guide about how to set this all up using just a little time and a free Magazinify account.

September 06, 2011
Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popluar Articles
Features

Collating PDFs using JavaScript

Despite the numerous benefits, there can be potential issues with the conversion of paper documents into electronic archives. When scanning paper pages into PDF, it's possible to end up with the odd- and even-numbered pages in separate PDF files. It can be very time-consuming to collate them manually, but there is an easier way. Sean Stewart explains.

Featured Product
Platinum Sponsor

Debenu - Unrivaled PDF Productivity | PDF Library, Acrobat Plug-Ins

Create & Edit PDF - Nitro PDF Software

Silver Sponsors

LockLizard DRM PDF Security Quick PDF Library: The Unrivaled PDF Developer Toolkit