1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''
'===================================================
' ADA - 19/06/2008 - OCX_PDFcreator
' OCX permettant de fusionner et sauvegarder des
' documents dans un répertoire avec un nom
' donné, avec l'imprimante logicielle PDFcreator
'
' /!\ ajouter la référence PDFCreator.exe au projet
'===================================================
''''''''''''''''''''''''''''''''''''''''''''''''''''
Private WithEvents PDFCreator1 As PDFCreator.clsPDFCreator '/ composant principal
Private pErr As clsPDFCreatorError '/ classe de gestion d'erreur
Private opt As clsPDFCreatorOptions '/ classe de paramétrage
Dim DefaultPrinter As String
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'Initialise PDFcreator
Public Sub PDFcreator_init()
Set PDFCreator1 = New clsPDFCreator
Set pErr = New clsPDFCreatorError
With PDFCreator1
.cVisible = False
If .cStart("/NoProcessingAtStartup") = False Then
If .cStart("/NoProcessingAtStartup", True) = False Then
Exit Sub
End If
.cVisible = False
End If
'On affecte les options par défaut au composant principal PDFCreator1
Set opt = .cOptions
DefaultPrinter = PDFCreator1.cDefaultPrinter ' Sauvegarde de l'imprimante par défaut
.cDefaultPrinter = "PDFCreator" 'définition de PDFcreator comme imprimante par défaut
.cClearCache
End With
End Sub
'Ajoute un fichier dans la file d'attente de l'imprimante PDFcreator
Public Sub PDFcreator_addFile(ByVal fileToAdd As String)
With PDFCreator1
.cPrintFile (fileToAdd)
End With
End Sub
'Fusionne les fichiers présents dans la file d'attente
'Sauvegarde la fusion au format PDF dans Rep/fileNameFusion
Public Sub PDFcreator_combineAndPrint(ByVal Rep As String, ByVal fileNameFusion As String)
With opt
.AutosaveDirectory = Rep ' Chemin du fichier
.UseAutosave = 1
.UseAutosaveDirectory = 1
.AutosaveFormat = 0 ' PDF
.AutosaveFilename = fileNameFusion ' Nom du fichier
End With
'/ on affecte ensuite les nouvelles options au composant principal PDFCreator1
Set PDFCreator1.cOptions = opt
With PDFCreator1
.cCombineAll
.cPrinterStop = False
End With
While PDFCreator1.cCountOfPrintjobs > 0
Sleep 1000
Wend
PDFCreator1.cPrinterStop = True
End Sub
'Ferme PDFcreator, repositionne l'imprimante par défaut
Public Sub PDFcreator_close()
While PDFCreator1.cPrinterStop = False
DoEvents
Wend
With PDFCreator1
.cClearCache
.cDefaultPrinter = DefaultPrinter ' Réaffectation de l'imprimante par défaut
.cClose
End With
Set pErr = Nothing
Set opt = Nothing
Set PDFCreator1 = Nothing
End Sub
Private Sub Command1_Click()
Dim err As Integer
PDFcreator_init
PDFcreator_addFile ("C:\Documents and Settings\Ordi\Bureau\1.txt")
PDFcreator_addFile ("C:\Documents and Settings\Ordi\Bureau\2.txt")
PDFcreator_combineAndPrint "C:\Documents and Settings\Ordi\Bureau", "testfusion.pdf"
PDFcreator_close
End Sub |
Partager