tcDirectory=Getdir() mergefiles(tcDirectory) Function mergefiles Lparameters tcDirectory, tcPDFCombinedFile Local lcFileSkeleton, ; lnPDFCount, ; lcCombinedFile, ; lcLastFile, ; lcResult Do Case Case Vartype(tcDirectory) # "C" Return "First PDF file parameter not passed as a character" Case Vartype(tcPDFCombinedFile) # "C" tcPDFCombinedFile = Addbs(Fullpath(Curdir())) + "DirectoryCombined.pdf" Otherwise Endcase If Directory(tcDirectory) tcDirectory = Addbs(tcDirectory) Else Return tcDirectory + " does not exist" Endif Dimension laPDFFiles[1] lcFileSkeleton = Addbs(Alltrim(tcDirectory)) + "*.pdf" lnPDFCount = Adir(laPDFFiles, lcFileSkeleton) Do Case Case lnPDFCount > 1 lcLastFile = tcDirectory + laPDFFiles[1, 1] For lnCount = 2 To lnPDFCount If lnCount = lnPDFCount lcCombinedFile = tcPDFCombinedFile Else lcCombinedFile = Forceext(Addbs(Sys(2023)) + "Temp" + Alltrim(Str(lnCount)), "PDF") Endif lcResult = PdfMerger(lcLastFile, tcDirectory + laPDFFiles[lnCount, 1], lcCombinedFile) lcLastFile = lcCombinedFile Endfor Case lnPDFCount = 1 Copy File laPDFFiles[1, 1] To tcPDFCombinedFile Otherwise Endcase Return Endfunc Function PdfMerger Lparameters tcPDFOne, tcPDFTwo, tcPDFCombined, tlShowAcrobat #Define ccSAVEFULL 0x0001 Local loAcrobatExchApp, ; loAcrobatExchPDFOne, ; loAcrobatExchPDFTwo, ; lnLastPage, ; lnNumberOfPagesToInsert, ; lcOldSafety Do Case Case Vartype(tcPDFOne) # "C" Return "First PDF file parameter not passed as a character" Case Vartype(tcPDFTwo) # "C" Return "Second PDF file parameter not passed as a character" Otherwise Endcase tcPDFOne = Forceext(tcPDFOne, "PDF") tcPDFTwo = Forceext(tcPDFTwo, "PDF") If File(tcPDFOne) If File(tcPDFTwo) Else Return tcPDFTwo + " does not exist" Endif Else Return tcPDFOne + " does not exist" Endif If Vartype(tcPDFCombined) # "C" tcPDFCombined = Addbs(Justpath(tcPDFOne)) + "combined.pdf" Endif tcPDFCombined = Forceext(tcPDFCombined, "PDF") Wait Window "Combining " + Justfname(tcPDFOne) + Chr(13) + ; "with " + Justfname(tcPDFTwo) + Chr(13) + ; "into " + tcPDFCombined + Chr(13) + ; "please wait..." Nowait Noclear lcOldSafety = Set("Safety") Set Safety Off Erase tcPDFCombined Set Safety &lcOldSafety loAcrobatExchApp = Createobject("AcroExch.App") loAcrobatExchPDFOne = Createobject("AcroExch.PDDoc") loAcrobatExchPDFTwo = Createobject("AcroExch.PDDoc") If tlShowAcrobat loAcrobatExchApp.Show() Endif loAcrobatExchPDFOne.Open(tcPDFOne) lnLastPage = loAcrobatExchPDFOne.GetNumPages() - 1 loAcrobatExchPDFTwo.Open(tcPDFTwo) lnNumberOfPagesToInsert = loAcrobatExchPDFTwo.GetNumPages() loAcrobatExchPDFOne.InsertPages(lnLastPage, loAcrobatExchPDFTwo, 0, lnNumberOfPagesToInsert, .T.) loAcrobatExchPDFTwo.Close() loAcrobatExchPDFOne.Save(ccSAVEFULL, tcPDFCombined) loAcrobatExchPDFOne.Close() loAcrobatExchApp.Exit() Release loAcrobatExchPDFTwo Release loAcrobatExchPDFOne Release loAcrobatExchApp Wait Clear Return Space(0) Endproc Endfunc |
Bonjour Mike,
Bravo pour cette contrib ... je l'ai trouvée en googlant 'AcroExch.PDDoc', 3è position mondiale !! Atoutfox always best !!
Dis-moi,
Sais-tu comment extraire des pages d'un pdf ?
Je n'ai trouvé aucune méthode ressemblante ...
Bien sûr je peux deleter les autres pages et enregistrer sous ...
Mais si c'est déjà empaqueté ce serait mieux.
@ +
Th