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

VBScript Discussion :

Script avec PDF créator


Sujet :

VBScript

  1. #1
    Candidat au Club
    Inscrit en
    Février 2012
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Février 2012
    Messages : 2
    Points : 4
    Points
    4
    Par défaut Script avec PDF créator
    Bonjour,

    dans ma société nous avons beaucoup de fichiers au format PDF.

    Je souhaite ajouter sur chaque fichier PDF son nom en en-tête de document par exemple et cela de manière automatique (d’où l'idée d'un script via PDF creator).

    Connaissez-vous un moyen afin d'y arriver ?

    Merci de votre aide.

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut [VBS] Convert2PDF.vbs

    Je viens juste de télécharger et installer PDFCreator et j'ai trouvé pas mal d'exemples en Vbscript.
    Donc, le plus intéressant, pour le moment c'est ce script : Convert2PDF.vbs
    Je l'ai modifié un peu pour mes besoins et voila, je vous partage pour le moment cette modification
    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
    '****************************************************************************************************

  3. #3
    Candidat au Club
    Inscrit en
    Février 2012
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Février 2012
    Messages : 2
    Points : 4
    Points
    4
    Par défaut
    Salut,

    en effet, j'ai vue qu'il existe une multitude de script liés à PDFCreator.
    Cependant je n'ai pas vu de script permettant de faire apparaître le nom d'un PDF directement sur l'une ou sur l'ensemble des pages qu'il contient.

    Si quelqu'un a une solution, je pense que celà peut intéresser pas mal de monde

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut [VBS] Téléchargement + Installation silencieuse de PDFCreator

    Je cherche encore de mon côté, comment ajouter le nom du fichier dans un fichier PDF par un Vbscript
    Pour le moment, J'ai fait ce Vbscript, peut-être ça intéresse autres personnes pour un téléchargement avec installation silencieuse de PDFCreator

    Testez puis votez

  5. #5
    Invité
    Invité(e)
    Par défaut
    Bonjour

    Tu peux également jeter un coup d’œil sur cette discussion : http://www.developpez.net/forums/d43...ro-pdfcreator/

    C'est dans le forum VBA Excel, mais tu pourrais y trouver des informations intéressantes sur PDF Creator et Acrobat.

    Philippe

  6. #6
    Expert éminent sénior
    Avatar de kiki29
    Homme Profil pro
    ex Observeur CGG / Analyste prog.
    Inscrit en
    Juin 2006
    Messages
    6 132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : ex Observeur CGG / Analyste prog.

    Informations forums :
    Inscription : Juin 2006
    Messages : 6 132
    Points : 11 274
    Points
    11 274
    Par défaut
    Salut, je ne peux qu'acquiescer, il y a une liste ( à remettre à jour ) pour naviguer dans le bazar.

  7. #7
    Membre expert
    Avatar de sachadee
    Homme Profil pro
    AMI DU BAT
    Inscrit en
    Janvier 2013
    Messages
    1 478
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Brésil

    Informations professionnelles :
    Activité : AMI DU BAT
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2013
    Messages : 1 478
    Points : 3 768
    Points
    3 768
    Par défaut
    Salut à tous,

    Je m'orienterais du côté des COM il y a des scripts qui peuvent apparemment résoudre ton problèmes en combinant par exemple 2 impressions dans 1 PDF

    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
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
     
    ' CombineJobs script
    ' Part of PDFCreator
    ' License: GPL
    ' Homepage: http://www.pdfforge.org/products/pdfcreator
    ' Windows Scripting Host version: 5.1
    ' Version: 1.0.0.0
    ' Date: September, 1. 2005
    ' Author: Frank Heindörfer
    ' Comments: This script combines some printjobs in one pdf.
     
    Option Explicit
     
    Const maxTime = 30    ' in seconds
    Const sleepTime = 250 ' in milliseconds
     
    Dim PDFCreator, DefaultPrinter, ReadyState, fso, c, opath, _
     AppTitle, ScriptBasename, WshShell
     
    Set fso = CreateObject("Scripting.FileSystemObject")
     
    ScriptBaseName = fso.GetBaseName(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
     
    opath = CompletePath(fso.GetParentFolderName(Wscript.ScriptFullname))
     
    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.Popup "Please wait a moment.", 2, AppTitle, 64
     
    Set PDFCreator = Wscript.CreateObject("PDFCreator.clsPDFCreator", "PDFCreator_")
    PDFCreator.cStart "/NoProcessingAtStartup"
     
    With PDFCreator
     .cPrinterStop = true
     .cOption("UseAutosave") = 1
     .cOption("UseAutosaveDirectory") = 1
     .cOption("AutosaveDirectory") = opath
     .cOption("AutosaveFilename") = Scriptbasename
     DefaultPrinter = .cDefaultprinter
     .cDefaultprinter = "PDFCreator"
     .cClearcache
     
     ' 1. page
     CreateTextfileAndPrint opath & "1.txt", "1"
     
     ' 2. page
     CreateTextfileAndPrint opath & "2.txt", "2"
     
     ' 3. page
     CreateTextfileAndPrint opath & "3.txt", "3"
     
     ' 4. page
     CreateTextfileAndPrint opath & "4.txt", "4"
     
     Wscript.Sleep 2000                                        ' Wait until all files are printed
     
     ' Page order: 1 2 3 4
     
     .cMovePrintjobTop 3 
     ' Page order: 3 1 2 4
     
     
     .cMovePrintjobBottom 2
     ' Page order: 3 2 4 1
     
     .cMovePrintjobDown 2
     ' Page order: 3 4 2 1
     
     .cMovePrintjobUp 2
     ' Page order: 4 3 2 1
     
     .cDeletePrintjob 1
     ' Page order: 3 2 1
     
     .cCombineAll
     
     c = 0
     Do While (.cCountOfPrintjobs <> 1) and (c < (maxTime * 1000 / sleepTime))
      c = c + 1
      Wscript.Sleep sleepTime
     Loop
     
     .cPrinterStop = False
    End With
     
    c = 0
    ReadyState = 0
    Do While (ReadyState = 0) and (c < (maxTime * 1000 / sleepTime))
     c = c + 1
     Wscript.Sleep sleepTime
    Loop
     
    If ReadyState = 0 then
     MsgBox "An error is occured: Time is up!", vbExclamation + vbSystemModal, AppTitle
     Wscript.quit
    End If
     
    With PDFCreator
     .cDefaultprinter = DefaultPrinter
     Wscript.Sleep 200
     .cClose
    End With
     
    Public Sub CreateTextfileAndPrint(Filename, Content)
     Dim fso, f
     Set fso = CreateObject("Scripting.FileSystemObject")
     Set f = fso.CreateTextFile(Filename, True)
     f.WriteLine(Content)
     f.Close
     PDFCreator.cPrintfile cStr(Filename)
     WScript.Sleep 2000                                        ' Wait until the file is printed
     fso.DeleteFile(Filename)
    End Sub
     
    Private Function CompletePath(Path)
     If Right(Path, 1) <> "\" Then
       CompletePath = Path & "\"
      Else
       CompletePath = Path
     End If
    End Function
     
    '--- 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
    On pourrait donc très bien imaginer que ton premier JOB d'impression serait l'impression d'un simple txt contenant le éléments que tu veux rajouter
    à ton PDF qui lui serait le second JOB.

    Il y a même celui-çi :

    Qui imprime 2 JOBs d'impression avec ajout de bookmark

    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
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
     
    ' CombineAndAddBookmarks script
    ' Part of PDFCreator
    ' License: GPL
    ' Homepage: http://www.pdfforge.org/products/pdfcreator
    ' Windows Scripting Host version: 5.1
    ' Version: 1.0.0.0
    ' Date: December, 10. 2005
    ' Author: Frank Heindörfer
    ' Comments: This script combines some printjobs in one pdf and add a bookmark for each file.
     
    Option Explicit
     
    Const ForReading = 1, ForAppending = 8
    Const maxTime = 30    ' in seconds
    Const sleepTime = 250 ' in milliseconds
     
    Dim objArgs, ifname, fso, PDFCreator, DefaultPrinter, ReadyState, _
     i, c, AppTitle, Scriptname, ScriptBasename, FileInfo()
     
    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 objArgs = WScript.Arguments
     
    If objArgs.Count = 0 Then
     MsgBox "Syntax: " & vbtab & Scriptname & " <Filename>" & vbcrlf & vbtab & "or use ""Drag and Drop""!", vbExclamation + vbSystemModal, AppTitle
     WScript.Quit
    End If
     
    Redim FileInfo(1, objArgs.Count - 1)
     
    Set PDFCreator = Wscript.CreateObject("PDFCreator.clsPDFCreator", "PDFCreator_")
    PDFCreator.cStart "/NoProcessingAtStartup", True
    With PDFCreator
     .cPrinterstop =  true
     .cOption("UseAutosave") = 1
     .cOption("UseAutosaveDirectory") = 1
     .cOption("AutosaveFormat") = 0                              ' 0 = PDF
     DefaultPrinter = .cDefaultprinter
     .cDefaultprinter = "PDFCreator"
     .cClearcache
    End With
     
    For i = 0 to objArgs.Count - 1
     With PDFCreator
      ifname = objArgs(i)
      If Not fso.FileExists(ifname) Then
       MsgBox "Can't find the file: " & ifname, vbExclamation + vbSystemModal, AppTitle
       Exit For
      End If
      if Not .cIsPrintable(CStr(ifname)) Then
       MsgBox "Converting: " & ifname & vbcrlf & vbcrlf & _
        "An error is occured: File is not printable!", vbExclamation + vbSystemModal, AppTitle
       WScript.Quit
      End if
     
      .cOption("AutosaveDirectory") = fso.GetParentFolderName(ifname)
      .cOption("AutosaveFilename") = fso.GetBaseName(ifname)
      .cPrintfile cStr(ifname)
      c = 0
      Do While (.cCountOfPrintjobs < i + 1) and (c < (maxTime * 1000 / sleepTime))
       c = c + 1
       Wscript.Sleep sleepTime
      Loop
      FileInfo(0, i) = fso.GetBasename(ifname)
      FileInfo(1, i) = GetCountOfPagesFromPostscriptfile(.cPrintjobFilename(i + 1))
     End With
    Next
     
    With PDFCreator
     .cCombineAll
     c = 0
     Do While (.cCountOfPrintjobs <> 1) and (c < (maxTime * 1000 / sleepTime))
      c = c + 1
      Wscript.Sleep sleepTime
     Loop
     ReadyState = 0
     AppendBookmarks .cPrintjobFilename(1)
     .cPrinterStop = false
     
     c = 0
     Do While (ReadyState = 0) and (c < (maxTime * 1000 / sleepTime))
      c = c + 1
      Wscript.Sleep sleepTime
     Loop
     If ReadyState = 0 then
      MsgBox "Converting: " & ifname & vbcrlf & vbcrlf & _
       "An error is occured: Time is up!", vbExclamation + vbSystemModal, AppTitle
       WScript.Quit
     End If
     .cDefaultprinter = DefaultPrinter
     .cClearcache
     WScript.Sleep 200
     .cClose
    End With
     
    Private Sub AppendBookmarks(PostscriptFile)
     Dim fso, f, i, c
     Set fso = CreateObject("Scripting.FileSystemObject")
     Set f = fso.OpenTextFile(PostscriptFile, ForAppending, True)
     f.writeline "[/Page " & 1 & "/View[/Fit]/Title(" & FileInfo(0, 0) & ")/OUT pdfmark"
     For i = 2 to objArgs.Count
      c = c + CLng(FileInfo(1, i - 2))
      f.writeline "[/Page " & c + 1 & "/View[/Fit]/Title(" & FileInfo(0, i - 1) & ")/OUT pdfmark"
     Next
     f.WriteLine "[/PageMode/UseOutlines/Page 1/View[/Fit]/DOCVIEW pdfmark"
     f.Close
    End Sub
     
    Private Function GetCountOfPagesFromPostscriptfile(PostscriptFile)
     Dim fso, f, fstr, pp
     Set fso = CreateObject("Scripting.FileSystemObject")
     Set f = fso.OpenTextFile(PostscriptFile, ForReading, True)
     fstr = f.ReadAll
     f.Close
     pp = InstrRev(fstr, "%%Pages:", -1, 1)
     If pp <= 0 Then
      GetCountOfPagesFromPostscriptfile = 1
      Exit Function
     End If
     pp = Instr(pp, fstr," ", 1)
     If pp <= 0 Then
      GetCountOfPagesFromPostscriptfile = 1
      Exit Function
     End If
     fstr = Trim(Mid(fstr,pp))
     fstr = Replace(fstr, chr(10), " ", 1, -1, 1)
     fstr = Replace(fstr, chr(13), " ", 1, -1, 1)
     pp = Instr(1, fstr," ", 1)
     If pp <= 0 Then
      GetCountOfPagesFromPostscriptfile = 1
      Exit Function
     End If
     fstr=mid(fstr,1,pp-1)
     If Not IsNumeric(fstr) Then
      fstr = 1
     End If
     GetCountOfPagesFromPostscriptfile = fstr
    End Function
     
    '--- 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
    Avec ces éléments ça devrait être assez simple de résoude ton problème

    :EDIT J'avais pas regardé le lien posté par @Philippe JOCHMANS apparemment il ya tout ce dont tu-as besoin.
    ________________________________
    Un p'tit coup de pouce ça fait toujours plaisir, pensez-y !
    ________________________________

  8. #8
    Membre expert
    Avatar de sachadee
    Homme Profil pro
    AMI DU BAT
    Inscrit en
    Janvier 2013
    Messages
    1 478
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Brésil

    Informations professionnelles :
    Activité : AMI DU BAT
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2013
    Messages : 1 478
    Points : 3 768
    Points
    3 768
    Par défaut
    Bon après avoir tester diverse fonction disponible pour PDFCreator grâce à ce magnifique post :

    http://www.developpez.net/forums/d43...ro-pdfcreator/
    Merci @kiki29


    j' ai réussi à faire ce que tu veux.

    EDIT: Apparemment fonctionne
    Juste un petit problème il faut utiliser un autre visualiseur que ADOBE READER qui ne reconnaît pas les FONTs.

    J'en parle ici pour voir si quelqu'un a une solution.

    http://www.developpez.net/forums/d43...r/#post7781037

    Une demande a également été faîtes ici sur le forum de Pdfforge :

    http://forums.pdfforge.org/discussio...pdffile#Item_1

    J'ai fais des test et je me suis donc tourner vers IRFANVIEW avec Ghostscript installé pour la visualisation de PDF.

    Et là ça marche parfaitement avec Foxit Reader également).


    Donc voilà pour ceux que ça intèresse La fonction utilisée est : AddTextToPDFFile

    Donc à vos codes !!!


    Pour les flemmard voici un exe que j'ai fais juste de cette fonction et qui vous permets d'inclure une en-tête (en haut à gauche) à vos PDF (voir image 1)

    image 1:

    Nom : TESTPDF3.JPG
