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

Windows Forms Discussion :

Impression pdf creator


Sujet :

Windows Forms

  1. #1
    Membre du Club
    Inscrit en
    Avril 2007
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 103
    Points : 46
    Points
    46
    Par défaut Impression pdf creator
    Bonjour à tous,

    je souhaiterais via vb.net imprimer des documents au format pdf en utilisant

    pdf creator. Je me suis donc inspiré du bout de code se trouvant dans le

    dossier d'installation de pdf creator mais ca ne fonctionne pas. lorsque je

    lance le programme, il ouvre le fichier word que je veux imprimer, le met dans

    le spool, mais il ne l'imprime pas. J'ai fouillé dans ce bout de code mais je ne

    vois pas le bug. Pouvez vous m'aider à debugger svp?

    ci dessous 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
     
    Imports System.IO
    Public Class Form1
        Inherits System.Windows.Forms.Form
     
        Private WithEvents _PDFCreator As PDFCreator.clsPDFCreator
        Private pErr As PDFCreator.clsPDFCreatorError
        Private ReadyState As Boolean
        Private Const maxTime As Long = 20
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            pErr = New PDFCreator.clsPDFCreatorError
            _PDFCreator = New PDFCreator.clsPDFCreator
            With _PDFCreator
                If .cStart("/NoProcessingAtStartup") = False Then
                    If .cStart("/NoProcessingAtStartup", True) = False Then
                        MsgBox("Le traitement ne peut pas se faire actuellement")
                        Exit Sub
                    End If
                    MsgBox("Une instance de PDFCreator existe déjà, il faut le fermer!")
                    .cVisible = True
                End If
            End With
        End Sub
        Private Sub PrintIt(ByVal Filetyp As Long)
            Dim DefaultPrinter As String
            Dim opt As PDFCreator.clsPDFCreatorOptions
            opt = _PDFCreator.cOptions
            With opt
                .UseAutosave = 1
                .UseAutosaveDirectory = 1
                .AutosaveDirectory = "D:\MesPdf"
                .AutosaveFormat = Filetyp
                opt.AutosaveFilename = "Toto3"
            End With
            With _PDFCreator
                .cOptions = opt
                .cClearCache()
                DefaultPrinter = .cDefaultPrinter
                .cDefaultPrinter = "PDFCreator"
                .cPrintFile("D:\MesPdf\Didier.doc")
                ReadyState = False
                .cPrinterStop = False
            End With
     
            _PDFCreator.cPrinterStop = True
            _PDFCreator.cDefaultPrinter = DefaultPrinter
            opt = Nothing
        End Sub
     
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            PrintIt(0)
        End Sub
        Private Sub PDFCreator_Ready() Handles _PDFCreator.eReady
            'ToolStripStatusLabel1.Text = "Status: """ & _PDFCreator.cOutputFilename & """ was created!"
            _PDFCreator.cPrinterStop = True
            ReadyState = True
        End Sub
     
        Private Sub _PDFCreator_eError() Handles _PDFCreator.eError
            pErr = _PDFCreator.cError
        End Sub
     
    End Class

  2. #2
    Membre du Club
    Inscrit en
    Avril 2007
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 103
    Points : 46
    Points
    46
    Par défaut
    Bonjour,

    j'ai repris le code. Il faut dire qu'l y'a une légère amélioration. J'arrive

    maintenant à imprimer en pdf. Mais j'ai toujours un petit soucis.

    Lors du premier lancement du programmepas de probleme ca marche bien.

    Mais lorsqu'une instance de pdf creator est deja lancée, le programme ne

    marche plus.

    J'ai vu voulu contourner le probleme en testant si une instance est lancée, si

    oui je la referme.

    Mais ca marche toujours pas. certainement que je m'y prend mal. Pourriez

    vous m'aider à debugguer s'il vous plait?


    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
     
    Imports System.IO
    Imports System.Threading
     
    Public Class Form1
        Inherits System.Windows.Forms.Form
     
        Private WithEvents _PDFCreator As PDFCreator.clsPDFCreator
        Private pErr As PDFCreator.clsPDFCreatorError
        Private ReadyState As Boolean
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            pErr = New PDFCreator.clsPDFCreatorError
            _PDFCreator = New PDFCreator.clsPDFCreator
            If _PDFCreator.cStart("/NoProcessingAtStartup") = False Then
                MsgBox("Une instance de pdf creator est deja ouverte")
            Else
                Button1.Enabled = True
            End If
     
        End Sub
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            ConvertionToPdf("D:\Mespdf\Dupont2.txt")
        End Sub
     
        Private Function ConvertionToPdf(ByVal nomFichierAConvertir As String) As String
            Dim fname As String, fi As FileInfo, DefaultPrinter As String
            Dim opt As PDFCreator.clsPDFCreatorOptions
            fi = New FileInfo(nomFichierAConvertir)
            If InStr(fi.Name, ".", CompareMethod.Text) > 1 Then
                fname = Mid(fi.Name, 1, InStr(fi.Name, ".", CompareMethod.Text) - 1)
            Else
                fname = fi.Name
            End If
            If Not _PDFCreator.cIsPrintable(fi.FullName) Then
                MsgBox("File '" & fi.FullName & "' ne peut etre imprimé!", MsgBoxStyle.Exclamation, Me.Text)
                Return (0)
            End If
            opt = _PDFCreator.cOptions
            With opt
                .UseAutosave = 1
                .UseAutosaveDirectory = 1
                .AutosaveDirectory = My.Computer.FileSystem.SpecialDirectories.Temp
                MsgBox(My.Computer.FileSystem.SpecialDirectories.Temp)
                .AutosaveFormat = 0
                opt.AutosaveFilename = fname
            End With
            With _PDFCreator
                .cOptions = opt
                .cClearCache()
                DefaultPrinter = .cDefaultPrinter
                .cDefaultPrinter = "PDFCreator"
                .cPrintFile(fi.FullName)
                ReadyState = False
                .cPrinterStop = False
            End With
     
            Do While Not ReadyState
                Application.DoEvents()
            Loop
            _PDFCreator.cPrinterStop = True
            _PDFCreator.cDefaultPrinter = DefaultPrinter
            opt = Nothing
            MsgBox(_PDFCreator.cOutputFilename)
            _PDFCreator.cClose()
            Return (_PDFCreator.cOutputFilename)
        End Function
        Private Sub PDFCreator_Ready() Handles _PDFCreator.eReady
            _PDFCreator.cPrinterStop = True
            ReadyState = True
        End Sub
     
        Private Sub _PDFCreator_eError() Handles _PDFCreator.eError
            pErr = _PDFCreator.cError
        End Sub
    End Class

  3. #3
    Invité
    Invité(e)
    Par défaut
    A mon avis tu dois oublier de libérer la ressource et cela bloque les nouvelles instance.
    Regarde dans l'API de Pdf creator si il n'y pas une instruction pour fermer et libérer PDF Creator

  4. #4
    Membre du Club
    Inscrit en
    Avril 2007
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 103
    Points : 46
    Points
    46
    Par défaut
    Merci pour ta réponse,

    effectivement, il fallait ajouter cette instruction au cas ou l'instance est déjà lancée:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    _PDFCreator.cStart("NoProcessingAtStartup", True)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Impression et conversion PDF avec PDF Creator
    Par lolob84 dans le forum Contribuez
    Réponses: 12
    Dernier message: 11/09/2015, 16h56
  2. [XL-2003] Comprendre une impression PDF Creator
    Par Stutak dans le forum Excel
    Réponses: 3
    Dernier message: 29/09/2014, 16h06
  3. [XL-2003] Impression PDF creator
    Par dlight dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 10/02/2011, 04h45
  4. problèmes d'impression de document avec pdf creator
    Par sergentgarcia dans le forum Word
    Réponses: 5
    Dernier message: 27/11/2007, 14h23
  5. Impression PDF et imprimante par défaut
    Par bobbafet dans le forum C++Builder
    Réponses: 2
    Dernier message: 03/11/2004, 21h33

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