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

VB 6 et antérieur Discussion :

Pb OCX PDFcreator


Sujet :

VB 6 et antérieur

  1. #1
    Membre à l'essai
    Directeur technique
    Inscrit en
    Juillet 2005
    Messages
    8
    Détails du profil
    Informations professionnelles :
    Activité : Directeur technique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2005
    Messages : 8
    Points : 10
    Points
    10
    Par défaut Pb OCX PDFcreator
    Bonjour,
    je tiens en premier lieu à signaler que oui j'ai lu les multiples FAQs et post sur ce sujet mais la je sèche...
    Mon objectif :
    créer un OCX (je développe sous NSDK) pour exporter des fichiers en PDF avec possibilité de les fusionner.
    Mon problème :
    - Comportement aléatoire lors de la fusion ; des fois j'obtiens une impression des deux documents (cf code 1.txt, 2.txt), des fois un seul...
    - L'impression se fait avec le nom et le répertoire définit dans les options de sauvegardes automatiques de PDFcreator et pas avec le répertoire et le nom redéfinit dans le code.

    Je vous passe le code directement exploitable :
    créer un projet, ajouter la référence PDFcreator au projet
    faites un bouton et coller ce qui suit
    redéfinissez vos propres chemins pour tests.

    J'attends avec impatience vos retours,

    Cordialement,

    Antoine.

    (environnement : PDFcreator Version 0.9.5 / Windows 2K et XP / VB6)

    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
    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

  2. #2
    Expert éminent
    Avatar de ThierryAIM
    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    3 673
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2002
    Messages : 3 673
    Points : 8 524
    Points
    8 524
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
        While PDFCreator1.cCountOfPrintjobs > 0
            Sleep 1000
        Wend
    j'aurais plutôt mis un DoEvents au lieu d'un Sleep qui bloque l'exécution
    Vous vous posez une question, la réponse est peut-être ici :
    Toutes les FAQs VB
    Les Cours et Tutoriels VB6/VBScript
    Les Sources VB6


    Je ne réponds pas aux questions techniques par MP. Utilisez les forums. Merci de votre compréhension

  3. #3
    Membre à l'essai
    Directeur technique
    Inscrit en
    Juillet 2005
    Messages
    8
    Détails du profil
    Informations professionnelles :
    Activité : Directeur technique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2005
    Messages : 8
    Points : 10
    Points
    10
    Par défaut
    Bonjour Thierry,
    j'ai mis un sleep car j'utilise While PDFCreator1.cCountOfPrintjobs > 0
    et non While PDFCreator1.cPrinterStop = False qui me posait des problèmes... PDFcreator.exe n'était pas toujours kill en fin de procédure.
    Je ne pense pas que cela pose de problèmes et j'en suis venu à cette solution après de nombreux essais.

    Le vrai souci pour moi c'est que l'impression se fait dans le répertoire et le nom de fichier défini dans les options d'enregistrement automatique de PDFcreator et non dans celles que je définis dans mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    With opt
            .AutosaveDirectory = Rep ' Chemin du fichier
            .UseAutosave = 1
            .UseAutosaveDirectory = 1
            .AutosaveFormat = 0 ' PDF
            .AutosaveFilename = fileNameFusion ' Nom du fichier
    End With

  4. #4
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut
    Bonjour,

    Voici mon code :
    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
    162
    163
    164
    165
    166
     
    Option Compare Database
    Option Explicit
     
    ' Ce code permet d'imprimer des documents avec PDFCreator directement en VBA
    ' /!\ Ajouter la référence "PDFCreator"
    ' Un seul document : ConversionPDF
    ' Plusieurs documents : DemarrerFusionPDF, ConversionFusionPDF et TerminerFusionPDF
     
    ' Déclaration des APIs
    Private Declare Function GetTickCount Lib "kernel32" () As Long
     
    ' Déclaration du composant principal
    Private WithEvents PDFCreator1 As PDFCreator.ClsPDFCreator
     
    ' Déclaration de la classe de gestion des erreurs
    Private PDFCreatorErreur As clsPDFCreatorError
     
    ' Déclaration de la classe de paramétrage
    Private PDFCreatorOptions As clsPDFCreatorOptions
     
    ' Déclaration des variables globales
    Private Imprimante As String
    Private InitialisationOK As Boolean
    Private Compteur As Integer
     
    Private Sub Class_Initialize()
        Set PDFCreator1 = New ClsPDFCreator
        Set PDFCreatorErreur = New clsPDFCreatorError
     
        InitialisationOK = False
     
        With PDFCreator1
            .cVisible = True
     
            ' Pas de traitement au démarrage
            If .cStart("/NoProcessingAtStartup") = False Then
                MsgBox "Impossible d'initialiser PDFCreator !", vbCritical + vbOKOnly, "Erreur"
                Exit Sub
            End If
     
            Set PDFCreatorOptions = .cOptions
     
            .cClearCache
     
            ' On sauvegarde l'imprimante par défaut
            Imprimante = .cDefaultPrinter
        End With
     
        InitialisationOK = True
    End Sub
     
    Public Sub ConversionPDF(FichierEntreeAvecChemin As String, RepertoireSortie As String, FichierSortieSansExtension As String)
        With PDFCreatorOptions
            ' Répertoire du fichier de sortie
            .AutosaveDirectory = RepertoireSortie
     
            ' Nom du fichier de sortie
            .AutosaveFilename = FichierSortieSansExtension
     
            ' Format du fichier de sortie (PDF)
            .AutosaveFormat = 0
     
            ' Sauvegarde automatique
            .UseAutosave = 1
            .UseAutosaveDirectory = 1
        End With
     
        Set PDFCreator1.cOptions = PDFCreatorOptions
        PDFCreator1.cDefaultPrinter = "PDFCreator"
        PDFCreator1.cPrintFile FichierEntreeAvecChemin
        PDFCreator1.cPrinterStop = False
        While PDFCreator1.cPrinterStop = False
            DoEvents
        Wend
    End Sub
     
    Public Sub DemarrerFusionPDF(RepertoireSortie As String, FichierSortieSansExtension As String)
        With PDFCreatorOptions
            ' Répertoire du fichier de sortie
            .AutosaveDirectory = RepertoireSortie
     
            ' Nom du fichier de sortie
            .AutosaveFilename = FichierSortieSansExtension
     
            ' Format du fichier de sortie (PDF)
            .AutosaveFormat = 0
     
            ' Sauvegarde automatique
            .UseAutosave = 1
            .UseAutosaveDirectory = 1
        End With
     
        Compteur = 0
     
        Set PDFCreator1.cOptions = PDFCreatorOptions
        PDFCreator1.cDefaultPrinter = "PDFCreator"
    End Sub
     
    Public Sub ConversionFusionPDF(FichierEntreeAvecChemin As String)
        ' On ajoute le document à la file d'attente
        PDFCreator1.cPrintFile FichierEntreeAvecChemin
        Compteur = Compteur + 1
     
        ' Par sécurité
        SleepDoEvents 1000
    End Sub
     
    Public Sub TerminerFusionPDF()
        ' On attend que tous les documents soient prêts
        While PDFCreator1.cCountOfPrintjobs <> Compteur
            DoEvents
        Wend
     
        ' On demande la fusion de tous les documents qui se trouvent dans la file d'attente
        PDFCreator1.cCombineAll
     
        ' Par sécurité
        SleepDoEvents 1000
     
        ' On lance la fusion
        PDFCreator1.cPrinterStop = False
     
        ' On attend que la fusion soit terminée
        While PDFCreator1.cCountOfPrintjobs <> 0
            DoEvents
        Wend
    End Sub
     
    Private Sub PDFCreator1_eReady()
        ' L'impression est terminée et l'imprimante est libre !
        PDFCreator1.cPrinterStop = True
    End Sub
     
    Private Sub PDFCreator1_eError()
        Set PDFCreatorErreur = PDFCreator1.cError
     
        ' On affiche l'erreur
        MsgBox "N°" & Trim(Str(PDFCreatorErreur.Number)) & vbCrLf & "Message : " & PDFCreatorErreur.Description, vbCritical + vbOKOnly, "Erreur"
     
        ' On restaure l'imprimante par defaut
        PDFCreator1.cDefaultPrinter = Imprimante
    End Sub
     
    Private Sub Class_Terminate()
        ' On restaure l'imprimante par défaut
        PDFCreator1.cDefaultPrinter = Imprimante
     
        If InitialisationOK = True Then
            DoEvents
            PDFCreator1.cClose
        End If
     
        Set PDFCreator1 = Nothing
        Set PDFCreatorErreur = Nothing
        Set PDFCreatorOptions = Nothing
    End Sub
     
    Private Sub SleepDoEvents(ByVal intervalle As Long)
        Dim debut As Long
     
        debut = GetTickCount
        While debut + intervalle > GetTickCount
            DoEvents
        Wend
    End Sub
    Il s'utilise comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    Private Sub TestPDF()
        Dim clPDF As ClsPDF
     
        Set clPDF = New ClsPDF
     
        'clPDF.ConversionPDF "C:\Temp\Test1.doc", "C:\Temp\", "Test"
        clPDF.DemarrerFusionPDF "C:\Temp\", "TestFusion"
        clPDF.ConversionFusionPDF "C:\Temp\Test1.doc"
        clPDF.ConversionFusionPDF "C:\Temp\Test2.doc"
        clPDF.ConversionFusionPDF "C:\Temp\Test3.doc"
        clPDF.ConversionFusionPDF "C:\Temp\Test4.doc"
        clPDF.TerminerFusionPDF
    End Sub
    Pouvez-vous le tester et me retourner les problèmes que vous rencontrez (surtout pour la fusion de documents) ?

    Merci,
    ZiP

Discussions similaires

  1. [VB6]comment creer un ocx invisible
    Par windob dans le forum VB 6 et antérieur
    Réponses: 9
    Dernier message: 14/03/2004, 15h19
  2. Mscomm32.ocx et c++ builder 6
    Par Maximilius dans le forum C++Builder
    Réponses: 6
    Dernier message: 05/03/2004, 19h49
  3. [CR][VB6][Win2000] Problème OCX
    Par msna dans le forum SDK
    Réponses: 2
    Dernier message: 23/09/2003, 14h18
  4. Les composants : ATL, DLL, COM, OCX, ...
    Par Pucpood dans le forum Windows
    Réponses: 3
    Dernier message: 04/07/2003, 10h03
  5. [Kylix] Kylix et les OCX
    Par mailstef dans le forum EDI
    Réponses: 2
    Dernier message: 30/09/2002, 14h23

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