>It supposed to merge PDF files...but I can't get the damn thing to work in VFP...seems like it should be pretty straight forward... but my 'wish-it-was-a-conversion', even though it doesn't seem error until I try the last 'save' in it...doesn't seem to be doing anything either. Anyone feel up to it?
>
>
>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
SET LURK OFF
#DEFINE PDF_WILDCARD "*.pdf"
#DEFINE PDF_DIRECTORY "c:\acrobatdocstomerge\"
#DEFINE JOIN_FILENAME "complete.pdf"
#DEFINE TRUE -1
#DEFINE NumberOfPagesToInsert AcroExchInsertPDDoc.GetNumPages()
FUNCTION JoinAllAcrobatDocsInDir()
AcroExchApp = CreateObject("AcroExch.App")
AcroExchPDDoc = CreateObject("AcroExch.PDDoc")
AcroExchInsertPDDoc = CreateObject("AcroExch.PDDoc")
AcroExchApp.Show
cPath = PDF_DIRECTORY
iTotalPdfFiles = ADIR( aPdfFiles, cPath + PDF_WILDCARD )
IF iTotalPdfFiles < 2 THEN
RETURN .F.
ENDIF
AcroExchPDDoc.Open( cPath + aPdfFiles[ iPdfFile, 1 ] )
iLastPage = AcroExchPDDoc.GetNumPages() - 1
FOR iPdfFile = 2 TO iTotalPdfFiles
AcroExchInsertPDDoc.Open( cPath + aPdfFiles[ iPdfFile, 1 ] )
AcroExchPDDoc.InsertPages( iLastPage, AcroExchInsertPDDoc ;
, 0, NumberOfPagesToInsert ;
, TRUE )
AcroExchInsertPDDoc.Close()
NEXT iPdfFile
AcroExchPDDoc.Save( 0x0001, strPath + JOIN_FILENAME )
AcroExchPDDoc.Close
AcroExchApp.Exit
RETURN .T.
ENDFUNC
The code above is completly UNTESTED !!!
The value of TRUE is a guess.
The PDF_DIRECTORY and JOIN_FILENAME should be parameters passed to the function.
All of the variables created within the function should be LOCAL.
Etc.
SET LURK ON
censored.