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 :

PDFcreator V 2.x et interface COM


Sujet :

VB 6 et antérieur

  1. #1
    Nouveau membre du Club
    Inscrit en
    Août 2006
    Messages
    7
    Détails du profil
    Informations forums :
    Inscription : Août 2006
    Messages : 7
    Par défaut PDFcreator V 2.x et interface COM
    Bonjour,

    Dans PDFCreator V 1.x, on trouve un répertoire avec des exemples de code (VB6 et autres langages) permettant d'utiliser PDFcreator comme un composant afin de générer des fichiers PDF par programmation.
    Mais ces exemples ont disparu dans le version 2.x ... et l'interface COM a été complètement remaniée. Les classes d'objet ne sont plus les mêmes ni les propriétés et méthodes.
    Après de longues recherches en français et en anglais : rien, pas le moindre début d'exemple ...

    Je me suis attelé à la tâche et voici donc un exemple de code VB6. Vous pouvez le retrouver à: http://grandzebu.net/informatique/vb/printPDF-2.zip (En page: http://grandzebu.net/informatique/vb/progvb.htm )
    Il faut bien sûr avoir installé PDFcreator V 2 et l'avoir déclaré dans les références du projet.

    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
    Option Explicit
    Private PDF As New PdfCreatorObj
    'Avec PDFcreator V 2.1 / With PDFcreator V 2.1
     
    Private Sub Command1_Click()
      Dim OldPrinterName$, Prt As Printer, PDFQueue As New Queue, MyJob As PrintJob, PDFdevices As Printers, PDFprinterName$, Chaine$
      Screen.MousePointer = vbHourglass
      Command1.Enabled = False
     
      'Garder l'imprimante actuelle
      'Keep the current printer
      OldPrinterName$ = Printer.DeviceName
     
      'Obtenir le nom de l'imprimante PDF
      'Get the name of the PDF printer
      Set PDFdevices = PDF.GetPDFCreatorPrinters
      PDFprinterName$ = PDFdevices.GetPrinterByIndex(0)
     
      'Diriger Printer vers PDFcreator
      'Direct Printer to PDFcreator
      For Each Prt In Printers
        If Prt.DeviceName = PDFprinterName$ Then
          Set Printer = Prt
          Exit For
        End If
      Next
     
      'Initialiser
      'Initialize
      PDFQueue.Initialize
     
      'Maintenant on imprime
      'Now we print
      Chaine$ = "Hello World"
      Printer.Line (500, 500)-(Printer.ScaleWidth - 500, Printer.ScaleHeight - 500), , B
      Printer.Line (3500, 3500)-(Printer.ScaleWidth - 3500, Printer.ScaleHeight - 3500), , B
      Printer.Font.Size = 30
      Printer.CurrentX = (Printer.ScaleWidth - Printer.TextWidth(Chaine$)) / 2
      Printer.CurrentY = (Printer.ScaleHeight - Printer.TextHeight(Chaine$)) / 2
      Printer.Print Chaine$
      Printer.EndDoc
     
      'Attendre que le document arrive dans la file d'impression
      'Wait until the document arrives in the queue
      Do Until PDFQueue.Count > 0
        DoEvents
      Loop
     
      'Définir les paramètres et lancer la création
      'Set the parameters and start creating
      Set MyJob = PDFQueue.NextJob
      Call MyJob.SetProfileSetting("OpenViewer", "false")
      Call MyJob.ConvertTo("C:\pdftest.pdf")
     
      'Attendre la fin
      'Wait the end
      Do Until MyJob.IsFinished
        DoEvents
      Loop
     
      'Nettoyer
      'Clean
      Call PDFQueue.ReleaseCom
     
      'Rétablir Printer sur l'ancienne imprimante
      'Restore Printer to the old printer
      For Each Prt In Printers
        If Prt.DeviceName = OldPrinterName$ Then
          Set Printer = Prt
          Exit For
        End If
      Next
     
      Command1.Enabled = True
      Screen.MousePointer = vbNormal
    End Sub
     
    Private Sub Form_Load()
      'Vérifier que PDFcreator est disponible
      'Check PDFcreator available
      If PDF.IsInstanceRunning Then
        MsgBox "PDFcréator est occupé / PDFcreator is busy"
        Command1.Enabled = False
        End
      End If
    End Sub
    GZ

  2. #2
    Nouveau membre du Club
    Femme Profil pro
    Ingénieur qualité méthodes
    Inscrit en
    Juin 2016
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Canada

    Informations professionnelles :
    Activité : Ingénieur qualité méthodes
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2016
    Messages : 6
    Par défaut version débuggée et adapté pour PDFcreator V3.x
    Ayant eu beaucoup de mal a trouver de quoi imprimer un PDF sous Access avec possibilité de mettre un mot de passe, je donne ici le fruit de mes recherches.
    Code testé et fonctionnel avec :
    - PDFCreator3.0.2 (inclure la référence PDFCreator_COM a votre projet)
    - Access 2013 (vba 7.1)

    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
    Sub PrintToPDFCreator(sPDFFullPath As String, _
                           reportToPrint As Report, _
                           Optional sOwnerPassword As String, _
                           Optional sUserPassword As String, _
                           Optional bOpenViewer As String, _
                           Optional bAllowCopy As Boolean, _
                           Optional bAllowPrint As Boolean, _
                           Optional bAllowEdit As Boolean)
     
    Dim PDF As New PdfCreatorObj
    Dim PDFdevices As PDFCreator_COM.Printers
    Dim DefaultPrinterName, Prt As Printer
     
    Dim PDFprinterName As String
    Dim PDFCreatorQueue As PDFCreator_COM.Queue
    Dim pdfjob As PDFCreator_COM.PrintJob
     
    'On Error GoTo Err_Infos
        'Keep the current printer
        DefaultPrinterName = Printer.DeviceName
     
        'Get the name of the PDF printer
        Set PDFdevices = PDF.GetPDFCreatorPrinters
     
        PDFprinterName = PDFdevices.GetPrinterByIndex(0)
     
        'Direct Printer to PDFcreator
        For Each Prt In Printers
          If Prt.DeviceName = PDFprinterName Then
            Set Printer = Prt
            Exit For
          End If
        Next
     
        Set PDFCreatorQueue = New PDFCreator_COM.Queue
        PDFCreatorQueue.Initialize
     
        DoCmd.PrintOut 'Imprimer document actif
     
        If Not PDFCreatorQueue.WaitForJob(10) Then
            MsgBox "Impossible de joindre la file d'attente - 10sec. ", , TITLE_POPUP_ERROR
            GoTo Err_Infos
        End If
     
        Set pdfjob = PDFCreatorQueue.NextJob
     
        With pdfjob
            .SetProfileByGuid ("DefaultGuid")
     
            ' Set up the pdf security using the SetProfileSetting method of the job object.
            '-------------------------------------------------------------------------------
            'Since we want to make our pdf more safe, we have to enable the security action first
            .SetProfileSetting "PdfSettings.Security.Enabled", "true"
            ' We set up the encryption level to medium
            .SetProfileSetting "PdfSettings.Security.EncryptionLevel", "Rc128Bit"
            ' Notice that in order to have a user password we have also to set the owner password
            ' and additionally enable the RequireUserPassword property
            .SetProfileSetting "PdfSettings.Security.OwnerPassword", sOwnerPassword
            ' Require a user password to be able to view the PDF
            .SetProfileSetting "PdfSettings.Security.RequireUserPassword", "true"
            ' Now everyone who wants to open the converted file has to know the security password "myPassword"
            .SetProfileSetting "PdfSettings.Security.UserPassword", sUserPassword
            ' Set Security options
            .SetProfileSetting "PdfSettings.Security.AllowToCopyContent", IIf(bAllowCopy, "True", "False")
            .SetProfileSetting "PdfSettings.Security.AllowPrinting", IIf(bAllowPrint, "True", "False")
            .SetProfileSetting "PdfSettings.Security.AllowToEditTheDocument", IIf(bAllowEdit, "True", "False")
     
     
            ' Setup main option
            '-------------------------------------------------------------------------------
            .SetProfileSetting "OpenViewer", IIf(bOpenViewer, "True", "False")
     
            .ConvertTo sPDFFullPath
     
        End With
     
        Do Until pdfjob.IsFinished
            DoEvents
        Loop
     
        Set pdfjob = Nothing
        PDFCreatorQueue.ReleaseCom
     
        'Restore Printer to the old printer
        For Each Prt In Printers
            If Prt.DeviceName = DefaultPrinterName Then
                Set Printer = Prt
                Exit For
            End If
        Next
     
     
    Exit_currentFunction:
         Set PDFCreatorQueue = Nothing
         Exit Sub
    Err_Infos:
         MsgBox "Erreur #" & Err.Number & " : " & vbCr & vbCr & _
                "Unable to initialize PDFCreator." & vbCr & vbCr & _
                "This may be an indication that the PDF application has become corrupted, " & _
                "or its spooler blocked by AV software." & vbCr & vbCr & _
                "Re-installing PDF Creator may restore normal working."
         Resume Exit_currentFunction
     
     End Sub

Discussions similaires

  1. interface COM / manipulation de pointeurs
    Par slylafone dans le forum C++
    Réponses: 2
    Dernier message: 06/03/2006, 20h12
  2. utiliser l'interface COM
    Par baert dans le forum C++
    Réponses: 2
    Dernier message: 18/01/2006, 16h14
  3. RTTI:Lister les propriétés d'une interface COM
    Par zeprogrameur dans le forum Langage
    Réponses: 10
    Dernier message: 09/11/2005, 16h06
  4. Réponses: 9
    Dernier message: 03/03/2005, 14h36

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