Affichages : 6792
Taille : 15,7 Ko

    Ici j'ai rajouter l'entête : "Fichier Test.PDF"

    DOWNLOAD :
    ADDTEXTToPDFFile Download

    Etant un script Autoit ça peux vous donner un Faux Positif. Mais pas d'inquiètude il n'y a pas de virus.

    Utilisation : AddTextToPDFFile.exe "Texte de l'entête" "FichierPDF" [Optional[OutputFile]]
    Sortie : FichierPDF_modified.pdf [Optional[OutputFile.pdf]]

    exemple : AddTextToPDFFile.exe "Bonjour à tous" "Un PDF_de_Votre choix"

    En sortie vous aurez un fichier "Un PDF_de_Votre choix_Modified" avec la modification effectué.

    Voilà très basique mais ça vous permet de faire des traitements par lots avec un petit fichier batch ou un script VBS (D'ailleurs vous pouvez utiliser cette fonction directement en VBS
    et faire un code 100% VBS)).
    Et surtout ça vous montre la faisabilité de la chose. Et dès que j'aurai un peu de temps je rajouterai bien plus de paramètres et d'options.

    Il y a vraiment plein de fonction vraiment intèressante pour le traitement des PDF (toute très bien décrite dans le post de @kiki29)

    Enjoy

    ________________________________
    Un p'tit coup de pouce ça fait toujours plaisir, pensez-y !
    ________________________________

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut On est presque arrivé la résolution du problème :)
    Sacha et bien pour cette contribution c'est trop +1
    Néanmoins, je voudrais faire un Vbscript qui va utiliser 2 paramètres qui sont le InputFile et le OutputFile, or dans ton application en ligne de commandes, on peut passer juste un seul paramètre qui est le InputFile, donc ce n'est pas trop flexible, tu vois ce que je veux dire
    Donc, si c'est possible, et si tu trouve le temps bien sûr, a nous faire une autre version avec 2 paramètres (le 1er est obligatoire, et le 2ème peut-être Optionnel)
    Donc si le 2ème paramètre est omis (OutputFile) , alors le fichier de sortie aura comme nom par défaut [NomdufichierInput_Modified]
    Donc avec ce vbscript qui parcours un dossier et qui sélectionne que les fichiers avec l'extension .PDF
    le fichier SortiePDF est écrasé à chaque fois ce qui n'est pas pratique dans ce cas càd un traitement par lot.

    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
    Dim fso,ext
    Set fso = CreateObject("Scripting.FileSystemObject")
    For each ifname in FSO.GetFolder(Parcourir_Dossier()).Files 
        ext = fso.GetExtensionName(ifname)
        ext = lcase(ext)
        If ext = "pdf" Then
        'MsgBox ifname.Name
            Call AddHeader2PDF(ifname.Name,ifname)
        end if
    Next
    MsgBox "Terminé !"
    '****************************************************************************************************
    Function Parcourir_Dossier()
        Dim objShell,objFolder
        Set objShell = CreateObject("Shell.Application")
        Set objFolder = objShell.BrowseForFolder(0, "Veuillez choisir un dossier pour ajouter le nom du fichier dans les entêtes PDF  ",1,"c:\Programs")
        If objFolder Is Nothing Then
            Wscript.Quit
        End If
        Parcourir_Dossier = objFolder.self.path
    end Function
    '****************************************************************************************************
    Sub AddHeader2PDF(Header,InputFile)',OutPutFile) ' Manque le chemin du Output
        Dim fso,AddHeader,MyCmd
        AddHeader = "AddTextToPDFFile.exe"
        Set fso = CreateObject("Scripting.FileSystemObject")
        if fso.FileExists(AddHeader) Then
            MyCmd = AddHeader & " " & DblQuote(Header) & " " & DblQuote(InputFile)' DblQuote(OuputFile)
            'msgbox MyCmd
            Call Executer(MyCmd,0)
        Else
            MsgBox "Check if the file " & AddHeader & " Exists !",VbCritical,"Check if the file " & AddHeader & " Exists !"
            Wscript.Quit
        end if
    End Sub
    '************************************************************************************
    Function Executer(StrCmd,Console)
        Dim ws,MyCmd,Resultat
        Set ws = CreateObject("wscript.Shell")
    'La valeur 0 pour cacher la console MS-DOS
        If Console = 0 Then
            MyCmd = "CMD /C " & StrCmd & ""
            Resultat = ws.run(MyCmd,Console,True)
            If Resultat = 0 Then
    'MsgBox "Success"
            Else
                MsgBox "Une erreur inconnue est survenue !",16,"Une erreur inconnue est survenue !"
            End If
        End If
    'La valeur 1 pour montrer la console MS-DOS
        If Console = 1 Then
            MyCmd = "CMD /K " & StrCmd & ""
            Resultat = ws.run(MyCmd,Console,False)
            If Resultat = 0 Then
    'MsgBox "Success"
            Else
                MsgBox "Une erreur inconnue est survenue !",16,"Une erreur inconnue est survenue !"
            End If
        End If
        Executer = Resultat
    End Function
    '****************************************************************************************************
    Function DblQuote(Str)
        DblQuote = Chr(34) & Str & Chr(34)
    End Function
    '************************************************************************************************
    Autre question : Est-ce-qu'il est possible de choisir le texte à ajouter (à gauche ou bien centré ou bien à droite) ?
    Si oui c'est un grand plus à ajouter comme paramètre lui aussi
    Merci encore une autre fois
    @+

  10. #10
    Membre expert
    Avatar de sachadee
    Homme Profil pro
    AMI DU BAT
    Inscrit en
    Janvier 2013
    Messages
    1 478
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Brésil

    Informations professionnelles :
    Activité : AMI DU BAT
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2013
    Messages : 1 478
    Points : 3 768
    Points
    3 768
    Par défaut
    Salut à tous,

    @Hackoo

    J'ai fait les modifs comme demandées pour le fichier de sortie :

    ADDTEXTToPDFFile Download

    Utilisation : AddTextToPDFFile.exe "Texte de l'entête" "FichierPDF" [Optional[OutputFile]]
    Sortie : FichierPDF_modified.pdf [Optional[OutputFile.pdf]]

    exemple : AddTextToPDFFile.exe "Bonjour à tous" "Un PDF_de_Votre choix"

    En sortie vous aurez un fichier "Un PDF_de_Votre choix_Modified" avec la modification effectué.

    Pour les positions (Et bien d'autres choses...) comme je l'ai dis je m'y attacherai bientôt pour faire un utilitaire complet.....

    EDIT : PDFCreator doit-être installé pour utiliser cette utilitaire
    ________________________________
    Un p'tit coup de pouce ça fait toujours plaisir, pensez-y !
    ________________________________

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut
    +1 pour Sacha
    Vbscript à tester avec la nouvelle version de Sacha
    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
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    Option Explicit
    Dim Titre,MsgAttente,MyInputFolder,MyOutPutFolder,OutPutFile,oExec,fso,ws,Temp,PathScript,ifname,ext
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ws = CreateObject("wscript.Shell")
    Temp = ws.ExpandEnvironmentStrings("%Temp%")
    Titre = "Ajout du nom de fichier dans les fichiers de type PDF "
    MsgAttente = "Veuillez patienter. "& DblQuote(Titre) &" est en cours..."
    MyInputFolder = Parcourir_Dossier()
    MyOutputFolder = MyInputFolder & "\MyPDF_Modified"
    If Not fso.FolderExists(MyOutputFolder) Then
        fso.CreateFolder(MyOutputFolder)
    End if
    Call CreateProgressBar(Titre,MsgAttente)'Creation de barre de progression
    Call LancerProgressBar() 'Launch of the progress bar
    Call Ajouter()
    Call FermerProgressBar() 'Closing progress bar
    MsgBox Titre & " est terminé !",VbInformation,Titre
    Call Explore(MyOutputFolder)
    '****************************************************************************************************
    Sub Ajouter()
        For each ifname in FSO.GetFolder(MyInputFolder).Files 
            ext = fso.GetExtensionName(ifname)
            ext = lcase(ext)
            OutPutFile = MyOutputFolder & "\" & fso.GetBaseName(ifname) & "_modified"
            If ext = "pdf" Then
                Call AddHeader2PDF(ifname.Name,ifname,OutputFile)
            end if
        Next
    End Sub
    '****************************************************************************************************
    Function Parcourir_Dossier()
        Dim objShell,objFolder
        Set objShell = CreateObject("Shell.Application")
        Set objFolder = objShell.BrowseForFolder(0, "Veuillez choisir un dossier pour ajouter le nom du fichier dans les fichiers de type PDF  ",1,"c:\Programs")
        If objFolder Is Nothing Then
            Wscript.Quit
        End If
        Parcourir_Dossier = objFolder.self.path
    end Function
    '****************************************************************************************************
    Sub AddHeader2PDF(Header,InputFile,OutPutFile)
        Dim fso,AddHeader,MyCmd
        AddHeader = "AddTextToPDFFile.exe"
        Set fso = CreateObject("Scripting.FileSystemObject")
        if fso.FileExists(AddHeader) Then
            MyCmd = AddHeader & " " & DblQuote(Header) & " " & DblQuote(InputFile) & " " & DblQuote(OutputFile)
    'msgbox MyCmd
            Call Executer(MyCmd,0)
        Else
            MsgBox "Check if the file " & AddHeader & " Exists !",VbCritical,"Check if the file " & AddHeader & " Exists !"
            Wscript.Quit
        end if
    End Sub
    '************************************************************************************
    Function Executer(StrCmd,Console)
        Dim ws,MyCmd,Resultat
        Set ws = CreateObject("wscript.Shell")
    'La valeur 0 pour cacher la console MS-DOS
        If Console = 0 Then
            MyCmd = "CMD /C " & StrCmd & ""
            Resultat = ws.run(MyCmd,Console,True)
            If Resultat = 0 Then
    'MsgBox "Success"
            Else
                MsgBox "Une erreur inconnue est survenue !",16,"Une erreur inconnue est survenue !"
            End If
        End If
    'La valeur 1 pour montrer la console MS-DOS
        If Console = 1 Then
            MyCmd = "CMD /K " & StrCmd & ""
            Resultat = ws.run(MyCmd,Console,False)
            If Resultat = 0 Then
    'MsgBox "Success"
            Else
                MsgBox "Une erreur inconnue est survenue !",16,"Une erreur inconnue est survenue !"
            End If
        End If
        Executer = Resultat
    End Function
    '****************************************************************************************************
    Function DblQuote(Str)
        DblQuote = Chr(34) & Str & Chr(34)
    End Function
    '****************************************************************************************************
    Function Explore(filename)
        Dim ws
        Set ws=CreateObject("wscript.Shell")
        ws.run "Explorer /n,/select,"& filename &" "
    End Function
    '****************************************************************************************************
    Sub CreateProgressBar(Titre,MsgAttente)
        Dim ws,fso,f,f2,ts,ts2,Ligne,i,fread,LireTout,NbLigneTotal,Temp,PathOutPutHTML,fhta,oExec
        Set ws = CreateObject("wscript.Shell")
        Set fso = CreateObject("Scripting.FileSystemObject")
        Temp = WS.ExpandEnvironmentStrings("%Temp%")
        PathOutPutHTML = Temp & "\Barre.hta"
        Set fhta = fso.OpenTextFile(PathOutPutHTML,2,True)
        fhta.WriteLine "<HTML>"
        fhta.WriteLine "<HEAD>"
        fhta.WriteLine "<Title>  " & Titre & "</Title>"
        fhta.WriteLine "<HTA:APPLICATION"
        fhta.WriteLine "ICON = ""magnify.exe"" "
        fhta.WriteLine "BORDER=""THIN"" "
        fhta.WriteLine "INNERBORDER=""NO"" "
        fhta.WriteLine "MAXIMIZEBUTTON=""NO"" "
        fhta.WriteLine "MINIMIZEBUTTON=""NO"" "
        fhta.WriteLine "SCROLL=""NO"" "
        fhta.WriteLine "SYSMENU=""NO"" "
        fhta.WriteLine "SELECTION=""NO"" "
        fhta.WriteLine "SINGLEINSTANCE=""YES"">"
        fhta.WriteLine "</HEAD>"
        fhta.WriteLine "<BODY text=""white""><CENTER><DIV><SPAN ID=""ProgressBar""></SPAN>"
        fhta.WriteLine "<span><marquee DIRECTION=""LEFT"" SCROLLAMOUNT=""3"" BEHAVIOR=ALTERNATE><font face=""Comic sans MS"">" & MsgAttente &"</font></marquee></span></DIV></CENTER></BODY></HTML>"
        fhta.WriteLine "<SCRIPT LANGUAGE=""VBScript""> "
        fhta.WriteLine "Set ws = CreateObject(""wscript.Shell"")"
        fhta.WriteLine "Temp = WS.ExpandEnvironmentStrings(""%Temp%"")"
        fhta.WriteLine "Sub window_onload()"
        fhta.WriteLine "    CenterWindow 430,90"
        fhta.WriteLine "    Self.document.bgColor = ""Orange"" "
        fhta.WriteLine " End Sub"
        fhta.WriteLine " Sub CenterWindow(x,y)"
        fhta.WriteLine "    Dim iLeft,itop"
        fhta.WriteLine "    window.resizeTo x,y"
        fhta.WriteLine "    iLeft = window.screen.availWidth/2 - x/2"
        fhta.WriteLine "    itop = window.screen.availHeight/2 - y/2"
        fhta.WriteLine "    window.moveTo ileft,itop"
        fhta.WriteLine "End Sub"
        fhta.WriteLine "</script>"
        fhta.close
    End Sub
    '**********************************************************************************************
    Sub LancerProgressBar()
        Set oExec = Ws.Exec("mshta.exe " & Temp & "\Barre.hta")
    End Sub
    '**********************************************************************************************
    Sub FermerProgressBar()
        oExec.Terminate
    End Sub
    '**********************************************************************************************

  12. #12
    Membre expert
    Avatar de sachadee
    Homme Profil pro
    AMI DU BAT
    Inscrit en
    Janvier 2013
    Messages
    1 478
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Brésil

    Informations professionnelles :
    Activité : AMI DU BAT
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2013
    Messages : 1 478
    Points : 3 768
    Points
    3 768
    Par défaut
    Comme promis voici l'utilitaire un peu plus complet : PDF_Add_text.exe V1.0.1B

    A télécharger ici :

    http://open-source.developpez.com/te...F-Add-Text-exe
    ________________________________
    Un p'tit coup de pouce ça fait toujours plaisir, pensez-y !
    ________________________________

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut
    Citation Envoyé par sachadee Voir le message
    Comme promis voici l'utilitaire un peu plus complet : PDF_Add_text.exe V1.0.1B

    A télécharger ici :

    http://open-source.developpez.com/te...F-Add-Text-exe
    et encore une autre fois pour ta nouvelle contribution +1
    Je l'ai testé et ça marche impeccable

Discussions similaires

  1. scripts avec XP
    Par Zetophe dans le forum Windows
    Réponses: 3
    Dernier message: 23/02/2006, 13h07
  2. Execution script avec option sur OVH
    Par guepe dans le forum Réseau/Web
    Réponses: 3
    Dernier message: 15/01/2006, 15h54
  3. exemple de script avec autoloader
    Par djibril dans le forum Modules
    Réponses: 4
    Dernier message: 24/11/2005, 17h53
  4. Réponses: 4
    Dernier message: 02/11/2004, 15h18
  5. Script avec JOINTURE et CASE
    Par Labienus dans le forum Langage SQL
    Réponses: 6
    Dernier message: 27/02/2004, 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