_screen.AddProperty('document(3)','') && Replace 3 with the number of documents _screen.document(1)='mypath\mydoc1.pdf') && Make sure that you specify the whole path _screen.document(2)='mypath\mydoc2.pdf') _screen.document(2)='mypath2\mydoc3.pdf') Do mergepdf with 'outputpath\mergedfiles.pdf' && Complete filename including path
Function Mergepdf Lparameters pcOutput && Name of PDF to create #DEFINE PDSaveLinearized 4 && Save the file in a linearized #define CrLf = CHR(13) + CHR(10) If !Vartype(_screen.document)='C' or Empty(_screen.document) or Pcount()<1 or !Vartype(pcOutput)='C' or Empty(pcOutput) Return EndIf loAcroApp = Null loAVDoc = Null * Kill Acrobat if it's loaded into the memory KillAcrobat() loAcroApp = CREATEOBJECT("AcroExch.App") loAVDoc = CREATEOBJECT("AcroExch.AVDoc") lcFirstPdfFile = FULLPATH(_screen.document[1]) lcFirstPath=JustPath(lcFirstPdfFile) lcNewPdfFile = ForceExt(FULLPATH(pcOutput),'pdf') lcNewPath=JustPath(lcNewPdfFile) lcTempPdfFile = lcNewPdfFile COPY FILE (ForcePath(lcFirstPdfFile,JustPath(lcFirstPdfFile))) TO (lcNewPdfFile) loAVDoc.Open(lcNewPdfFile, "PDF") loPDDoc = loAVDoc.GetPDDoc() lnMaxPage1 = loPDDoc.GetNumPages() lnMaxPage = loPDDoc.GetNumPages() loPDDoc2 = CREATEOBJECT("AcroExch.PDDoc") FOR lnInd=2 TO ALEN(_screen.document) llDelete=.f. lcFileName = _screen.document(lnInd) &&FULLPATH(_screen.document[lnInd]) lnMaxPage = loPDDoc.GetNumPages() loPDDoc2.Open(lcFileName) lnMaxPage2 = loPDDoc2.GetNumPages() If llDelete Erase (ForcePath(_screen.document(lnInd),lcFirstPath)) EndIf loPDDoc.InsertPages(lnMaxPage-1, loPDDoc2, 0, lnMaxPage2, .T.) loPDDoc2.Close() ENDFOR loPDDoc.Save(PDSaveLinearized, lcTempPdfFile) * Close and release all objects loPDDoc.Close() loPDDoc = Null loAVDoc.Close(.T.) loAVDoc = Null loAcroApp.Exit() * Kill Acrobat if it still been loaded into the memory KillAcrobat() RETURN *------------------------------------------------------- FUNCTION KillAcrobat() loCIMV2 = GetObject("winmgmts://localhost/root/cimv2") loProcesses = loCIMV2.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'Acrobat.exe'") IF loProcesses.Count > 0 For Each objProcess in loProcesses objProcess.Terminate(0) NEXT ENDIF RETURN ENDFUNCNB! Adobe Acrobat Professional is required to use this function