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

Dotnet Discussion :

fermer process pdf


Sujet :

Dotnet

  1. #1
    Membre averti
    Homme Profil pro
    Employer
    Inscrit en
    Juillet 2013
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Employer
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2013
    Messages : 33
    Par défaut fermer process pdf
    Bonjour,

    Je fait des testes pour un future développement qui ouvrira et fermera des fichiers PDF. Alors pour commencer, j'ai essayer avec quelque chose de simple, et je coince déjà.

    Voici mon code avec une form1 et 4 boutons:
    Code VB.NET : 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
    Public Class Form1
     
        Private PIDs As New Collection
     
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim ProcessPDF As New Process
            Dim DocumentPDF As String = Application.StartupPath & "\Test.pdf"
            Try
                ProcessPDF.StartInfo.UseShellExecute = True
                ProcessPDF.StartInfo.FileName = DocumentPDF
                ProcessPDF.StartInfo.CreateNoWindow = True
                ProcessPDF.Start()
                PIDs.Add(ProcessPDF.Id, DocumentPDF)
            Catch erreur As Exception
                Console.WriteLine((erreur.Message))
            End Try
        End Sub
     
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim ProcessPDF As New Process
            Dim DocumentPDF As String = Application.StartupPath & "\Test2.pdf"
            Try
                ProcessPDF.StartInfo.UseShellExecute = True
                ProcessPDF.StartInfo.FileName = DocumentPDF
                ProcessPDF.StartInfo.CreateNoWindow = True
                ProcessPDF.Start()
                PIDs.Add(ProcessPDF.Id, DocumentPDF)
            Catch erreur As Exception
                Console.WriteLine((erreur.Message))
            End Try
        End Sub
     
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            Dim DocumentPDF As String = Application.StartupPath & "\Test.pdf"
            Dim i As Integer
            i = PIDs.Item(DocumentPDF)
            Process.GetProcessById(i).Kill()
            PIDs.Remove(DocumentPDF)
        End Sub
     
        Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
            Dim DocumentPDF As String = Application.StartupPath & "\Test2.pdf"
            Dim i As Integer
            i = PIDs.Item(DocumentPDF)
            Process.GetProcessById(i).Kill()
            PIDs.Remove(DocumentPDF)
        End Sub
     
    End Class

    Bouton1 ouvre le test.pdf, bouton2 ouvre le test2.pdf, cela fonctionnent plutôt bien

    Mais là où ça coince, c'est le bouton 3 ou 4 lorsque je cherche à fermer l'un des document ouvert.
    Je récupère bien le PID de mes process, mais j'ai comme l'impression qu'adobe Acrobat DC récupère les documents ouvert pour les intégrés au premier PID du premier document ouvert, ou alors il les gèrent de manière complétement bizzard.
    Soit il fermer tout les documents ouvert, soit il ne trouve plus le PID du second document ouvert. Ou encore si un document est déjà ouvert avant l'ouverture des PDF test, il ne trouve simplement pas les PID.

    Quelqu'un a-t-il une idée de comment je peux gérer cela ?

  2. #2
    Membre averti
    Homme Profil pro
    Employer
    Inscrit en
    Juillet 2013
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Employer
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2013
    Messages : 33
    Par défaut
    Pour ceux qui voudrais faire la même chose que moi, il faut partir sur tout autre chose pour ouvrir les pdf.

    Et donc, voici un méthode qui fonctionnent, mais qui impose l'application d'adobe.
    Code VB.NET : 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
    ' ajout de la référence Acrobat (My Project -> onglet Référence -> click ajouter -> onglet COM -> sélection Acrobat)
    Imports Acrobat
    Public Class Form1
     
        Public Client As String = "MaDifferenceAMoi" 'me permet de différencier un pdf que j'ai ouvert avec l'appli d'un autre portant le meme nom
     
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim DocPdf As String = "Test.pdf"
            Dim DocumentPDF As String = Application.StartupPath & "\" & DocPdf
            Dim avApp As AcroApp
            Dim avDoc As AcroAVDoc
            avApp = CreateObject("AcroExch.App")
            avDoc = CreateObject("AcroExch.AVDoc")
            avDoc.Open(DocumentPDF, Client & " - " & DocPdf)
            avApp.Show()
            avApp.Exit()
            avApp = Nothing
            avDoc = Nothing
     
        End Sub
     
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim DocPdf As String = "Test2.pdf"
            Dim DocumentPDF As String = Application.StartupPath & "\" & DocPdf
            Dim avApp As AcroApp
            Dim avDoc As AcroAVDoc
            avApp = CreateObject("AcroExch.App")
            avDoc = CreateObject("AcroExch.AVDoc")
            avDoc.Open(DocumentPDF, Client & " - " & DocPdf)
            avApp.Show()
            avApp.Exit()
            avApp = Nothing
            avDoc = Nothing
     
        End Sub
     
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            Dim DocPdf As String = "Test.pdf"
            Dim DocumentPDF As String = Application.StartupPath & "\" & DocPdf
            Dim avApp As Acrobat.AcroApp
            Dim avDoc As Acrobat.AcroAVDoc
            avApp = CreateObject("AcroExch.App")
            avDoc = CreateObject("AcroExch.AVDoc")
     
            Dim nb As Integer
            Dim nDoc As Integer
            If avApp.GetNumAVDocs > 0 Then
                For nDoc = avApp.GetNumAVDocs - 1 To 0 Step -1
                    avDoc = avApp.GetAVDoc(nDoc)
                    nb = Len(Client & " - " & DocPdf)
                    If Mid(avDoc.GetTitle, 1, nb) = Client & " - " & DocPdf Then
                        avDoc.Close(2)
                    End If
                Next
            End If
            If avApp.GetNumAVDocs = 0 Then
                avApp.CloseAllDocs()
                avApp.Hide()
            End If
            avApp.Exit()
            avApp = Nothing
            avDoc = Nothing
     
        End Sub
     
        Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
            Dim DocPdf As String = "Test2.pdf"
            Dim DocumentPDF As String = Application.StartupPath & "\" & DocPdf
            Dim avApp As Acrobat.AcroApp
            Dim avDoc As Acrobat.AcroAVDoc
            avApp = CreateObject("AcroExch.App")
            avDoc = CreateObject("AcroExch.AVDoc")
     
            Dim nb As Integer
            Dim nDoc As Integer
            If avApp.GetNumAVDocs > 0 Then
                For nDoc = avApp.GetNumAVDocs - 1 To 0 Step -1
                    avDoc = avApp.GetAVDoc(nDoc)
                    nb = Len(Client & " - " & DocPdf)
                    If Mid(avDoc.GetTitle, 1, nb) = Client & " - " & DocPdf Then
                        avDoc.Close(2)
                    End If
                Next
            End If
            If avApp.GetNumAVDocs = 0 Then
                avApp.CloseAllDocs()
                avApp.Hide()
            End If
            avApp.Exit()
            avApp = Nothing
            avDoc = Nothing
     
        End Sub
     
    End Class

    Je n'ai pas trouver d'autre méthode plus universel, du moins pour le moment. Et je doute que je vais continuer à chercher car cela m'as déjà pris un week-end avant de poster cette demande.
    Cependant je laisse le poste ouvert pendant un temps si quelqu'un à quelque chose à proposer.

  3. #3
    Membre émérite
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2005
    Messages
    562
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Saône et Loire (Bourgogne)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Distribution

    Informations forums :
    Inscription : Juillet 2005
    Messages : 562
    Par défaut
    Bonjour,

    Le plus simple souvent c'est d'ouvrir le pdf dans un composant webBrowser.
    Dans bien des cas internet explorer est déjà configurer pour ouvrir un pdf, donc si tu utilises un webBrowser, tu lui passe le chemin du fichier en url, et ensuite le webBrowser se débrouillera avec l'extension du web browser permettant d'afficher un pdf, bien souvent adobe reader...

    J@ck.

  4. #4
    Membre averti
    Homme Profil pro
    Employer
    Inscrit en
    Juillet 2013
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Employer
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2013
    Messages : 33
    Par défaut
    Sauf que les pdf en question contienne du javascipt, et que ces scripte en question sont d'une certaine importance.
    Les webBroser sont bien pour afficher le contenu, et que ça, mais pas pour utiliser le plein potentiel des pdf.

  5. #5
    Membre averti
    Homme Profil pro
    Employer
    Inscrit en
    Juillet 2013
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Employer
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2013
    Messages : 33
    Par défaut
    Je relance cette discussion car je n'ai toujours pas trouvé comment faire.

    Donc je vais essayer de formuler une demande qui pourrais éventuellement m'aider d'une manière détourné.

    Peut-on obtenir les nom complet du PDF actuellement ouvert dans l’acrobate reader ? (Le chemin, car le fichier j'y arrive comme si dessous)
    Et si oui, comment?

    Code VB.NET : 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
    'Avec la bibliothèque "Adobe Acrobat 10.0 Type Library" dans les référence du projet
            Dim avApp As Acrobat.AcroApp
            Dim avDoc As Acrobat.AcroAVDoc
            Dim pdDoc As Acrobat.AcroPDDoc
            avApp = CreateObject("AcroExch.App")
            avDoc = CreateObject("AcroExch.AVDoc")
            pdDoc = CreateObject("AcroExch.PDDoc")
            Dim nDoc As Integer
            If avApp.GetNumAVDocs > 0 Then
                For nDoc = 0 To avApp.GetNumAVDocs - 1
                    avDoc = avApp.GetAVDoc(nDoc)
                    pdDoc = avDoc.GetPDDoc()
                    MessageBox.Show("Fichier Ouvert : " & pdDoc.GetFileName())
                    'Mais comment obtenir l'emplacement du PDF ouvert ?????
                Next
            End If
            avApp = Nothing
            avDoc = Nothing

  6. #6
    Membre averti
    Homme Profil pro
    Employer
    Inscrit en
    Juillet 2013
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Employer
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2013
    Messages : 33
    Par défaut
    Personne n'a de solution apparemment, et le poste date, donc je le ferme. je vais essayer une autre approche avec un nouveau poste.

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

Discussions similaires

  1. Fermer un PDF ou une application
    Par Anonyme5571 dans le forum NodeJS
    Réponses: 0
    Dernier message: 02/02/2015, 11h15
  2. Ouvrir un Pdf, l'imprimer, fermer le Pdf
    Par melouille56 dans le forum Macros et VBA Excel
    Réponses: 7
    Dernier message: 24/02/2010, 11h43
  3. Fermer un pdf ouvert dans un webbrowser!
    Par NejNej dans le forum Windows Forms
    Réponses: 1
    Dernier message: 09/10/2008, 16h52
  4. Fermer le .pdf à la compilation
    Par Surikat14 dans le forum Editeurs / Outils
    Réponses: 1
    Dernier message: 10/08/2007, 14h06
  5. Réponses: 2
    Dernier message: 09/03/2007, 17h53

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