IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Batch, PowerShell ou Script - Convertion silencieuse vers PDF


Sujet :

Scripts/Batch

  1. #1
    Membre habitué
    Inscrit en
    Octobre 2006
    Messages
    316
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 316
    Points : 146
    Points
    146
    Par défaut Batch, PowerShell ou Script - Convertion silencieuse vers PDF
    Bonjour,

    je cherche un batch, script ou powershell qui 1 fois par jour scannerai un répertoire et convertirai chaque fichier trouvé en PDF.
    Les fichiers en question sont des TXT et/ou fichier sans extension mais ce sont des fichiers de type texte.
    Si le fichier existe déjà en version PDF, il est alors écrasé.

    Difficulté supplémentaire, la conversion doit être totalement silencieuse.

    Merci pour votre aide.

  2. #2
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 836
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 836
    Points : 9 217
    Points
    9 217
    Par défaut

    Un coup d’œil ici ==> Script avec PDF creator

  3. #3
    Membre habitué
    Inscrit en
    Octobre 2006
    Messages
    316
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 316
    Points : 146
    Points
    146
    Par défaut
    Bonjour,

    Merci pour cette réponse, je vais regarder ca..

  4. #4
    Membre habitué
    Inscrit en
    Octobre 2006
    Messages
    316
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 316
    Points : 146
    Points
    146
    Par défaut
    Salut,

    Je trouve pas mal d'exemple de script mais lorsque j'en execute un, j'ai un message d'erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    WScrip.CreateObject: Could not locate automation class named "PDFCreator.clsPDFCreator"
    .

    Je suis sûre que vous avez déjà rencontré ca..
    Mille mercis !

  5. #5
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 836
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 836
    Points : 9 217
    Points
    9 217
    Par défaut
    Citation Envoyé par guilld Voir le message
    Salut,

    Je trouve pas mal d'exemple de script mais lorsque j'en execute un, j'ai un message d'erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    WScrip.CreateObject: Could not locate automation class named "PDFCreator.clsPDFCreator"
    .

    Je suis sûre que vous avez déjà rencontré ca..
    Mille mercis !
    Avez-vous installé PDFCreator ?

  6. #6
    Membre habitué
    Inscrit en
    Octobre 2006
    Messages
    316
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 316
    Points : 146
    Points
    146
    Par défaut
    Oui et il fonctionne trés bien.

  7. #7
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 836
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 836
    Points : 9 217
    Points
    9 217
    Par défaut
    Citation Envoyé par guilld Voir le message
    Oui et il fonctionne trés bien.
    Dans ce cas partager le code source du script qui ne marche pas chez vous ?

  8. #8
    Membre habitué
    Inscrit en
    Octobre 2006
    Messages
    316
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 316
    Points : 146
    Points
    146
    Par défaut
    J'ai pris un exemple afin de comprendre le fonctionnement.
    Ce script est un original, je n'ai rien modifié.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    '****************************************************************************************************
    Et voici ce que j'obtiens :

    Nom : Capture.PNG
Affichages : 1934
Taille : 2,4 Ko

  9. #9
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 836
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 836
    Points : 9 217
    Points
    9 217
    Par défaut
    Citation Envoyé par guilld Voir le message
    J'ai pris un exemple afin de comprendre le fonctionnement.
    Ce script est un original, je n'ai rien modifié.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    '****************************************************************************************************
    Et voici ce que j'obtiens :

    Nom : Capture.PNG
