ATOUTFOX
COMMUNAUTÉ FRANCOPHONE DES PROFESSIONNELS FOXPRO
Visual FoxPro : le développement durable

Comment combiner plusieurs fichiers PDF ensembles   



L'auteur

Mike Gagnon
Canada Canada
Membre Simple
# 0000000025
enregistré le 14/10/2004

Gagnon Mike
Pointe Cla H9R 3K8
de la société Carver Technologies Inc.
Fiche personnelle


Note des membres
20/20
1 vote


Contributions > 09 - Automation > Adobe Acrobat

Comment combiner plusieurs fichiers PDF ensembles
# 0000000232
ajouté le 18/08/2005 21:02:03 et modifié le 13/03/2008
consulté 12221 fois
Niveau initié

Version(s) Foxpro :
VFP 9.0
VFP 8.0
VFP 7.0
VFP 6.0
VFP 5.0

Description

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

Commentaires
le 13/03/2008, FoxInCloud (Th. Nivelet) a écrit :
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


www.atoutfox.org - Site de la Communauté Francophone des Professionnels FoxPro - v3.4.0 - © 2004-2024.
Cette page est générée par un composant COM+ développé en Visual FoxPro 9.0-SP2-HF3