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 with Merging PDFs in VB
Conf: (P-PDF) Developers, Msg: 129479
From: ChristianRusso
Date: 3/16/2005 07:09 AM

I'm having some trouble trying to merge PDF's. I'm new to VB, but I was able to find some code from Planet PDF that does just what I am looking for. The only problem is that when I run it, it goes through each of the pdf's in my folder, but the output file only includes the first pdf in the folder. Is it something I'm doing wrong? This is the code I'm using:

Sub Form_Click()

Const PDF_WILDCARD = "*.pdf"
Const PDF_DIRECTORY = "C:\Documents and Settings\Christian\My Documents\2.1 documentation\"
Const JOIN_FILENAME = "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

No one else seems to have a problem with this (at least the problem I'm having), so I'm not sure what I'm doing wrong. Again, I'm very new to VB, so it could easily be something stupid that I'm doing. Thanks in advance for any help.

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.