Affichages : 1934
Taille : 2,4 Ko
    Effectivement, j'ai eu la même erreur que vous, alors, qu'il marche à merveille avant
    Je crois ils ont changé quelque chose au niveau du scripting et de la création des objets dans la nouvelle version, je vais chercher, si, on peut trouver une solution pour résoudre ce petit problème
    Voici la version originale et n'est pas inclut dans cette nouvelle instalation

  10. #10
    Membre habitué
    Inscrit en
    Octobre 2006
    Messages
    316
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 316
    Points : 146
    Points
    146
    Par défaut
    Merci. Je regarde cette version originale pour voir ce que je peux en tirer.

  11. #11
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 836
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 836
    Points : 9 217
    Points
    9 217
    Par défaut
    Citation Envoyé par guilld Voir le message
    Merci. Je regarde cette version originale pour voir ce que je peux en tirer.
    Même cette ancienne version originale que je l'ai testé ne marche plus, mais je crois, j'ai eu une piste, et je vais le refaire avec cette nouvelle version, juste il faut être un peu patient

  12. #12
    Membre habitué
    Inscrit en
    Octobre 2006
    Messages
    316
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 316
    Points : 146
    Points
    146
    Par défaut
    Pas de probleme pour la patience.. je vais prendre un café

  13. #13
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 836
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 836
    Points : 9 217
    Points
    9 217
    Par défaut
    la pause est terminé
    J'ai fait un test avec ce nouveau vbscript : NewConvert2PDF.vbs

    Tout d'abord j'ai désinstallé le logiciel accompagnant PDF Architect
    puis , j'ai crée un dossier de test nommé C:\TestPDF
    J'ai mis un fichier fictif pour le test nommé C:\TestPDF\Test.txt
    Fais un test par double clic sur ce script puis revient et dis-moi le résultat.
    Dans la prochaine version, je vais le modifier afin de l'utiliser en ligne de commande et ça va être plus intéressant pour un traitement par lot

    Code VB : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Dim strExt, intStatus, strDestFileName, strInputFileName, strReason 
    Const ForReading = 1 
    Const ForWriting = 2
    Const ForAppending = 8
     
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("Shell.Application")
    Set PDFCreatorQueue = CreateObject("PDFCreator.JobQueue")
    Set PDFCreator = CreateObject("PDFCreator.PDFCreatorObj")
     
    strInputFileName = "C:\TestPDF\Test.txt" 
    strDestFileName = "C:\TestPDF\Test.pdf"
     
    PDFProcess 
     
    ' ** Sub Routine to render file as PDF
    Sub PDFProcess  
        Dim objFolder, job, intStatPDFCreator, intPageCount
     
        intPageCount = 1  
     
        Loggit "PDF Destination Name: " & strDestFile 
        Loggit "Initializing PDFCreator queue..."
        intStatPDFCreator = PDFCreatorQueue.Initialize()
        Loggit "PDFCreator Object Status: " & intStatPDFCreator 
     
        If intStatPDFCreator = 0 Then 
                If Not objFSO.FileExists(strInputFileName) Then
                    Loggit "PDFCreator: Can't find the file: " & strInputFileName
                Else 
                    Loggit "Printing Page: " & strInputFileName 
     
                    PDFCreator.PrintFile strInputFileName
     
                    WScript.Sleep 1000
                    Loggit "Currently there are " & PDFCreatorQueue.Count & " job(s) in the queue" 
                End If
     
            Loggit "Waiting for the job to arrive at the queue..."
            if Not(PDFCreatorQueue.WaitForJobs(intPageCount, 100)) Then 
                strReason = "The print job did not reach the queue within " & 10 & " seconds" 
                Loggit strReason 
                intStatus = 0
            Else
                Loggit "Currently there are " & PDFCreatorQueue.Count & " job(s) in the queue" 
                Loggit "Getting job instance and merging"
     
                PDFCreatorQueue.MergeAllJobs
     
                while(PDFCreatorQueue.Count > 0)
                    Set job = PDFCreatorQueue.NextJob
                        Loggit "Staging PDF File: " & strDestFileName 
                    job.ConvertTo(strDestFileName)
                        WScript.sleep 5000
     
                    If Not(job.IsFinished Or job.IsSuccessful) Then
                        strReason = "Could not convert the file: " & strDestFileName
                            Loggit strReason 
                        intStatus = 0
                    Else
                        Loggit "Job finished successfully" 
                    End If 
                Wend 
            End If 
                Loggit "Releasing the object"
            PDFCreatorQueue.ReleaseCom()
        Else
            strReason =  "Failed to create PDFCreator COM instance."
                Loggit strReason 
            intStatus = 0
        End If
    End Sub 
     
    ' ** Sub Routine for Logging to Text File
    Sub Loggit(msg) 
        Dim stream 
        Set stream = objFSO.OpenTextFile("C:\TestPDF\test.log" , 8, True)
            stream.writeline Date & " " & Time & ": " & msg
            WScript.Echo Date & " " & Time & ": " & msg
            stream.close
    End Sub

  14. #14
    Membre habitué
    Inscrit en
    Octobre 2006
    Messages
    316
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 316
    Points : 146
    Points
    146
    Par défaut
    Cool !! ca fonctionne !
    Maintenant reste le traitement par lot (en mode silencieux)

    Merci du coup de main

  15. #15
    Membre habitué
    Inscrit en
    Octobre 2006
    Messages
    316
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 316
    Points : 146
    Points
    146
    Par défaut
    Je repasse demain pour voir s'il y a de l'avancement..

  16. #16
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 836
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 836
    Points : 9 217
    Points
    9 217
    Par défaut

    Voici la sortie de la mise à jour de ce script : Convert2PDF.vbs

    Avec ce nouveau script, vous pouvez glisser et déposer votre fichier à convertir vers le format PDF
    Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    Option Explicit
    Dim strExt,intStatus,strDestFileName,objShell,PDFCreatorQueue,Scriptname,Converted_Folder,curDir
    Dim fso,strInputFileName,strReason,objArgs,AppTitle,PDFCreator,ScriptBasename
    Const ForReading = 1 
    Const ForWriting = 2
    Const ForAppending = 8
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("Shell.Application")
    Set PDFCreatorQueue = CreateObject("PDFCreator.JobQueue")
    Set PDFCreator = CreateObject("PDFCreator.PDFCreatorObj")
    Scriptname = fso.GetFileName(Wscript.ScriptFullname)
    ScriptBasename = fso.GetFileName(Wscript.ScriptFullname)
     
    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 objArgs = WScript.Arguments
     
    If objArgs.Count = 0 Then
     AppTitle = "PDFCreator updated by Hackoo - 18/10/2016 - " & ScriptBaseName
     MsgBox "Syntax : " & vbtab & Scriptname & " <Filename>" & vbtab & vbCrLf & vbCrLf &_
    "[ Or use ""Drag and Drop"" ]" & vbCrLf &_
    "[ Ou bien vous pouvez utiliser ce script par glisser et déposer le fichier à convertir ]",_
     vbExclamation + vbSystemModal, AppTitle
     WScript.Quit
    End If
     
    Call forceCScriptExecution()
     
    curDir = fso.GetParentFolderName(WScript.ScriptFullName)
    Converted_Folder = curDir &"\PDF-Conversion"
    If Not FSO.FolderExists(Converted_Folder) Then
        FSO.CreateFolder(Converted_Folder)
    End If
     
    strInputFileName = objArgs(0) 
    If (objArgs.Count > 1) Then
        strDestFileName = objArgs(1)
        strDestFileName = curDir & "\PDF-Conversion\" & GetName(strInputFileName) & ".pdf"
    Else
        strDestFileName = curDir & "\PDF-Conversion\" & GetName(strInputFileName) & ".pdf"
    End If
     
    Call PDFProcess()
    '**************************************************************
    '            Sub Routine to render file as PDF
    '**************************************************************
    Sub PDFProcess  
        Dim objFolder, job, intStatPDFCreator, intPageCount
        intPageCount = 1  
        Loggit "PDF Destination Name: " & strDestFileName 
        Loggit "Initializing PDFCreator queue..."
        intStatPDFCreator = PDFCreatorQueue.Initialize()
        Loggit "PDFCreator Object Status: " & intStatPDFCreator 
     
        If intStatPDFCreator = 0 Then 
                If Not fso.FileExists(strInputFileName) Then
                    Loggit "PDFCreator: Can't find the file: " & strInputFileName
                Else 
                    Loggit "Printing Page: " & strInputFileName 
                    PDFCreator.PrintFile strInputFileName
                    WScript.Sleep 1000
                    Loggit "Currently there are " & PDFCreatorQueue.Count & " job(s) in the queue" 
                End If
            Loggit "Waiting for the job to arrive at the queue..."
            if Not(PDFCreatorQueue.WaitForJobs(intPageCount, 100)) Then 
                strReason = "The print job did not reach the queue within " & 10 & " seconds" 
                Loggit strReason 
                intStatus = 0
            Else
                Loggit "Currently there are " & PDFCreatorQueue.Count & " job(s) in the queue" 
                Loggit "Getting job instance and merging"
                PDFCreatorQueue.MergeAllJobs
                while(PDFCreatorQueue.Count > 0)
                    Set job = PDFCreatorQueue.NextJob
                        Loggit "Staging PDF File: " & strDestFileName 
                    job.ConvertTo(strDestFileName)
                        WScript.sleep 5000
                    If Not(job.IsFinished Or job.IsSuccessful) Then
                        strReason = "Could not convert the file: " & strDestFileName
                            Loggit strReason 
                        intStatus = 0
                    Else
                        Loggit "Job finished successfully" 
                    End If 
                Wend 
            End If 
                Loggit "Releasing the object" & vbCrLF & String(150,"*")
            PDFCreatorQueue.ReleaseCom()
        Else
            strReason =  "Failed to create PDFCreator COM instance."
                Loggit strReason 
            intStatus = 0
        End If
    End Sub 
    '**************************************************************
    '         Sub Routine for Logging to Text File
    '**************************************************************
    Sub Loggit(msg) 
        Dim stream 
        Set stream = fso.OpenTextFile(Converted_Folder & "\" & scriptbasename &".log" , 8, True)
            stream.writeline Date & " " & Time & ": " & msg
            WScript.Echo Date & " " & Time & ": " & msg
            stream.close
    End Sub 
    '**************************************************************
    Function GetName(Path)
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    GetName = fso.GetBaseName(path)
    End Function
    '**************************************************************
    Sub forceCScriptExecution
        Dim Arg, Str
        If Not LCase( Right( WScript.FullName, 12 ) ) = "\cscript.exe" Then
            For Each Arg In WScript.Arguments
                If InStr( Arg, " " ) Then Arg = """" & Arg & """"
                Str = Str & " " & Arg
            Next
            CreateObject( "WScript.Shell" ).Run _
                "cscript //nologo """ & _
                WScript.ScriptFullName & _
                """ " & Str
            WScript.Quit
        End If
    End Sub
    '*************************************************************
    Si vous souhaitiez convertir plusieurs fichiers (*.txt) contenus dans un dossier à la fois :
    Juste, glisser et déposer le dossier sur ce batch :
    Folder_Convert2PDF.bat
    Code BAT : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    @ECHO OFF
    Title Conversion des fichiers de type "*.txt" vers "*.pdf" by Hackoo 2016
    Mode con cols=75 lines=15
    color 0A 
    IF [%1] EQU [] Goto:Error
    CD /D "%~1"
    2>nul cd "%~1" && Goto:Conversion || Goto:Error
    echo.
    :Conversion
    FOR %%a IN (*.txt) DO (
        echo      Conversion du fichier "%%a" vers "%%~na.pdf" ... & echo.
        Cscript /NoLogo %~dp0Convert2PDF.vbs "%%a" & Cls & echo.
    )
    Exit
     
    :Error
    Color 0c
    echo.
    ECHO    Il faut glisser et deposer un dossier sur ce programme batch 
    Timeout /T 6 /NoBreak >nul
    Exit



  17. #17
    Membre habitué
    Inscrit en
    Octobre 2006
    Messages
    316
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 316
    Points : 146
    Points
    146
    Par défaut


    J'aimerai bien être aussi doué avec les scripts !!!!

    Ca semble parfait.. je termine un autre sujet et je teste ca..
    Je reviens vers vous avant la fin de la semaine...

    Merci pour votre aide !

  18. #18
    Membre habitué
    Inscrit en
    Octobre 2006
    Messages
    316
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 316
    Points : 146
    Points
    146
    Par défaut
    Bon, j'ai pas eu la patience d'attendre, je viens de tester.. et ca marche nickel ! D'enfer même !

    Le seul truc est que ce batch doit être programmé la nuit (ca je sais faire ), donc personne ne sera là pour glisser le dossier à convertir..
    Le petit truc à modifier serait d'avoir un répertoire source fixe (à convertir) et un répertoire de destination fixe (pour acceuillir les PDF).

    Encore une fois, excellent boulot !

    On y est presque !

  19. #19
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 836
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 836
    Points : 9 217
    Points
    9 217
    Par défaut
    Citation Envoyé par guilld Voir le message
    Bon, j'ai pas eu la patience d'attendre, je viens de tester.. et ca marche nickel ! D'enfer même !

    Le seul truc est que ce batch doit être programmé la nuit (ca je sais faire ), donc personne ne sera là pour glisser le dossier à convertir..
    Le petit truc à modifier serait d'avoir un répertoire source fixe (à convertir) et un répertoire de destination fixe (pour acceuillir les PDF).

    Encore une fois, excellent boulot !

    On y est presque !
    Ok très bien
    Tu m’annonces bien une très bonne nouvelle que ce script marche 5/5 chez toi
    Juste, donner moi les chemins absolus de tes répertoires source et destination pour modifier le batch
    @+

  20. #20
    Membre habitué
    Inscrit en
    Octobre 2006
    Messages
    316
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 316
    Points : 146
    Points
    146
    Par défaut
    alors..

    La source : C:\Users\guilld\Desktop\VME_TRANSFERT
    La destination : C:\Users\Public\Documents\Pdf

    Merci.

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. Convertion RTF vers PDF
    Par pjmorce dans le forum Général Java
    Réponses: 0
    Dernier message: 25/06/2010, 16h10
  2. Conversion d'un script shell Linux vers un batch Windows
    Par captu dans le forum Scripts/Batch
    Réponses: 1
    Dernier message: 19/01/2010, 12h22
  3. [FPDF] Convertion HTML vers PDF
    Par sami_c dans le forum Bibliothèques et frameworks
    Réponses: 6
    Dernier message: 21/09/2007, 17h43
  4. Convertion HTML vers pdf problème
    Par PrinceMaster77 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 26/07/2007, 18h25
  5. Script shell pour man en troff vers pdf
    Par bxflash dans le forum Shell et commandes GNU
    Réponses: 1
    Dernier message: 30/10/2006, 09h40

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo