Planet PDF Forum Archive

Planet PDF ForumWowsers! This is page is old, head to the LIVE Planet PDF Forum. It features more than 10 conferences, covering everything from beginner to in-depth developer and pre-press discussions. If you wish to continue... one & two archive covers 1999-2011 (160,000 pages).

New Forum | Previous | Next | (P-PDF) Developers

Topic: Help required to Merge many pdf files using Vb
Conf: (P-PDF) Developers, Msg: 131997
From: sriky
Date: 4/29/2005 02:27 PM

I got this code from this site only, but it doesn't seem to work. this is the first time I am doing anything with Adobe. i am not sure why it is not working. Help is appreciated very much.

I am trying merge all the pdf files in a folder to one pdf file. I have adobe acrobat 5 (not the reader). Do I need anything else installed or any other options checked. Thanks.

Code Start
Sub JoinAllAcrobatDocsInDir()
Const PDF_WILDCARD = "*.pdf"
Const PDF_DIRECTORY = "C:\work\pdf\"
Const JOIN_FILENAME = "C:\work\pdf\complete.pdf"

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

' Set the directory / folder to use

' 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

' Get the name of the next file in the directory
strFileName = Dir

' Save the entire document as the JOIN_FILENAME using SaveFull
[0x0001 = &H1]
AcroExchPDDoc.Save &H1, strPath + JOIN_FILENAME

End If

' Close the PDDoc

' Close Acrobat Exchange
End Sub

code end

PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link...

Download free demo

Debenu PDF Tools Pro

It's simple to use and will let you preview and edit PDF files, it's a Windows application that makes...

Download free demo

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
Platinum Sponsor

Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.


Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.