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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| ' Convert2PDF.vbs script
' Part of PDFCreator
' License: GPL
' Homepage: http://www.pdfforge.org/products/pdfcreator
' Windows Scripting Host version: 5.1
' Version: 1.1.0.0
' Date: December, 24. 2007
' Author: Frank Heindِrfer
' Comments: This script convert a printable file in a pdf-file using
' the com interface of PDFCreator.
'***************************************************************************************
'Modified by Hackoo on 11/04/2014
' - Ajout de la fonction Parcourir_Dossier() pour la conversion par lot
' - Ajout de la fonction Explore(filename) pour explorer dans le dossier de la conversion
'***************************************************************************************
Option Explicit
Const maxTime = 30 ' in seconds
Const sleepTime = 250 ' in milliseconds
Dim objArgs, ifname, fso, PDFCreator, DefaultPrinter, ReadyState, _
i, c, AppTitle, Scriptname, ScriptBasename
Set fso = CreateObject("Scripting.FileSystemObject")
Scriptname = fso.GetFileName(Wscript.ScriptFullname)
ScriptBasename = fso.GetFileName(Wscript.ScriptFullname)
AppTitle = "PDFCreator - " & ScriptBaseName
If CDbl(Replace(WScript.Version,".",",")) < 5.1 then
MsgBox "You need the ""Windows Scripting Host version 5.1"" or greater!", vbCritical + vbSystemModal, AppTitle
Wscript.Quit
End if
Set PDFCreator = Wscript.CreateObject("PDFCreator.clsPDFCreator", "PDFCreator_")
PDFCreator.cStart "/NoProcessingAtStartup"
With PDFCreator
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveFormat") = 0 'La valeur 0 = PDF La valeur 1 = PNG
DefaultPrinter = .cDefaultprinter
.cDefaultprinter = "PDFCreator"
.cClearcache
.cPrinterStop = false
End With
For each ifname in FSO.GetFolder(Parcourir_Dossier()).Files
With PDFCreator
If Not fso.FileExists(ifname) Then
MsgBox "Il n'y a pas de fichier : " & ifname, vbExclamation + vbSystemModal, AppTitle
Exit For
End If
if Not .cIsPrintable(CStr(ifname)) Then
MsgBox "Conversion : " & ifname & vbcrlf & vbcrlf & _
"Une erreur s'est produite est: Le fichier n'est pas imprimable !", vbExclamation + vbSystemModal, AppTitle
Exit For
Wscript.Quit
End if
ReadyState = 0
.cOption("AutosaveDirectory") = fso.GetParentFolderName(ifname) & "\MyPDF" 'Le dossier pour sauvegarder les fichiers convertis en PDF
.cOption("AutosaveFilename") = fso.GetBaseName(ifname)
.cPrintfile cStr(ifname)
c = 0
Do While (ReadyState = 0) and (c < (maxTime * 1000 / sleepTime))
c = c + 1
Wscript.Sleep sleepTime
Loop
If ReadyState = 0 then
MsgBox "Conversion : " & ifname & vbcrlf & vbcrlf & _
"Une erreur s'est produite est : Le temps est écoulé !", vbExclamation + vbSystemModal, AppTitle
Exit For
End If
End With
Next
With PDFCreator
.cDefaultprinter = DefaultPrinter
.cClearcache
WScript.Sleep 200
.cClose
End With
'Msgbox PDFCreator.cOption("AutosaveDirectory")
Call Explore(PDFCreator.cOption("AutosaveDirectory"))
'--- PDFCreator events ---
'****************************************************************************************************
Public Sub PDFCreator_eReady()
ReadyState = 1
End Sub
'****************************************************************************************************
Public Sub PDFCreator_eError()
MsgBox "An error is occured!" & vbcrlf & vbcrlf & _
"Error [" & PDFCreator.cErrorDetail("Number") & "]: " & PDFcreator.cErrorDetail("Description"), vbCritical + vbSystemModal, AppTitle
Wscript.Quit
End Sub
'****************************************************************************************************
Function Parcourir_Dossier()
Dim objShell,objFolder
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0, "Veuillez choisir un dossier pour convertir ses fichiers en PDF ",1,"c:\Programs")
If objFolder Is Nothing Then
With PDFCreator
.cDefaultprinter = DefaultPrinter
.cClearcache
WScript.Sleep 200
.cClose
End With
Wscript.Quit
End If
Parcourir_Dossier = objFolder.self.path
end Function
'****************************************************************************************************
Function Explore(filename)
Dim ws
Set ws=CreateObject("wscript.Shell")
ws.run "Explorer /n,/select,"& filename &" "
End Function
'**************************************************************************************************** |
Partager